/* 	
	JS Document for: 	give-ev.de
	Author:				info@markusgiesen.de
	CreateDate:			2008-02-11
	ChangeDate:			2008-02-11
*/
function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

// SuckerFish Hover Script

sfHover = function() {
	var sfEls = document.getElementById("navigationMain").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" showOnHover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" showOnHover\\b"), "");
		}
	}
}



activateToolTips = function(){
	/* Glossary */
	var Glossary = new Tips($$('.tip'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
};


var NavigationFoldOut = new Class ({
	initialize: function(options)
	{
		// define list elements to foldout by className
		var lists = $$("#navigationMain li");
		lists.each(function(el) {
			// check if there is a UL to fold out
			if($E('ul', el)){
				var elsUL = $E('ul',el);
				elsUL.setStyle('margin-left', '-' + el.getSize().size.x);
				el.addEvent('mouseenter', function(ev){
					ev = new Event(ev);
					lists.each(function(el2) {
						if(el!=el2){
							el2.removeClass('showOnHover');
						}
					});
					el.addClass('showOnHover');
					ev.stop();
				});
				el.addEvent('mouseleave', function(ev){
					ev = new Event(ev);
					el.removeClass('showOnHover');
					ev.stop();
				});
			}
		}.bind(this));
    }
});

var CustomGreenFrame = new Class ({
	initialize: function(options)
	{
		arrSelectorsToIdentify = new Array("#main .overviewImageSmall img",
								"#main .overviewImageBig img",
								"#main .csc-frame-frame1 img"
								);

		arrSelectorsToIdentify.each(function(strSelector,j) {
			if($defined($E(strSelector))){
				imagesToWrap = $$(strSelector);
				imagesToWrap.each(function(el,i) {
											 
					// create wrappers and insert them
					var myWrap1 = new Element('div', {'class': 'wrap1', 'id': 'no' + j + 'wrap1id'+i});
					var myWrap2 = new Element('div', {'class': 'wrap2', 'id': 'no' + j + 'wrap2id'+i});
					
					// check if image is a link and add the link-property to onclick
					
					if(el.getParent().tagName.toLowerCase()=="a"){
						myWrap1.addEvent('click', function(){
							// check if this is a popup, if not, follow the link, otherwise do nothing!
							if(el.getParent().href){
								var strLink = el.getParent().href.toString();
								if(strLink.indexOf('index.php?eID=tx_cms_showpic&file')==-1){
									window.location=strLink;
								}else{
									return false;
								}
							}
						});
					}
						
					myWrap1.setStyles({
						position: 'absolute',
						'margin-top': '-7px',
						'z-index': '1'
					});
					
					if(el.getParent().getParent().hasClass('image')) {
						var elHeight = el.getParent().getParent().getStyle('height').toInt() + 14 + 'px';
						var elWidth = el.getParent().getParent().getStyle('width');
						el.getParent().getParent().setStyles({
							'margin-top': '-4px'
						});
					}else{
						var elHeight = el.getStyle('height').toInt() + 14 + 'px';
						var elWidth = el.getStyle('width');
					}
					
					myWrap2.setStyles({
						width: elWidth,
						height: elHeight
					});
					
					// set bg-images by size
					if("#main .csc-frame-frame1 img" == strSelector) {
						myWrap1.addClass('greenFrame');
						if(window.gecko || window.webkit) {
							myWrap1.setStyles({
								'margin-top': '-' + (el.getStyle('height').toInt()+9) + 'px'
							});
						}
					} else {
						if(elWidth.toInt()<=77){
							myWrap1.addClass('greenS');
						}else if(elWidth.toInt()<=140){
							myWrap1.addClass('greenM');
							myWrap2.setStyles({
								height: (myWrap2.getStyle('height').toInt()-10) + 'px'
							});
						}
						myWrap2.setStyles({
							cursor: 'pointer'
						});
					}
					
					// special IE stuff
					if(window.ie) {
						if(elWidth.toInt()==77){
							elWidth = elWidth.toInt() + 53 + 'px';
						}
						
						myWrap1.setStyles({
							'margin-left': '-' + elWidth
						});
						
					}
					el.getParent().getParent().setStyles({
						'padding-top': '7px'
					});
					el.setStyles({
						'margin-top': '0'
					});
					
					myWrap1.injectAfter(el.getParent());
					myWrap2.injectInside('no' + j + 'wrap1id'+i);
					// myWrap3.injectInside('no' + j + 'wrap2id'+i);
					
					// create element clone
					// var myElClone = el.clone();
					
					// inject the clone into the wrapper construct
					// myElClone.injectInside('no' + j + 'wrap3id'+i);
					
					// remove the old element
//					el.remove();  // removing causes error in IE6 and IE7 why? nobody knows.... it seems that the images are loaded until infinity when removing them..?
					// el.setStyle('display', 'none');
					// el.setStyle('visibility', 'hidden');
					
				}.bind(this));
			} // end if $defined
		}.bind(this));
	}
});


window.onDomReady(function(){   
	/* Init browser-check */
	// browser-check for IE	
	var customFrames = new CustomGreenFrame();
	if(window.ie){
		var navFold = new NavigationFoldOut();
	}
	
});
