/*
	loads the long complex site
	
	author: luegs.ch
	for: networking.ch
*/

/*
	constructor
*/
siteLoader=function() { //constructor
	//alert("constructor");
	this.ie=false; //not microschrott internet explorer
	this.netscape=false; //not netscape
	this.other=false; //i.e opera ...
	this.tux=false; //tux, don't display drop movie over navPic
	this.version=0.0; //faster then string conversion

	this.navPicName="../_img/nav_hg.jpg"; //"_img/nav.jpg"; //navigation picture
	this.navPicLoadName="../_img/nav.jpg"; //navigation picture during load
	this.navHolderName=null; //navigation background image parent element name
	this.navPic=null; //navigation background
	this.mPlaceOrder=null; //image place order array (int)
	this.picNames = new Array(); //hold the filenames of the mountain
	this.imgElements = new Array(); //holds the preloaded pictures of the mountain
	this.imgHolderName=null; //parent element that holds the content
	this.imgCtr=0; //counts the already loaded pictures from the mountain
	this.markElements=new Array(); //save the meter marks, to remove it, when language switches
	this.wayContent=new Array(); //save the mountain way content for removing!
	
	this.preloaderName=null; //the preloader element name
	this.statusTextName=null; //where to write what we're currently doing!
	this.maxWayBPreloader=120; //bootle preloader max way to top
	this.preloaderChildNodes=null; //remove helper
	this.preloaderStatusNode=null; //remove help for the status text
	this.preloaderInfoNode=null; //remove help for the info text (green box)
	
	this.contentLoadDone=false; //mountain loaded indicator
	this.contentToLoad=null; //the content we have to load on bottom!
	this.collapsedSortiment=false; //if the sortiment movie is collapsed!
	this.fromBottomDist=310; //distance from bottom for bottomdiv content placing height
	
	this.scrollerObject=null; //our scroller object for this site!
	this.infoBox=null; //our info wikipedia object
	
	this.pSound=false; //not playing
	
	this.imageLocation=null; //location to the mountain images
	this.phpHandler=null; //php handler for communication
	
	this.topMenuEl=null; //holds menu top level categories > points to tme['lang']
	this.subMenuEl=null; //holds sub menu for each topemenu > points to sme['lang']
	this.contentScrollLinks=null; //the other links to scroll
	this.subMenuLinkPos=new Array(); //holds the link positions
	this.DEBUG=false; //if a client is debian gnu/linux with ...cache.memory.enable=false & ...cache.disk.enable=false
	
	this.months=new Array();
	this.months['de'] = new Array(	'Januar', 'Februar', 'M&auml;rz', 'April', 'Mai', 'Juni',
                      				'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
    								
    //menu entries
    this.tme=new Array();
    this.sme=new Array();
	//new style without innerhtml					
	this.tme['de'] =new Array( {'t1':"Wissenswertes",'t2':"Erlebniswelt", 't3':"Valser Sortiment",'http://www.valserservice.ch/de/0_home/index.php' : 'Valser Service', 't4':"Unternehmen",'t5':"Gastronomie",'t6':"Kontakt"} );
    this.sme['de']=new Array( 	{'m1':"Über diese Website",'m4':"Valser Fabrik",'m2':"Wasserkunde",'m3':"Wassertypologie",'m5':"Mineralienkunde", 'm6':"Gesundheit", 'm7':"Trinken & Leistung", 'm8':"Vals"},
						{'m14':'Valser Wasserwelt', 'm9':"Kampagne", 'm11':"Downloads",'m12':"E-Card",'m13':"Google Earth"},
						{'b1':"Valser Classic",'b2':"Valser Naturelle", 'b15':'Valser Silence', 'b3':"Valser Viva", 'b14':"Mineralisierung"},
						{},
						{'b4':"Geschichte",'b5':"Valser Service",'b7':"Fragen und Antworten",'b8':"Media"},
						{'b10':"Serviertipps",'b11':"Partnerschaften"},
						{'b12':"E-Mail", 'b13':"Adresse und Hotline"} ); //'m10':"Kuriositäten",
						
	this.tme['fr'] =new Array( {'t1':"Ce qu'il faut savoir",'t2':"Monde événementiel",'t3':"Assortiment", 'http://www.valserservice.ch/fr/0_home/index.php':'Valser Service', 't4':"Entreprise",'t5':"Gastronomie",'t6':"Contact"} );
    this.sme['fr']=new Array( 	{'m1':"Au sujet de ce site Internet",'m4':"La fabrique Valser",'m2':"Science de l'eau",'m3':"Typologie de l'eau",'m5':"Science des minéraux", 'm6':"Santé", 'm7':"Boire & Performance", 'm8':"Vals"},
						{'m14':'Notre Monde de l\'eau','m9':"Campagne", 'm11':"Téléchargement",'m12':"E-Card",'m13':"Google Earth"},
						{'b1':"Valser Classic",'b2':"Valser Naturelle", 'b15':'Valser Silence', 'b3':"Valser Viva", 'b14':"Minéralisation "},
						{},
						{'b4':"Histoire",'b5':"Valser Service",'b7':"Questions et réponses",'b8':"Média"},
						{'b10':"Conseil pour le service",'b11':"Partenariats"},
						{'b12':"E-Mail", 'b13':"Adresse et Hotline"} ); //'m10':"Curiosités",
						
	this.tme['it'] =new Array( {'t1':"Nozioni interessanti",'t2':"Tutto da scoprire",'t3':"Assortimento", 'http://www.valserservice.ch/it/0_home/index.php':'Valser Service', 't4':"Azienda",'t5':"Gastronomia",'t6':"Contatti"} );
    this.sme['it']=new Array( 	{'m1':"A proposito di questo sito",'m4':"La fabbrica Valser",'m2':"Idrologia",'m3':"Tipologie d'acqua",'m5':"Mineralogia", 'm6':"Salute", 'm7':"Bevande e rendimento", 'm8':"Vals"},
						{'m14':'Il mondo d\'acqua di Valser', 'm9':"Campagna", 'm11':"Downloads",'m12':"E-Card",'m13':"Google Earth"},
						{'b1':"Valser Classic",'b2':"Valser Naturelle", 'b15':'Valser Silence', 'b3':"Valser Viva", 'b14':"Mineralizzazione"},
						{},
						{'b4':"Storia",'b5':"Valser Service",'b7':"Domande e risposte"}, //,'b8':"Media" > non existent in italian!
						{'b10':"Come servire",'b11':"Partner"},
						{'b12':"E-Mail", 'b13':"Indirizzo e Hotline"} ); //'m10':"Curiosit�;",
                      
    this.stretchPic=null; //picture number 2, for stretching the mountain
    this.mountainEndHeight=0; //the ending height
    this.lang='de'; //language default: de
}

siteLoader.prototype.createSiteBasic=function(navparent, imgparent, preloaderparent, infoparent, imagelocation, phphandler,mplace, scrollLinks) { //topMenuElements, subMenuElements,
	//alert("create site basic!");
	//save the init stuff
	this.navHolderName=navparent;
	this.imgHolderName=imgparent;
	this.preloaderName=preloaderparent;
	this.statusTextName=infoparent;
	this.imageLocation=imagelocation;
	this.phpHandler=phphandler;
	
	this.mPlaceOrder=mplace;
	this.contentScrollLinks=scrollLinks;
	//alert(this.topMenuEl);
	
	if (navigator.appName.indexOf("Explorer") != -1) { //if ie
		//alert("argh, we hit a internet explorer");
		this.ie=true;
	} else if (navigator.appName.indexOf("Netscape") != -1) { //if netscape
		//alert("got a netscape here!");
		this.netscape=true;
	} else {
		//alert("something else than netscape or ie");
		this.other=true;
	}
	if(navigator.userAgent.indexOf("Linux") != -1) { //if it's a tux > flash wmode doesn't work there
		this.tux=true;
	}
	//bottomdiv ie6 correction and version getting
	var bdiv=document.getElementById('bottomdiv');
	if(!this.ie) {
		this.version=parseFloat(navigator.appVersion);
		bdiv.style.position='fixed';
	} else {
		//this.fromBottomDist=380; //was 380
		var arVersion = navigator.appVersion.split("MSIE");
		this.version = parseFloat(arVersion[1]);
		if ((this.version >= 5.5) && (this.version < 7)) {
			bdiv.style.position='absolute';
		} else {
			bdiv.style.position='fixed';
		}
	}
	
	//language detection
	this.lang=this.getLanguage();
	//this.lang='fr'; //debug
	this.setLanguage();
	
	this.topMenuEl=this.tme[this.lang];
	this.subMenuEl=this.sme[this.lang];
	
	//show the right logo
	this.logoChoice();
	
	//start site building...
	this.navPic=new Image();
	var self=this;
	var element=document.getElementById(this.navHolderName);
	navLoaded=function () { //loaded
		element.appendChild(self.navPic);
		self.createBottlePreloader();
		//self.createPreloader();
		self.picLoad(); //load the rest of the pictures
		self.navPic.onload=null;
		self.navPic.onabort=null;
	}
	
	this.navPic.onload=navLoaded; //set the handler for onload ff/ie
	this.navPic.onabort=navLoaded; //set the hander for onabort ie if pics already loaded
	
	//move that!
	if(!this.tux) { //not tux > wmode not supported!
		var sb=new SWFObject("../_flash/drp01.swf","drpb","100","300", 8);
		sb.addParam("scale","noscale");
		//sb.addParam("salign","tl");
		sb.addParam("name","drpb");
		sb.addParam("wmode", "transparent"); //set background transparent
		sb.addParam("allowScriptAccess","always");
		sb.write("bottomdrop");
		
		//drop @ divm5 old
		/*var mdrop=new SWFObject("../_flash/drp01.swf","mdrpb","340","1200", 8);
		mdrop.addParam("scale","noscale");
		mdrop.addParam("name","mdrpb");
		mdrop.addParam("wmode", "transparent"); //set background transparent
		mdrop.addParam("allowScriptAccess","always");
		mdrop.write("mineraldrop");*/
	}
	
	this.navPic.src=this.navPicLoadName; //start trigger!
}

siteLoader.prototype.logoChoice=function() {
	var wlogo=document.getElementById('willkommen');
	wlogo.innerHTML="<img src='../_img/willkommen_"+this.lang+".png' width='434' height='115' onload='siteLoader.prototype.fixPNG(this)'/>"
	//alert("logo choice passed");
}

siteLoader.prototype.setScrollerObject=function(obj) {
	this.scrollerObject=obj;
}

siteLoader.prototype.setInfoObject=function(obj) {
	this.infoBox=obj;
}

siteLoader.prototype.createBottlePreloader=function() {
	var pel=document.getElementById(this.preloaderName);
	var lel=document.getElementById(this.statusTextName);
	var infoText=document.getElementById('loadInfoText');
	
	var itext=document.createElement('div');
	var str=this.getContent('load');
	itext.innerHTML=str;
	infoText.style.display='';

	var ltext=document.createElement('div');
	str="Loading Images";
	ltext.innerHTML=str;

	var iel=document.createElement('div');
	iel.style.cssText="z-index:5;position:relative;margin-left:5px;"; //iel.style.cssText="z-index:5;position:relative;margin-left:13px;";
	str="<img src='../_img/preloader_bg.png' onload='siteLoader.prototype.fixPNG(this)' />";
	iel.innerHTML=str;
	bel=document.createElement('div');
	bel.style.cssText="z-index:6;position:absolute;top:143px;";
	str="<img src='../_img/preloader_bar.gif'/>";
	bel.innerHTML=str;
	//iel.src='../_img/preloader_bg.gif';
	var tel=document.createElement('div');
	tel.style.cssText="z-index:6;width:41px;text-align:center;";
	str="0%";
	tel.innerHTML=str;
	
	infoText.appendChild(itext);

	lel.appendChild(ltext);	

	pel.appendChild(iel);
	pel.appendChild(bel);
	pel.appendChild(tel);
	//save for removing
	this.preloaderChildNodes=new Array(iel,bel,tel);
	this.preloaderStatusNode=ltext;
	this.preloaderInfoNode=itext;
	//this.updateBottlePreloader(0,"hasd","sdfs");
	//alert("create preloader passed");
}

siteLoader.prototype.updateBottlePreloader=function(status,loadTxt) {
	var pel=document.getElementById(this.preloaderName);
	var bar=this.preloaderChildNodes[1];
	var currentpos=parseInt(bar.style.top);
	var delta=(status/100)*this.maxWayBPreloader;
	var newpos=this.maxWayBPreloader-delta;
	bar.style.top=newpos+"px";
	var text=this.preloaderChildNodes[2]; //pel.childNodes[3];
	var str=status+"%";
	text.innerHTML=str;	
	var ltext=this.preloaderStatusNode;
	ltext.innerHTML=loadTxt;
	//alert("update preloader with txt:"+loadTxt+" status: "+status);
}

siteLoader.prototype.removeBottlePreloader=function() {
	var pel=document.getElementById(this.preloaderName);
	for(var i=0; i<this.preloaderChildNodes.length; i++) {
		pel.removeChild(this.preloaderChildNodes[i]);
	}
	var lel=document.getElementById(this.statusTextName);
	lel.removeChild(this.preloaderStatusNode);
	var iel=document.getElementById('loadInfoText');
	iel.removeChild(this.preloaderInfoNode);
	this.showSiteInfo();
}

siteLoader.prototype.showSiteInfo=function() {
	var infoText=document.getElementById('loadInfoText');
	infoText.style.cssText="background-color:;width:390px;margin-left:250px;margin-top:470px;";
	var content=document.createElement('div');
	var str=this.getContent('load_done');
	content.innerHTML=str;
	infoText.appendChild(content);
	var el=document.getElementById('express');
	var text=document.createElement('div');
	str=this.getContent('express');
	el.style.display='';
	text.innerHTML=str;
	el.appendChild(text);
	el=document.getElementById('time');
	text=document.createElement('div');
	str=this.getContent('time');
	el.style.display='';
	text.innerHTML=str;
	el.appendChild(text);
	el=document.getElementById('usageBigArrow');
	str="<img src='../_img/arrow_big.png' onload='siteLoader.prototype.fixPNG(this)' />";
	el.innerHTML=str;
	el=document.getElementById('usageLittleArrow');
	str="<img src='../_img/arrow_little.png' onload='siteLoader.prototype.fixPNG(this)' />";
	el.innerHTML=str;
	el=document.getElementById('startlbox');
	el.style.display='';
	str=this.getContent('startlbox');
	el.innerHTML=str;
	//alert("show site info passed");
}

/*
	add handlers for css switching with the display attribute
	to a specific element
*/
/*siteLoader.prototype.addMenuSwitcher=function(name) { //adds a css switching menu
	var navMenu=document.getElementById(name);
	var self=this;
	switchMenu=function(e) { //display menu object, set others to none
		var el=null;
		if(self.netscape) {
  			el=document.getElementById(e.target.hash.substr(1));
  		} else if(self.ie) { //ie
  			el=document.getElementById(e.srcElement.hash.substr(1));
  		}
		for(key in self.topMenuEl[0]) {
			var m=document.getElementById(key);
			m.style.display='none';
		}
		el.style.display = '';
	};
	
	var allLinks=document.getElementsByTagName("a");
	for(var g=0; g<allLinks.length; g++) {
		for(skey in self.topMenuEl[0]) {
			if(allLinks[g]!='') { //wierd: prevent an exception!
				if(allLinks[g].hash.substr(1)==skey) {
					//alert("adding menu switch handler for: "+allLinks[g]);
					self.addEvent(allLinks[g],'click',switchMenu,false);
				}
			}
		}	
	}
}*/

/*
	add handlers for css switching with the display attribute
	to a specific element
*/
siteLoader.prototype.addMenuSwitcher=function(name) { //adds a css switching menu
	var navMenu=document.getElementById(name);
	var self=this;
	switchMenu=function(e) { //display menu object, set others to none
		var el=null;
		if(self.netscape) {
  			el=document.getElementById(e.target.hash.substr(1));
  		} else if(self.ie) { //ie
  			el=document.getElementById(e.srcElement.hash.substr(1));
  		}
		for(key in self.topMenuEl[0]) {
			var m=document.getElementById(key);
			m.style.display='none';
		}
		el.style.display = '';
	};
	
	var allLinks=document.getElementsByTagName("a");
	for(var g=0; g<allLinks.length; g++) {
		for(skey in self.topMenuEl[0]) {
			if(allLinks[g]!='') { //wierd: prevent an exception!
				if(allLinks[g].hash.substr(1)==skey) {
					//alert("adding menu switch handler for: "+allLinks[g]);
					self.addEvent(allLinks[g],'click',switchMenu,false);
				}
			}
		}	
	}
}

/*
	add the content in the mountain
*/
siteLoader.prototype.addWayContent=function() { //hard adding, later, mysql getting, etc
	/*content add test! read out from db and so on!*/
	/*howto handle a language switch > reload the content*/
    					
	c1=document.getElementById("divm2");
	var str=this.getContent('m2');
	c1.innerHTML=str;
    this.wayContent.push(c1);
					
    c1=document.getElementById("divm3");
    str=this.getContent('m3');
    c1.innerHTML=str;
    this.wayContent.push(c1);
					
    c1=document.getElementById("divm4");
    str=this.getContent('m4');
    c1.innerHTML=str;
    this.wayContent.push(c1);					
					
    c1=document.getElementById("divm5");
    str=this.getContent('m5');
    c1.innerHTML=str;
    this.wayContent.push(c1);

    c1=document.getElementById("divm6");
    str=this.getContent('m6');
    c1.innerHTML=str;
    this.wayContent.push(c1);			
	c1=document.getElementById("divm7");
	str=this.getContent('m7');
    c1.innerHTML=str;
    this.wayContent.push(c1);
									
	c1=document.getElementById("divm8");
	str=this.getContent('m8');
    c1.innerHTML=str;
    this.wayContent.push(c1);
					
	c1=document.getElementById("divm9");
	str=this.getContent('m9');
    c1.innerHTML=str;
    this.wayContent.push(c1);				
					
	c1=document.getElementById("divm10");
	str=this.getContent('m10');
    c1.innerHTML=str;
    this.wayContent.push(c1);
				
	c1=document.getElementById("divm11");
	str=this.getContent('m11');
    c1.innerHTML=str;
	this.wayContent.push(c1);

	c1=document.getElementById("divm12");
	str=this.getContent('m12')
    c1.innerHTML=str;				
	this.wayContent.push(c1);
	
	c1=document.getElementById("divm13");
	str=this.getContent('m13')
    c1.innerHTML=str;				
	this.wayContent.push(c1);		
	
	c1=document.getElementById("divm14");
	str=this.getContent('m14')
    c1.innerHTML=str;				
	this.wayContent.push(c1);		
					
    c1=document.getElementById("bottom");
    c1.innerHTML= "&nbsp;"; 
    this.wayContent.push(c1);
    
	//this.addContentHandlers();
    //alert('addwaycontent passed!');
}

/*
	add scrollHandlers to links in the mountain (way content)
*/
siteLoader.prototype.addContentHandlers=function() {
	var self=this;
	//alert("addcontentHandlers");
	scrollHandler=function(e) { //scrolls the site to the clicked content link
		var cname="";
		if(self.netscape) {
			if(e.target.hash===undefined) { //if the caller is a linked image
				cname=e.target.parentNode.hash.substr(1);
			} else {
				cname=e.target.hash.substr(1); //the callersname
			}
  		} else if(self.ie) { //ie
  			if(e.srcElement.hash===undefined) {
				cname=e.srcElement.parentNode.hash.substr(1);
			} else {
				cname=e.srcElement.hash.substr(1); //the callersname
			}
  		}
  		//alert(cname);
  		if (window.event) { //ie event killer, stop propagation of link click
 			//alert("clearing event!");
    		window.event.cancelBubble = true;
    		window.event.returnValue = false;
    	}
    	if (e && e.preventDefault && e.stopPropagation) { //ff event killer
      		e.preventDefault();
      		e.stopPropagation();
    	}
    	//alert("cname: "+cname);
    	var mypos=self.findPosition(cname);
    	//alert(mypos);
    	if(mypos==-1) {
    		alert("link not found on site!");
    		return;
    	}
    	//alert("scroll cname: "+cname);
    	self.scrollerObject.scrollSite(cname,parseInt(mypos));
    	//window.scrollTo(0,parseInt(mypos));
    	//self.scrollerObject.scrollSite('#',0);
  	};
  	var allAnchors=document.getElementsByTagName("a");
  	for(var i=0; i<this.contentScrollLinks.length; i++) {
  		for(j=0; j<allAnchors.length; j++) {
  			var lnk=allAnchors[j];
  			//prevent an exception and ask just at the end, if hash is key
  			if 	((lnk.href && lnk.href.indexOf('#') != -1) && 
    			( (lnk.pathname == location.pathname) ||
				('/'+lnk.pathname == location.pathname) ) && 
    			(lnk.search == location.search) &&
    			(lnk.hash.substr(1)==this.contentScrollLinks[i])) {
    				//alert("add event for: "+this.contentScrollLinks[i]);
					this.addEvent(allAnchors[j],'click',scrollHandler,false);
					//this.buildLinkInfoStruct(key);
			}
  		}
  	}
}


/*
	add an Event to a specific object in an cross browser fassion 
*/
siteLoader.prototype.addEvent=function(obj, eventType, func, useCaption) { //add an event in cross browser style
  if (obj.addEventListener) { //netscape
    obj.addEventListener(eventType, func, useCaption);
    return true;
  } else if (obj.attachEvent) {
    var retVal = obj.attachEvent("on"+eventType, func); //ie
    return retVal;
  } else { //doesn't work!
    return false;
  }
}

/*
	Find the position of name on the whole site in
	a cross browser fassion
*/
siteLoader.prototype.findPosition=function(name) { //find the content anchor position in the content of the site
	var el=document.getElementsByName(name);
	var destLink=null; //nulling the value, to have a defined state!
	for(z=0; z<el.length; z++) { 
		var lnk = el[z];
      	if (lnk.name && (lnk.name == name)) { //find the right link
        	destLink = lnk;
        	break;
      	}
	}
	if(destLink==null) { //link not found
		var b=document.getElementById('bottom');
		//alert("undefined link, return bottom: "+b.offsetTop)
		return b.offsetTop; //send to bottom!
	}			
  	var desty = destLink.offsetTop;
    while (destLink.offsetParent && (destLink.offsetParent != document.body)) {
    	destLink = destLink.offsetParent;
      	desty += destLink.offsetTop;
    }
    //alert("desty of "+name+" is: "+desty);
    return desty;
}

/*
	create the top menu entries for the submenus
*/
/*siteLoader.prototype.addMenus=function() { //add the on click handler stuff to the menu, after everything is loaded!
	var element=document.getElementById(this.navHolderName);
	var navMenu=document.createElement("div");		
		
	navMenu.setAttribute("id","navContainer");
	if(this.ie) { //ie6 hack for not fixed positions!
		//alert("ie in version: "+this.siteLoaderObj.version);
		if ((this.version >= 5.5) && (this.version < 7)) {
			navMenu.style.position='absolute'; //ie 6 is not able to have a element in fixed position!
		} else {
			navMenu.style.position='fixed';
		}
	} else {
		navMenu.style.position='fixed';
	}
	//navMenu.id='navContainer';
	
	var htmlString=""; //never edit innerHTML directly in a for loop, browser adds closing tags! eek
		
	var i=0;
	for(key in this.topMenuEl[0]) {
		//alert(this.topMenuEl[0][key]);
		if(i==0) { //init logo, etc
			htmlString=	"<div id='logo'><a href='#start' id='start'><img src='../_img/valser.gif' alt='Valser' width='78' height='23' /></div></a>" + //<a href='#start' onclick='loader.scrollHandler(this,loader);'>
   								"<div id='nav'>";
		}
		//alert("topMenuEl: "+this.topMenuEl[i]);
		htmlString += 	"<a href='#"+key+"'>"+this.topMenuEl[0][key]+"</a>" + //
								"<div id="+key+" class='submenu' style='display:none'>";
		for(skey in this.subMenuEl[i]) { //for every submenu entry
			//alert("skey: "+skey+" value: "+this.subMenuEl[i][skey]);
			htmlString += "<a href='#"+skey+"'>"+this.subMenuEl[i][skey]+"</a> ";
		}
		htmlString += "</div>";
		i++;
	}
		
	navMenu.innerHTML=htmlString;
	navMenu.style.top="10px";
	element.appendChild(navMenu); //append it to the element to publish it
	
	this.addMenuSwitcher("navContainer"); //add the css switching funcs
}*/

/*
	create the top menu entries for the submenus
*/
siteLoader.prototype.addMenus=function() { //add the on click handler stuff to the menu, after everything is loaded!
	var element=document.getElementById(this.navHolderName);
	var navMenu=document.createElement("div");		
		
	navMenu.setAttribute("id","navContainer");
	if(this.ie) { //ie6 hack for not fixed positions!
		//alert("ie in version: "+this.siteLoaderObj.version);
		if ((this.version >= 5.5) && (this.version < 7)) {
			navMenu.style.position='absolute'; //ie 6 is not able to have a element in fixed position!
		} else {
			navMenu.style.position='fixed';
		}
	} else {
		navMenu.style.position='fixed';
	}
	//navMenu.id='navContainer';
	
	/*var htmlString=""; //never edit innerHTML directly in a for loop, browser adds closing tags! eek
		
	var i=0;
	for(key in this.topMenuEl[0]) {
		//alert(this.topMenuEl[0][key]);
		if(i==0) { //init logo, etc
			htmlString=	"<div id='logo'><a href='#start' id='start'><img src='../_img/valser.gif' alt='Valser' width='78' height='23' /></div></a>" + //<a href='#start' onclick='loader.scrollHandler(this,loader);'>
   								"<div id='nav'>";
		}
		//alert("topMenuEl: "+this.topMenuEl[i]);
		htmlString += 	"<a href='#"+key+"'>"+this.topMenuEl[0][key]+"</a>" + //
								"<div id="+key+" class='submenu' style='display:none'>";
		for(skey in this.subMenuEl[i]) { //for every submenu entry
			//alert("skey: "+skey+" value: "+this.subMenuEl[i][skey]);
			htmlString += "<a href='#"+skey+"'>"+this.subMenuEl[i][skey]+"</a> ";
		}
		htmlString += "</div>";
		i++;
	}
	alert("this we should reach if the theory is correct!");	
	navMenu.innerHTML=htmlString;*/
	
	var ndiv=document.createElement('div');
	ndiv.id='logo';
	
	var astart=document.createElement('a')
	astart.href='#start';
	astart.id='start';
	
	var mimg=document.createElement('img');
	mimg.src='../_img/valser.gif';
	mimg.width='78';
	mimg.height='23';
	
	astart.appendChild(mimg);
	ndiv.appendChild(astart);
	
	var tdiv=document.createElement('div');
	tdiv.id='nav';
	
	var i=0;
	for(key in this.topMenuEl[0]) {
		var cel=document.createElement('a');
		if(key.indexOf('http')==-1) {
			cel.href='#'+key;
		} else {
			cel.href=key;
			cel.target='_blank';
		}
		cel.appendChild(document.createTextNode(this.topMenuEl[0][key]));
		var sdiv=document.createElement('div');
		sdiv.id=key;
		sdiv.className='submenu';
		sdiv.style.cssText='display:none';
		for(skey in this.subMenuEl[i]) {
			var scel=document.createElement('a');
			scel.href='#'+skey;
			scel.appendChild(document.createTextNode(this.subMenuEl[i][skey]));
			sdiv.appendChild(scel);
		}
		tdiv.appendChild(cel);
		tdiv.appendChild(sdiv);
		i++;
	}
	ndiv.appendChild(tdiv);
	navMenu.appendChild(ndiv);
	navMenu.style.top="10px";
	element.appendChild(navMenu); //append it to the element to publish it
	//alert("add menu switcher");
	this.addMenuSwitcher("navContainer"); //add the css switching funcs
}

siteLoader.prototype.scrollHandler=function(e,self) { //add a scroll handler > call it from the content context
		var cname=e.hash.substr(1);
  		if (window.event) { //ie event killer, stop propagation of link click
 			//alert("clearing event!");
    		window.event.cancelBubble = true;
    		window.event.returnValue = false;
    	}
    	if (e && e.preventDefault && e.stopPropagation) { //ff event killer
      		e.preventDefault();
      		e.stopPropagation();
    	}
    	//alert("cname: "+cname);
    	var mypos=0;
    	if(cname.indexOf('b') != -1) { //if the content is on bottom, because of a bx in the link name
    		self.contentToLoad=cname;
    		mypos=self.findPosition('bottom');
    		//alert("bottom pos: "+mypos);
    	} else { 
    		mypos=self.findPosition(cname); //normal position in the mountain
    		self.contentToLoad=null;
    	}
    	//alert(mypos);
    	if(mypos==-1) {
    		alert("link not found on site!");
    		return;
    	}
    	//alert(mypos);
    	self.scrollerObject.scrollSite(cname,parseInt(mypos));
    	//window.scrollTo(0,parseInt(mypos));
    	//self.scrollerObject.scrollSite('#',0);
}

/*
	add All defined submenus with a specific handler
*/
siteLoader.prototype.addSubMenus=function() { //add submenus to the top level menus. Set the right handlers
	var self=this;
	scrollHandler=function(e) { //sets the right 
		var cname="";
		if(self.netscape) {
			//alert("set cname for netscape to: "+e.target.hash.substr(1));
  			cname=e.target.hash.substr(1); //the callersname
  		} else if(self.ie) { //ie
  			cname=e.srcElement.hash.substr(1);
  		}
  		if (window.event) { //ie event killer, stop propagation of link click
 			//alert("clearing event!");
    		window.event.cancelBubble = true;
    		window.event.returnValue = false;
    	}
    	if (e && e.preventDefault && e.stopPropagation) { //ff event killer
      		e.preventDefault();
      		e.stopPropagation();
    	}
    	//alert("cname: "+cname);
    	var mypos=0;
    	if(cname.indexOf('b') != -1) { //if the content is on bottom, because of a bx in the link name
    		self.contentToLoad=cname;
    		mypos=self.findPosition('bottom');
    		//alert("bottom pos: "+mypos);
    	} else { 
    		mypos=self.findPosition(cname); //normal position in the mountain
    		self.contentToLoad=null;
    	}
    	//alert(mypos);
    	if(mypos==-1) {
    		alert("link not found on site!");
    		return;
    	}
    	self.scrollerObject.scrollSite(cname,parseInt(mypos));
    	//window.scrollTo(0,parseInt(mypos));
    	//self.scrollerObject.scrollSite('#',0);
	}
	//old to delete!
  	/*var allAnchors=document.getElementsByTagName("a");
  	for(i=0; i<this.subMenuEl.length; i++) {
  		for(key in this.subMenuEl[i]) {
  			for(j=0; j<allAnchors.length; j++) {
  				var lnk=allAnchors[j];
  				//prevent an exception and ask just at the end, if hash is key
  				if 	((lnk.href && lnk.href.indexOf('#') != -1) && 
       				( (lnk.pathname == location.pathname) ||
	   				('/'+lnk.pathname == location.pathname) ) && 
       				(lnk.search == location.search) &&
       				(lnk.hash.substr(1)==key)) {
						this.addEvent(allAnchors[j],'click',scrollHandler,false);
						this.buildLinkInfoStruct(key);
				}
  			}
  		}
  	}*/
  	//new
  	var allAnchors=document.getElementsByTagName("a");
  	for(i=0; i<this.subMenuEl.length; i++) {
  		for(key in this.subMenuEl[i]) {
  			for(j=0; j<allAnchors.length; j++) {
  				var lnk=allAnchors[j];
  				//alert("lnk.href is: "+lnk.href+" key is: "+key+" lnk.hash.substr(1) is: "+lnk.hash.substr(1)+" lnk.pathname: "+lnk.pathname+" lnk.search: "+lnk.search);
  				//prevent an exception and ask just at the end, if hash is key
  				/*if 	((lnk.href && lnk.href.indexOf('#') != -1) && 
       				( (lnk.pathname == location.pathname) ||
	   				('/'+lnk.pathname == location.pathname) ) && 
       				(lnk.search == location.search) &&
       				(lnk.hash.substr(1)==key)) {
       					//this.removeEvent(allAnchors[j],'click',scrollHandler,false);
       					alert("add event for sub menu click");
						this.addEvent(allAnchors[j],'click',scrollHandler,false);
						//this.buildLinkInfoStruct(key);
				}*/
				//alert("lnk.href is: "+lnk.href+" key is: "+key+" lnk.hash.substr(1) is: "+lnk.hash.substr(1));
				if((lnk.href && lnk.href.indexOf('#')!=-1) && lnk.hash.substr(1) == key) {
					//alert("add event for sub menu click");
					this.addEvent(allAnchors[j],'click',scrollHandler,false);
				}
  			}
  		}
  	}
}

siteLoader.prototype.addLanguageSwitch=function() {
	var el=document.getElementById('lang_switch');
	var deStr='Deutsch';
	var frStr='Français';;
	var itStr='Italiano';
	var str="<div><a id='de' href='javascript:;'>"+deStr+"</a></div><div><a id='fr' href='javascript:;'>"+frStr+"</a></div><div><a id='it' href='javascript:;'>"+itStr+"</a></div>";
	el.innerHTML=str;
	var langarr=new Array('de','fr','it');
	var self=this;
	clicked=function(e) {
		if(self.ie) { //if ie
			if(self.lang==e.srcElement.id) {
				return;
			}
		} else { //netscape
			if(self.lang==e.target.id) { //choose the same language
				//alert("this is the same language!");
				return;
			}
		}
		var lang="";
		if(self.ie) { //if ie
			lang=e.srcElement.id;
			self.lang=lang;
		} else { //netscape
			//alert(e.target.id);
			lang=e.target.id;
			self.lang=lang;
		}
		for(var i=0; i<langarr.length; i++) {
			if(self.ie) {
				if(langarr[i]==e.srcElement.id) {
					e.srcElement.style.cssText="text-decoration:none;background-color:#ffffff;color:#005d2f;";
				} else {
					var del=document.getElementById(langarr[i]);
					del.style.cssText="text-decoration:none;background-color:#005d2f;color:#ffffff";
				}
			} else {
				if(langarr[i]==e.target.id) {
					e.target.style.cssText="text-decoration:none;background-color:#ffffff;color:#005d2f;";
					//alert("key is: "+langarr[i]+" equals to target id: "+e.target.id);
				} else {
					//alert("reset key: "+langarr[i]);
					var del=document.getElementById(langarr[i]);
					del.style.cssText="text-decoration:none;background-color:#005d2f;color:#ffffff";
				}
			}
		}
		//alert("remove everything!");
		self.scrollerObject.userHitEnd=false; //set to not hit again. No way around this hack!
		self.setLanguage();
		self.topMenuEl=self.tme[self.lang];
		self.subMenuEl=self.sme[self.lang];
		self.logoChoice();
		self.removeLangSwitch();
		self.removeScala();
		self.removeNavigation();
		self.removeWayContent();
		self.removeSortimentMovie();
		self.createBottlePreloader();
		self.makeScala(1000,25,1000000); //do it again in other language
	}
	
	el=document.getElementById('de');
	this.addEvent(el,'click',clicked,false);
	el=document.getElementById('fr');
	this.addEvent(el,'click',clicked,false);
	el=document.getElementById('it');
	this.addEvent(el,'click',clicked,false);
	document.getElementById(this.lang).style.cssText="text-decoration:none;background-color:#ffffff;color:#005d2f;"; //mark the current!
}

/*
	information building for the scrolling and flash updates
*/
siteLoader.prototype.buildLinkInfoStruct=function(lnkName) {
	//alert("adding info for: "+lnkName);
	this.subMenuLinkPos[lnkName]=this.findPosition(lnkName);
	//alert("data: "+this.subMenuLinkPos[lnkName]);
	return;
}

siteLoader.prototype.buildInfoStructString=function(initstr) {
	for(key in this.subMenuLinkPos) {
		//alert("key is: "+key+"value is: "+this.subMenuLinkPos[key]);
		initstr+=","+key+":"+this.subMenuLinkPos[key];
	}
	return initstr;
}

/*
	load the navigation objects
*/
siteLoader.prototype.navLoad=function() {
	var element=document.getElementById(this.navHolderName);
		//alert("nav loaded!");
		
	if(!this.tux) {
		this.navPic.src=this.navPicName;
	}
	
	this.addMenus();
    this.addWayContent();
    this.addContentHandlers(); //add way links to the content
  	this.addSubMenus();
  	this.addLanguageSwitch();
    	
    //create the swf shit with swfobject or something like that
    //to check the browser compatiblity!
    var bottleMenu=document.createElement("div");
    bottleMenu.setAttribute("id","bottlepos");
    
    if(this.ie) { //ie6 hack for not fixed positions!
		//alert("ie in version: "+this.siteLoaderObj.version);
		if ((this.version >= 5.5) && (this.version < 7)) {
			bottleMenu.style.position='absolute'; //ie 6 is not able to have a element in fixed position!
		} else {
			bottleMenu.style.position='fixed';
		}
	} else {
		bottleMenu.style.position='fixed';
	}
    
    //bottleMenu.style.position='fixed';
    bottleMenu.style.top="388px";
    this.scrollerObject.bottlePosition=388;
    element.appendChild(bottleMenu);
    /*flash adding with swfobject debug!*/
    var so = new SWFObject("../_flash/valser01.swf", "valser01", "41", "200", "8", "#000000");
    so.addParam("wmode", "transparent"); //set background transparent
    so.addParam("name","valser01"); //set the name to showpos
    so.addParam("swLiveConnect","true"); //update from javascript to flash
    so.addParam("debug","1");
    so.write("bottlepos"); //write it to the right element
    //positioning
    this.updateFixedPos("bottlepos",830);
    this.updateFixedPos("navContainer",10);
    //alert("flash written: "+document.getElementById("bottlepos").innerHTML);
    //alert("try to find the just written element: "+window.document.showpos);
    
    //add the manual user wheel scroll handler
    //alert("manual user scroll handling");
    this.scrollerObject.userBarScrollHandling();
    
    //set the handler to detect a resize of the browser window, to set the fixed elements
    var self=this;
    window.onresize=function() {
    	//alert("resize");
    	self.updateFixedPos("bottlepos",830);
    	self.updateFixedPos("navContainer",10);
    	//self.updateFixedPos("lang_switch",10);
    	self.infoBox.centerBoxes();
    }
    //add the sortiment movie
    this.addSortimentMovie();
    //add the mineraldrop movie
    var mdrop=new SWFObject("../_flash/drp01.swf","mdrpb","340","1200", 8);
	mdrop.addParam("scale","noscale");
	mdrop.addParam("name","mdrpb");
	mdrop.addParam("wmode", "transparent"); //set background transparent
	mdrop.addParam("allowScriptAccess","always");
	mdrop.write("mineraldrop");
    document.getElementById('mineraldrop').style.display='';
}

/*
	create atalker object in cross browser fassion
*/
siteLoader.prototype.createXMLHttpRequest = function() { //creates the talking object differently for activex
    var xmlHttp = null;
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp
}

/*
	bubblesorting arrays
*/
siteLoader.prototype.arraySort=function(tosort) {
	for (var i=0; i<(tosort.length-1); i++) {
		for (var j=i+1; j<tosort.length; j++) {
			if (tosort[j] < tosort[i]) {
            	var dummy = tosort[i];
                tosort[i] = tosort[j];
                tosort[j] = dummy;
            }
         }
	}
	return tosort;
}

siteLoader.prototype.getContent=function(cid) {
	var xmlHttp=this.createXMLHttpRequest();
	xmlHttp.open('get', this.phpHandler+'?op=getcontent&cid='+cid+'&lang='+this.lang+this.antiCacheStr(),false);
	xmlHttp.send('op=getcontent&cid='+cid+'&lang='+this.lang);
	if (xmlHttp.status == 200) {
    	if (xmlHttp.responseText) {
    		return xmlHttp.responseText;
        } else {
        	return "no content for this cid!";
        }
    } else {
    	return "no content for this cid!";
    }
}

/*
	detect the browser language
*/
siteLoader.prototype.getLanguage=function() {
	var xmlHttp=this.createXMLHttpRequest();
	xmlHttp.open('get', this.phpHandler+'?op=getlang'+this.antiCacheStr(),false);
	xmlHttp.send('op=getlang');
	if (xmlHttp.status == 200) {
    	if (xmlHttp.responseText) {
    		return xmlHttp.responseText;
        }
    } else {
    	return "de"; //no info from php, choose de
    }
}

siteLoader.prototype.setLanguage=function() {
	var xmlHttp=this.createXMLHttpRequest();
	xmlHttp.open('get', this.phpHandler+'?op=setlang&lang='+this.lang+this.antiCacheStr(),false);
	xmlHttp.send('op=setlang&lang='+this.lang);
	if (xmlHttp.status == 200) {
    	if (xmlHttp.responseText) {
    		return true;
        }
	}
}

/*
	get the available pictures from the specific folder, set @ creation time
*/
siteLoader.prototype.picGet=function() { //get all pictures from a folder for the mountain
	var xmlHttp = this.createXMLHttpRequest();
	//alert("pic get!");
    //xmlHttp.open("post", this.phpHandler , false);
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.open("GET", this.phpHandler+"?folder="+this.imageLocation+"&op=picget"+this.antiCacheStr() ,false);
    //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send("folder="+this.imageLocation+"&op=picget");
    if (xmlHttp.status == 200) {
    	if (xmlHttp.responseText) {
    		var res=xmlHttp.responseText.split(",");
    		var ires=new Array();
    		for(var i=0; i<res.length; i++) { //parse every value to int, for sort
    			//ires[i]=parseInt(res[i]);
    			var number=parseInt(res[i]);
    			if(!isNaN(number)) { //to be sure
    				ires.push(parseInt(res[i]));
    			} 
    		}
    		var self=this;
    		numsort = function(a, b) { //inline sort function
    			//alert("return a-b: "+(a-b));
    			return a-b;
			};
			
			ires.sort(numsort); //inline sort function
			
			for(key in ires) {
				//alert(ires[key].toString()+".jpg");
				this.picNames.push(ires[key].toString()+".jpg");
			}
        }
    } else {
    	alert("error in picGet!");
    }
}

/*
	load the mountain in the browser cache
	Just load the next picture in the onload function of the picture before
*/
siteLoader.prototype.picLoad=function() {
	var self=this;
	var ctr=0;
	this.picGet(); //search the folder an get the pictures
	var img=new Image(); //first image!
	imgloaded=function() {
		ctr++;
		self.imgElements.push(img); //save last image
		//alert("imgloaded");
		if(ctr==self.picNames.length) { //finished
			self.contentLoadDone=true;
			self.imgPlace(); //place the images, load the scala
			//alert("load finished");
		} else {
			//alert("load pic nr: "+self.picNames[ctr]);
			var status=parseInt(ctr/(self.picNames.length-1)*100);
			var statusText='';
			if(self.lang=='de') {
				statusText='Lade Bilder';
			} else if(self.lang=='fr') {
				statusText='T&eacute;l&eacute;chargement des images';
			} else if(self.lang=='it') {
				statusText='Carica immagini';
			}
			//alert(img.onabort);
			self.updateBottlePreloader(status,statusText);	
			img=new Image();
			img.onload=imgloaded;
			img.onabort=imgloaded; //needed by ie, if already in cache!
			img.src="../_img/mountain/"+self.picNames[ctr];
			//alert(status)
			/*if(ctr<15) {
				alert(img.src);
			}*/
		}
	};
	
	img.onabort=imgloaded;
	img.onload=imgloaded;
	img.onabort=imgloaded; //needed by ie, if already in cache!
	img.src="../_img/mountain/"+self.picNames[ctr]; //start trigger
}


/*	picture placing in fastest setInterval move we can get
	var together defines the package size for placing in the
	same interval
*/
siteLoader.prototype.imgPlace=function() {
	var element=document.getElementById(this.imgHolderName);
	var ictr=0; //image counter for stopping interval
	var self=this;
	var together=10; //n elements together in the interval, to speedup placing but deliver a status
	var action=setInterval("doPlacing()",1);
	doPlacing=function() {
		//alert("placing: "+self.imgElements[self.mPlaceOrder[ictr]].src);
		if(ictr==self.mPlaceOrder.length) {
			//alert("clear interval");
			clearInterval(action);

			/*var el=document.createElement("img"); //add last element
			el.src=self.imgElements[self.mPlaceOrder[ictr-1]].src;
			element.appendChild(el);*/
			
			var element1=document.getElementById("meter");
			element1.style.display='';
			element1.style.cssText="height:1000005px"; //+5 to see the next green mark!
			self.scrollerObject.create(self);
			//self.makeScala(1000, element.offsetHeight); //not accurate!
			self.makeScala(1000, 25, 1000000);
			return;
		}
		
		placeImg=function() {
			var el=document.createElement("img");
			el.src=self.imgElements[self.mPlaceOrder[ictr]].src;
			if(self.mPlaceOrder[ictr]==122) { //found stretch image
				self.stretchImage=el; //save the stretch image to make a resize after scala is finished
			}
			element.appendChild(el);
			ictr++;
		}
		
		if(ictr<self.mPlaceOrder.length-together) { //place package
			for(var z=0; z<together; z++) {
				placeImg();
			}
		} else { //place step by step
			placeImg();
		}
		var status=parseInt(ictr/(self.mPlaceOrder.length-1)*100);
		var statusText='';
		if(self.lang=='de') {
			statusText='Platziere Bilder';
		} else if(self.lang=='fr') {
			statusText='Placement des images';
		} else if(self.lang=='it') {
			statusText='Posiziona immagini';
		}
		self.updateBottlePreloader(status, statusText);
	};
}

siteLoader.prototype.getPastDate=function(mark) {
	mark=mark.toString();
	var now= new Date();
	var val=mark.split('.')
	var year=parseInt(val[0]);
	var month=parseFloat("0."+val[1]);
	month=Math.round(12*month); //-1 date object 0 = januar
	if(month>=1) {
		month-=1;
	}
	var result=new Date(now.getFullYear()-year,now.getMonth()-month,10);
	//alert("results in year: "+result.getFullYear()+" month: "+this.months[result.getMonth()]);
	return result;
}

/*
	remove the language switch, to prevent switching during removing!
*/

siteLoader.prototype.removeLangSwitch=function() {
	var el=document.getElementById('lang_switch');
	el.innerHTML='';
}

/*
	remove the whole mountain content for language switching
*/

siteLoader.prototype.removeWayContent=function() {
	var exel=document.getElementById('express');
	exel.innerHTML="";
	exel=document.getElementById('time');
	exel.innerHTML="";
	var exel=document.getElementById('startlbox');
	exel.innerHTML="";
	//var el=document.getElementById('container');
	for(var i=0; i<this.wayContent.length; i++) {
		//el.removeChild(this.wayContent[i]);
		this.wayContent[i].innerHTML="";
	}
}

/*
	remove navigation menus and the bottle position shower
*/
siteLoader.prototype.removeNavigation=function() {
	var el=document.getElementById(this.navHolderName);
	var rel=document.getElementById('navContainer');
	var rbel=document.getElementById('bottlepos');
	el.removeChild(rel);
	el.removeChild(rbel);
	var infoText=document.getElementById('loadInfoText');
	infoText.style.cssText="background: url(../_img/tr_bg.png) repeat;;width:210px;margin-left:400px;margin-top:440px;";
	infoText.innerHTML="";
}

/*
	remove the bottle sortiment movie
*/
siteLoader.prototype.removeSortimentMovie=function() {
	var el=document.getElementById('bottleSortiment');
	el.innerHTML="";
}

/*
	remove the scala for language switching
*/

siteLoader.prototype.removeScala=function() { //remove all links for language switching
	var el=document.getElementById('container');
	for(var i=0; i<this.markElements.length; i++) {
		el.removeChild(this.markElements[i]); //[i]
	}
	this.markElements=new Array(); //nulling it for new elements in other language
	var c=document.getElementById('copy');
	c.innerHTML="";
	//this.createBottlePreloader();
	//this.makeScala(1000,25,1000000);
}

siteLoader.prototype.makeScala=function(meters,years,pixels) { //place a scala for element positioning help, also for wikipedia entries!
	//alert("make scala now");
	var offset=410;
	//var element=document.getElementById(this.imgHolderName);
	var element=document.getElementById('container');
	var step=parseInt(pixels/meters);
	//alert("height was: "+element.offsetHeight+" step: "+step);
	var mctr=0; //meter counter
	var stepctr=0;
	var together=10; //n elements together in the interval, to speedup placing but deliver a status
	var self=this;
	var action=setInterval("writeScale()",1);
	writeScale=function() {
		//if(stepctr>pixels-step) {
		if(stepctr>=pixels+step) {
			clearInterval(action);
			var scalaheight=document.getElementById('meter').style.height;
			var contentheight=document.getElementById('mountain').offsetHeight;
			var wheight=0;
			if(!self.ie) {
				wheight=window.innerHeight;
			} else {
				wheight=document.documentElement.clientHeight;
			}
			//alert("difference between scala and content from the mountain: "+(parseInt(scalaheight)-parseInt(contentheight))+" wheight is: "+wheight);
			var endoffset=(parseInt(scalaheight)-parseInt(contentheight))+parseInt(wheight/3);
			//alert("mountain height: "+contentheight+" the scala is: "+scalaheight+" long wheight: "+wheight+" stretchimageheight: "+self.stretchImage.height+" offset should be: "+endoffset);
			self.stretchImage.height+=endoffset;
			self.stretchImage.width=960; //fixed!
			//alert("the stretch image is now: "+self.stretchImage.height);
			//copyright footer adding
			var c=document.getElementById('copy');
			c.style.display=''; 
			//var cstr="<div style='float:left'>&copy; Valser 2008, All Rights reserved</div><div><div style='margin-left:785px'>Site Map &#124; <a href='javascript:;' onclick=\"box.showCidBox('impressum')\"> Impressum</a></div>";
			var cstr="<div style='float:left'>&copy; Valser 2008, All Rights reserved</div><div><div style='margin-left:820px;cursor:pointer;'><div id='sitemap' style='float:left;'>Site Map &#124; </div><div style='padding-left:2px;cursor:pointer' id='impressum'> Impressum</div></div>";
			c.innerHTML=cstr;
			showImpr=function() {
				self.infoBox.showCidBox('impressum');
			}
			showMap=function() {
				self.infoBox.showCidBox('site-map');
			}
			self.addEvent(document.getElementById('impressum'),'click',showImpr,false);
			self.addEvent(document.getElementById('sitemap'),'click',showMap,false);
			
			//add the drop in the navigation hg
			if(!self.tux) { //only if not tux
				var so=new SWFObject("../_flash/valser2.swf","valser2","960","389", 8);
				so.addParam("scale","noscale");
				//so.addParam("salign","tl");
				so.addParam("name","valser2");
				so.addParam("wmode", "transparent"); //set background transparent
				so.write("navdrop");
			}
			
			self.removeBottlePreloader();
			self.navLoad(); //load the navigation
			self.findContainerLeft();
			//alert("set to pos: "+(document.getElementById('bottleSortiment').offsetTop-100));
			document.getElementById('bottomdrop').style.top=(document.getElementById('bottleSortiment').offsetTop-250)+'px'; //set the positon of the bottom drop
			return;
		}
		
		placeMark=function() {
			var el=document.createElement("div");
			if(!self.ie) { //ie has troubles with setAttribute
				el.setAttribute("class","mark");
			} else {
				el.className="mark";
			}
			el.style.top=((stepctr+offset)-17).toString()+"px";
			//alert("el top: "+el.style.top+" left: "+el.style.left);
			var yctr=(years/pixels*stepctr).toFixed(2);
			var date=self.getPastDate(yctr);
			clickmark=function() {
				//date=self.getPastDate(yctr);
				self.infoBox.showWikiBox(date.getFullYear(),escape(self.months['de'][date.getMonth()])); //hardcode to de!
			}
			
			var strYctr=yctr.toString();
			var val=strYctr.split('.')
			var month=parseFloat("0."+val[1]);
			month=Math.round(12*month); //-1 date object 0 = januar
			
			var str="<div style='padding-bottom:10px;'>";
			str+=(mctr.toString())+" m</div>"; //meters
			var yearname="";
			if(parseInt(yctr)==1) { //text correction einzahl jahr
				if(self.lang=='de'){
					yearname='Jahr';
				} else if(self.lang=='fr') {
					yearname='ann&eacute;e';
				} else if(self.lang=='it') {
					yearname='anno';
				}
				if(month==12) {
					//str+="<div><a href='javascript:;'>"+(parseInt(yctr)+1)+" "+yearname+"<br/>";
					str+="<div>"+(parseInt(yctr)+1)+" "+yearname+"<br/>"; //kill link to wikipedia
				} else {
					//str+="<div><a href='javascript:;'>"+parseInt(yctr)+" "+yearname+"<br/>";
					str+="<div>"+parseInt(yctr)+" "+yearname+"<br/>"; //kill link to wikipedia
				}
			} else { //mehrzahl
				if(self.lang=='de'){
					yearname='Jahre';
				} else if(self.lang=='fr') {
					if(parseInt(yctr)==0) {
						yearname='ann&eacute;e';
					} else {
						yearname='ann&eacute;es';
					}
				} else if(self.lang=='it') {
					if(parseInt(yctr)==0) {
						yearname='anno';
					} else {
						yearname='anni';
					}
				}
				if(month==12) { //increment the yearcounter and set month to 0
					if(parseInt(yctr)==0) { //special hack for boarder 0 to 1!
						if(self.lang=='de'){
							yearname='Jahr';
						} else if(self.lang=='fr') {
							yearname='ann&eacute;e';
						} else if(self.lang=='it') {
							yearname='anno';
						}
					}
					//alert("jahr mehrzahl, month==12, yearname: "+yearname+" yctr: "+parseInt(yctr));
					//str+="<div><a href='javascript:;'>"+(parseInt(yctr)+1)+" "+yearname+"<br/>";
					str+="<div>"+(parseInt(yctr)+1)+" "+yearname+"<br/>"; //kill link to wikipedia
				} else {
					//str+="<div><a href='javascript:;'>"+parseInt(yctr)+" "+yearname+"<br/>";
					str+="<div>"+parseInt(yctr)+" "+yearname+"<br/>"; //kill link to wikipedia
				}
			}
			var monthname="";
			if(parseInt(month)==1) { //text correction einzahl monat
				if(self.lang=='de'){
					monthname='Monat';
				} else if(self.lang=='fr') {
					monthname='mois';
				} else if(self.lang=='it') {
					monthname='mese';
				}
				if(month==12) {
					str+="0 "+monthname+"</a></div>";
				} else {
					str+=month+" "+monthname+"</a></div>";
				}
			} else { //mehrzahl
				if(self.lang=='de'){
					monthname='Monate';
				} else if(self.lang=='fr') {
					monthname='mois';
				} else if(self.lang=='it') {
					if(parseInt(month)==0) {
						monthname='mesi';
					} else if(parseInt(month)==1){
						monthname='mese';
					} else if(parseInt(month)>1) {
						monthname='mesi';
					}
				}
				if(yctr!=years) //end of scala
				{
					if(month==12) {
						//str+="0 "+monthname+"</a></div>";
						str+="0 "+monthname+"</div>"; //kill link to wikipedia
					} else {
						//str+=month+" "+monthname+"</a></div>";
						str+=month+" "+monthname+"</div>"; //kill link to wikipedia
					}
				} else {
					//str+='</a></div>';
					str+='</div>'; //kill link to wikipedia
				}
			}
			//str+="<br/>"+stepctr+"px";
			//str=(mctr.toString()+" m<p/><a href='javascript:;'>"+yctr+" Jahre</a></p>"+stepctr+"px");
			el.innerHTML=str;
			//alert(el.childNodes[1].childNodes[0]);
			/*if(self.lang=='de') { //german only!
				el.childNodes[1].childNodes[0].onclick=clickmark;
			}*/
			self.markElements.push(el);
			element.appendChild(el);
			mctr++;
			stepctr+=step;
			return;
		}
		
		if(stepctr<pixels-(together*step)) { //place package
			for(var z=0; z<together; z++) {
				placeMark();
			}
		} else { //place step by step
				placeMark();
		}
		var status=parseInt(stepctr/pixels*95); //fake it for long run menu link search!
		var statusText='';
		if(self.lang=='de') {
			statusText='Erstelle Skala';
		} else if(self.lang=='fr') {
			statusText="Cr&eacute;ation de l'&eacute;chelle";
		} else if(self.lang=='it') {
			statusText='Crea scala ';
		}
		if(status==95){
			if(self.lang=='de') {
				statusText='Zusammenstellung der Site';
			} else if(self.lang=='fr') {
				statusText="Composition du site";
			} else if(self.lang=='it') {
				statusText='Composizione del sito';
			}
		}
		self.updateBottlePreloader(status, statusText);
	}
}

siteLoader.prototype.findContainerLeft=function() { //find the left pos of the container!
	return document.getElementById("container").offsetLeft;
}

siteLoader.prototype.updateFixedPos=function(name, pos) {
	var element=document.getElementById(name);
	//alert(pos+this.findContainerLeft());
	element.style.left=(pos+this.findContainerLeft())+"px";
}

siteLoader.prototype.addSortimentMovie=function() {
	var el=document.getElementById('bottleSortiment');
	this.mountainEndHeight=document.getElementById('container').offsetHeight; //save the container height for placing
	el.style.top=(this.mountainEndHeight-350)+"px";
	//alert(el.style.top);
	var so=new SWFObject("../_flash/pal01.swf","pal","960","320", 8);
	so.addParam("scale","noscale"); //noscale
	so.addParam("salign","tl");
	so.addParam("swLiveConnect","true"); //update from javascript to flash
	so.addParam("name","pal");
	so.addParam("allowScriptAccess","always");
	so.addParam("wmode","transparent");
	so.write("bottleSortiment");
}

siteLoader.prototype.flashSortimentClicked=function(cat) { //load content in bottom div
	var el=document.getElementById('bottomdiv');
	var str=this.getContent(cat);
	el.innerHTML=str;
	//el.style.display='';
	this.setBottomContentHeight(null);
	el.style.display='';
	this.setBottomScrollHandler();
}

siteLoader.prototype.setBottomContentHeight=function(link) {
	var el=document.getElementById('contentb');
	if(el==null) {
		el=document.getElementById('contentbb');
		//alert("el is contentb: "+el);
	}
	if(el==null) {
		el=document.getElementById('contentbr');
		//alert("el is contentbr: "+el);
	}
	if(el==null) {
		el=document.getElementById('contentbs');
	}
	//alert("el is: "+el);
	var wheight=0;
	if(!this.ie) {
		wheight=window.innerHeight;
	} else {
		wheight=document.documentElement.clientHeight;
	}
	var curHeight=el.offsetHeight;
	var correction=0;
	if((link===null)||(link=='b1')||(link=='b2')||(link=='b3')||(link=='b15')) {
		correction=wheight-this.fromBottomDist;
	} else {
		correction=wheight-160;
	}
	if(curHeight>correction) {
		el.style.height=correction+"px";
	}
	/*document.getElementById('bscrollup').style.display='';
	document.getElementById('bscrolldown').style.display='';*/
	document.getElementById('closebdiv').style.display='';
}

siteLoader.prototype.setBottomScrollHandler=function() {
	//alert("setBottomScrollHandler for up: "+document.getElementById('bscrollup')+" and down: "+document.getElementById('bscrolldown'));
	var self=this;
	/*scrollMove=function(e){
		//alert("scroll move!");
		var el=document.getElementById('contentb');
		if(el==null) {
			el=document.getElementById('contentbb');
		}
		if(el==null) {
			el=document.getElementById('contentbr');
		}
		var direction=null;
		if(self.ie) {
			if(e.srcElement.id=='bscrollup') {
				//alert("scrolling up hit: "+e.srcElement.id);
				direction='up';
			} else {
				//alert("scrolling down hit: "+e.srcElement.id);
				direction='down';
			}
		} else {
			if(e.target.id=='bscrollup') { //scroll up
				//alert("scrolling up hit: "+e.target.id);
				direction='up';
			} else { //scroll down
				//alert("scrolling down hit: "+e.target.id);
				direction='down';
			}
		}
		if(direction=='up') { //the same for netscape 5, ie7
			//alert("scrollup");
			el.scrollTop-=100;
		} else {
			//alert("scrolldown");
			el.scrollTop+=100;
		}
	}
	if(this.ie&&this.version<7) {
		var ctr=0;
		var action = setInterval('wait()',500);
		wait=function() { 
			if(ctr==3) {
				clearInterval(action);
				self.addEvent(document.getElementById('bscrollup'),'click',scrollMove,false);
				self.addEvent(document.getElementById('bscrolldown'),'click',scrollMove,false);
			}
			ctr++;
		}
	} else { 
		this.addEvent(document.getElementById('bscrollup'),'click',scrollMove,false);
		this.addEvent(document.getElementById('bscrolldown'),'click',scrollMove,false);
	}*/
	document.getElementById('closebdiv').onclick=function() {
		//alert("close it!");
		var el=document.getElementById('contentb');
		if(el==null) {
			el=document.getElementById('contentbb');
		}
		if(el==null) {
			el=document.getElementById('contentbr');
		}
		if(el==null) {
			el=document.getElementById('contentbs');
		}
		el.style.display='none';
		document.getElementById('bscrollup').style.display='none';
		document.getElementById('bscrolldown').style.display='none';
		document.getElementById('closebdiv').style.display='none';
	}
}


/*
	send a mail
*/
siteLoader.prototype.sendMail=function(name,vorname,address,plzort,mail,msg,relother,relation,firma,age,tel) {
	var xmlHttp=this.createXMLHttpRequest();
	xmlHttp.open('POST', this.phpHandler+'?op=sendmail&name='+name+'&vorname='+vorname+'&address='+address+'&plzort='+plzort+'&mail='+mail+'&msg='+msg+'&relother='+relother+'&relation='+relation+'&firma='+firma+'&age='+age+'&tel='+tel+this.antiCacheStr(),false);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.send('op=sendmail&name='+name+'&vorname='+vorname+'&address='+address+'&plzort='+plzort+'&mail='+mail+'&msg='+msg+'&relother='+relother+'&relation='+relation+'&firma='+firma+'&age='+age+'&tel='+tel);
	if (xmlHttp.status == 200) {
    	if (xmlHttp.responseText) {
    		return xmlHttp.responseText;
        } else {
        	return "Cannot send mail, please try again later";
        }
    } else {
    	return "Cannot send mail, please try again later";
    }
}

/*
	check the mail and send it with the method above
*/
siteLoader.prototype.checkSendMail=function() {
	//alert("checkSendMail called");
	var mustFields=new Array('msg','relation','name','vorname','address','plzort','mail');
	var errStack=new Array();
	var err=false;
	for(var i=0;i<mustFields.length; i++) {
		var el=null;
		el=document.getElementsByName(mustFields[i]);
		if(el) { //if the field is there
			if(el[0].name=='relation') {
				for(y=0;y<el.length;y++) {
					if((el[y].value=='Andere')&&(el[y].checked)) {
						var relother=document.getElementsByName('relother');
						//alert('Andere is the choice! value of relother is: '+relother[0].value);
						if(relother[0].value=='') {
							errStack.push('Andere');
							err=true;
						}
					}
				}
			} else {
				if(el[0].value=="") {
					//alert("On or some fields are empty");
					switch(mustFields[i]) {
						case 'msg':
							errStack.push('Mitteilung');
							err=true;
							break;
						case 'name':
							errStack.push('Name');
							err=true;
							break;
						case 'vorname':
							errStack.push('Vorname');
							err=true;
							break;
						case 'address':
							errStack.push('Adresse');
							err=true;
							break;
						case 'plzort':
							errStack.push('PLZ/Ort');
							err=true;
							break;
						case 'mail':
							errStack.push('Email');
							err=true;
							break;
					}
				}
			}
		}
	}
	var errField=document.getElementById('senderror');
	var str='Fehler Bitte pr&uuml;fen Sie die Eingabe in: ';
	for(i=0; i<errStack.length; i++) {
		if(i!=errStack.length-1) {
			str+=errStack[i]+", "
		} else {
			str+=errStack[i];
		}
	}
	if(err) { //if error occured
		errField.innerHTML=str;
		return;
	} else {
		errField.innerHTML='&nbsp;';
		//name,vorname,address,plzort,mail,msg,relother,relation,firma,age,tel
		var name=document.getElementsByName('name')[0].value;
		var vorname=document.getElementsByName('vorname')[0].value;
		var address=document.getElementsByName('address')[0].value;
		var plzort=document.getElementsByName('plzort')[0].value;
		var mail=document.getElementsByName('mail')[0].value;
		var msg=document.getElementsByName('msg')[0].value;
		var relother=document.getElementsByName('relother')[0].value;
		var firma=document.getElementsByName('firma')[0].value;
		var age=document.getElementsByName('age')[0].value;
		var tel=document.getElementsByName('tel')[0].value;
		var relations=document.getElementsByName('relation')
		var relation=''
		for(var i=0; i<relations.length; i++) {
			if(relations[i].checked) {
				relation=relations[i].value;
			}
		}
		var response=this.sendMail(name,vorname,address,plzort,mail,msg,relother,relation,firma,age,tel);
		var answer=document.getElementById('mailanswer');
		answer.innerHTML=response;
		var el=document.getElementById('contentb');
		el.scrollTop+=200;
	}
	return;
}

/*
	add swf to playarea, don't add more then one
*/
siteLoader.prototype.playSound=function(file) {
	var el=null;
	el=document.getElementById('soundplayer');
	if(this.pSound) { //if playing, remove
		el.innerHTML='';
	}
	var so=new SWFObject("../_flash/sound/"+file,"sound","1","1", 8);
	so.addParam("quality", "high");
	so.addParam("loop","false");
	so.write('soundplayer');
	this.pSound=true;
}

siteLoader.prototype.antiCacheStr=function() {
	return('&randomcache='+new Date().getMilliseconds());
}

/*
	ie6 special hack for fixing png images
	not in class environment, so not use the keyword this!
	ie6 only!5ftr
*/
siteLoader.prototype.fixPNG=function(myImage) {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
	  	//alert("fixPNG processed");
	    var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
		var imgTitle = (myImage.title) ? 
			   "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
		var imgStyle = "display:inline-block;" + myImage.style.cssText
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
	    	          + " style=\"" + "width:" + myImage.width 
	                  + "px; height:" + myImage.height 
	                  + "px;" + imgStyle + ";"
	                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
		myImage.outerHTML = strNewHTML	  
	}
}
