// JavaScript Document

var GLOBARRAY = new Array();
var IMGARRAY = new Array();
GLOBARRAY['navipfad'] = "fileadmin/images/navi/";
//GLOBARRAY['navipfad'] = "../images/navi/";
GLOBARRAY['contentpfad'] = "fileadmin/images/content/";

// Lädt Bilder in den Cache im Array IMGARRAY
// IMGARRAY muss eine Globale Variable sein
// @param1   string/array	Bezeichner im IMGARRAY (für den Zugriff)
// @param2   string/array	Pfad zum Bild
function imgLoader(paramNameInArray, paramImgPfad){
	if(typeof(paramNameInArray) == "object"){ // Falls die übergebenen Parameter Arrays sind
		for(var i=0 ; paramNameInArray[i] ; ++i){
			if(!IMGARRAY[paramNameInArray[i]]){//Überprüfen ob Bild schon im Cache
				IMGARRAY[paramNameInArray[i]] = new Image();
				IMGARRAY[paramNameInArray[i]].src = paramImgPfad[i];
				//alert(IMGARRAY[paramNameInArray[i]].src);
			}
		}
	}else{ // ansonsten wenn Parameter Strings sind
		if(!IMGARRAY[paramNameInArray]){//Überprüfen ob Bild schon im Cache
			IMGARRAY[paramNameInArray] = new Image();
			IMGARRAY[paramNameInArray].src = paramImgPfad;
		}
	}
}

/*Lädt die Bilder für die Navigation*/
function loadNavigationImg(){
	var PL = GLOBARRAY['navipfad'];
	var imgNpfad = new Array(PL+'1N.gif',PL+'2N.gif',PL+'3N.gif',PL+'4N.gif',PL+'5N.gif',PL+'6N.gif');
	var imgNname = new Array('N0','N1','N2','N3','N4','N5');
	var imgSpfad = new Array(PL+'1S.gif',PL+'2S.gif',PL+'3S.gif',PL+'4S.gif',PL+'5S.gif',PL+'6S.gif');
	var imgSname = new Array('S0','S1','S2','S3','S4','S5');
	imgLoader(imgNname,imgNpfad);
	imgLoader(imgSname,imgSpfad);
}

//------------------------------------------------------
/*MENÜ-NAVIGATION****************************************************************/
function setMouseOverMenu(){
	//Bilder der Navigation in den Cache laden
	loadNavigationImg();
	
	var menu = $('div[id="naviMain"] div[id="NAVIGATION"] img');
	menu.each(function(i){ // Für jedes Bild in der Haupt-Navgation
		$(this).attr('sl',i);			   
		$(this).hover(function(){ //MouseOver
			/*Bild-Wechsel*/
				var name = 'S'+$(this).attr('sl');
				$(this).attr('src',IMGARRAY[name].src);
				//alert($(this).attr('src'));
		},function(){
				var name = 'N'+$(this).attr('sl');
				$(this).attr('src',IMGARRAY[name].src);
				//alert(IMGARRAY[('S'+GLOBARRAY['on'])].src);
		});
	});
}
/*MENÜ-NAVIGATION****************************************************************/
//------------------------------------------------------

		function Farbe () {
			var pfad = "fileadmin/images/diashow/";
			//window.clearInterval(aktiv);
			GLOBARRAY['tmp'].fadeOut(1000, function(){
				GLOBARRAY['tmp'].attr('src',GLOBARRAY['imgsfd'].src);
				GLOBARRAY['tmp'].fadeIn(1000);
			
			});
		  	GLOBARRAY['x']++;
		  	GLOBARRAY['bild']++;
			if(GLOBARRAY['x'] >= GLOBARRAY['temp'].length)
			GLOBARRAY['x'] = 0;
			GLOBARRAY['imgsfd'].src = pfad+GLOBARRAY['temp'][GLOBARRAY['x']];
			
		}

$(function(){
		   $('#gallery a').lightBox();
		   setMouseOverMenu();
	/*Menü-Navigation laden*/
	//setMouseOverMenu();
//	var images = $('img.sideImage');
//	if(images.length > 0){
//		images.each(function(){
//			$(this).fadeTo(0,0.7);
//			$(this).hover(function(){
//				$(this).stop().fadeTo(200,1);
//			},function(){
//				$(this).stop().fadeTo(200,0.7);
//			});
//		});
//	}
	var diashow = $('div#DIASHOW');
	if(diashow.length > 0){;
		var pfad = "fileadmin/images/diashow/";
		GLOBARRAY['tmp'] = diashow.find('img');
		GLOBARRAY['temp'] = GLOBARRAY['tmp'].attr('imgs').split(';');
		GLOBARRAY['x'] = 0;
		GLOBARRAY['imgsfd']= new Image();
		GLOBARRAY['imgsfd'].src = pfad+GLOBARRAY['temp'][GLOBARRAY['x']];		
		var aktiv = window.setInterval("Farbe()", 8000);
	}
	var links = $('div.linkText');
	if(links.length > 0){
		links.each(function(){
			$(this).hover(function(){
				$(this).css('cursor','pointer');
			},function(){
				
			});
		});
	}
	var tmb = $('img.referenz_tmb');
	if(tmb.length > 0){
		imgLoader('loader' , 'fileadmin/images/loader.gif' ); // Bild in den Cache laden
		GLOBARRAY['onclick'] = new Array();
		GLOBARRAY['bigimg'] = $('img.bigImage');
		GLOBARRAY['bigimgAtag'] = $('a.aTagBigImage');
		//GLOBARRAY['firstload'] = true;
		var helpImg = $('img[id="helpImage"]');
		tmb.each(function(i){
			$(this).fadeTo(0, 0.6 )
			$(this).hover(function(){
				$(this).fadeTo(150, 1 );
				$(this).css('cursor','pointer');
			},function(){
				if(!GLOBARRAY['onclick'][i]){
					$(this).fadeTo(100, 0.6 );
					$(this).css('borderColor','#ffffff');
				}
			});
			$(this).click(function(){
				for(m=0 ; m < GLOBARRAY['onclick'].length ; ++m){
					GLOBARRAY['onclick'][m]=false;
				}
				GLOBARRAY['onclick'][i] = true;
				tmb.each(function(n){
					if(i!=n){
						$(this).fadeTo(0, 0.6 );
						$(this).css('borderColor','#ffffff');
					}else{
						$(this).css('borderColor','#333333');
					}
				});
				var proj = $(this).attr('pro');
				var bigImg = $(this).attr('big');
				if(!IMGARRAY[i]){
					imgLoader( i , $(this).attr('smal') ); // Bild in den Cache laden
					GLOBARRAY['bigimg'].each(function(){
						$(this).attr('src',IMGARRAY['loader'].src);
					});
				}
				GLOBARRAY['bigimgAtag'].each(function(){
					$(this).attr('href',bigImg); // Pfad für Großes Bild übernehmen
				});
				helpImg.attr('src',IMGARRAY[i].src); // gecachtes Bild in das versteckte Hilfsimage
				//helpImg.attr('big',$(this).attr('big')); // Pfad für Großes Bild übernehmen
			});
		});
		helpImg.load(function(){
			//GLOBARRAY['firstload'] = false;
			GLOBARRAY['bigimg'].each(function(){
				$(this).fadeTo(100,0.1,function(){
					$(this).attr( 'src',helpImg.attr('src') ).fadeTo(100,1);
					$(this).attr( 'big',helpImg.attr('big') );
				});
			});
		});
		GLOBARRAY['bigimg'].each(function(){
			$(this).hover(function(){
				$(this).css('cursor','pointer');
				$(this).fadeTo(100,0.6);
			},function(){
				$(this).fadeTo(100,1);
			});
		});

	}
	
	var specTable = $('div.specialTables');
	if(specTable.length > 0){
		specTable.each(function(){
			var title = $(this).children('div:first');
			var table = $(this).children('div:last');
			table.slideUp(0);
			title.hover(function(){
				$(this).css('cursor','pointer');
				$(this).css('backgroundColor','#CCC');
			},function(){
				$(this).css('backgroundColor','#EEE');
			});
			title.click(function(){
				if(table.css('display')=='none'){
					table.slideDown(400);
					$(this).css('backgroundColor','#CCC');
					$(this).css('fontWeight','bold');
					$(this).children('span:first').text('-')
				}else{
					table.slideUp(200);
					$(this).css('backgroundColor','#EEE');
					$(this).css('fontWeight','normal');
					$(this).children('span:first').text('+')
				}
			});
		});
	}
	var sendMail = $('form input:hidden[name="sendetMail"]');
	if(sendMail.length > 0){
		if(sendMail.val()!=""){
			alert(sendMail.val());
		}
	}
	var bigImg = $('a.SHOWBIGIMG');
	if(bigImg.length > 0){
		bigImg.each(function(i){
			imgLoader('IMB_BIG_'+i,$(this).attr("href"));
				 
			$(this).hover(function(e){
				$('<div id="INFOBOX" style="z-index:100; background-color:#fff; color:#fff; padding:4px;"><img src="'+IMGARRAY['IMB_BIG_'+i].src+'"></div>')
				.css('position','absolute')
				.css('top',e.pageY-450)
				.css('left',e.pageX+30-1100)
				.appendTo('body')
				.hide()
				.fadeIn();
			},
			function(){
				$('div[id="INFOBOX"]').remove();
			});
			$(this).mousemove(function(e){
				$('div[id="INFOBOX"]')
				.css('top',e.pageY-450)
				.css('left',e.pageX+30-1100)
			});
		});
	}
});
