//Variable holds Main Menu
var myMenu =new Array();
// Stores selected Navigation
var	selectedMenu;
var	selectedSubMenu;

//Function to hold the sub menu objects
// name = name used to link with the Div - txt e.g. 
// <Div id='TestTxt'>text in here</div> therefore name world = Test
// img = Mouse image normal
// imgMo = Mouse over image
// pic = Main image displayed when you click on menu item
function SubMenu(name,img,imgMo,pic)
{	
	this.name = name;	
	
	image = new Image();
	image.src = img;
	this.img = img;
	
	imageMouseOver = new Image();
	imageMouseOver.src = imgMo;
	this.imgMo = imgMo	
	
	this.pic = pic;
}

//Function to hold Main menu objects
//Same as Sub Menu
//subMenus = Array of sub menu objects
function MainMenu(name,imgMo,img,subMenus,titleImg,pic)
{
	this.name = name;
	this.subMenus = subMenus;
	
	image = new Image();
	image.src = img;
	this.img = img;
	
	imageMouseOver = new Image();
	imageMouseOver.src = imgMo;
	this.imgMo = imgMo	
	
	imagetitle = new Image();
	imagetitle.src = titleImg;
	this.titleImg = titleImg
	
	this.pic = pic;
}


//Build Sub Menu 1
var arbeitSub=new Array();
arbeitSub[0]=new SubMenu("badewelten","images/navigation/sub/4u-nav_nav1.gif","images/navigation/sub/4u-nav-A_nav1.gif","images/navigation/pictures/5foto_nav1.jpg");
arbeitSub[1]=new SubMenu("wasser","images/navigation/sub/1u-nav_nav1.gif","images/navigation/sub/1u-nav-A_nav1.gif","images/navigation/pictures/2foto_nav1.jpg");
arbeitSub[2]=new SubMenu("gebaud","images/navigation/sub/2u-nav_nav1.gif","images/navigation/sub/2u-nav-A_nav1.gif","images/navigation/pictures/3foto_nav1.jpg");
arbeitSub[3]=new SubMenu("wellness","images/navigation/sub/3u-nav_nav1.gif","images/navigation/sub/3u-nav-A_nav1.gif","images/navigation/pictures/4foto_nav1.jpg");
//Build Menu 1
myMenu["arbeit"] = new MainMenu("arbeitsgebiete","images/navigation/main/1-nav-A.gif","images/navigation/main/1-nav.gif",arbeitSub,"images/navigation/titles/claim1_nav1.gif","images/navigation/pictures/1foto_nav1.jpg");

//Build Sub Menu 2
var referenzSub=new Array();	
referenzSub[0]=new SubMenu("ref_sanitaer","images/navigation/sub/1u-nav_nav2.gif","images/navigation/sub/1u-nav-A_nav2.gif","images/navigation/pictures/14foto_nav2.jpg");
referenzSub[1]=new SubMenu("ref_bedachungen","images/navigation/sub/2u-nav_nav2.gif","images/navigation/sub/2u-nav-A_nav2.gif","images/navigation/pictures/14foto_nav2.jpg");
referenzSub[2]=new SubMenu("ref_spenglerei","images/navigation/sub/3u-nav_nav2.gif","images/navigation/sub/3u-nav-A_nav2.gif","images/navigation/pictures/14foto_nav2.jpg");
referenzSub[3]=new SubMenu("ref_rohrsanierungen","images/navigation/sub/4u-nav_nav2.gif","images/navigation/sub/4u-nav-A_nav2.gif","images/navigation/pictures/14foto_nav2.jpg");
referenzSub[4]=new SubMenu("ref_badezimmer","images/navigation/sub/5u-nav_nav2.gif","images/navigation/sub/5u-nav-A_nav2.gif","images/navigation/pictures/14foto_nav2.jpg");
referenzSub[5]=new SubMenu("ref_solarenergie","images/navigation/sub/6u-nav_nav2.gif","images/navigation/sub/6u-nav-A_nav2.gif","images/navigation/pictures/14foto_nav2.jpg");
//Build Menu 2
myMenu["referenz"] = new MainMenu("referen","images/navigation/main/2-nav-A.gif","images/navigation/main/2-nav.gif",referenzSub,"images/navigation/titles/claim2_nav2.gif","images/navigation/pictures/14foto_nav2.jpg");

//Build Sub Menu 3
var uberSub=new Array();
uberSub[0]=new SubMenu("gruender","images/navigation/sub/6u-nav_nav3.gif","images/navigation/sub/6u-nav-A-nav3.gif","images/navigation/pictures/11foto_nav3.jpg");
uberSub[1]=new SubMenu("team","images/navigation/sub/1u-nav_nav3.gif","images/navigation/sub/1u-nav-A_nav3.gif","images/navigation/pictures/6foto_nav3.jpg");
uberSub[2]=new SubMenu("engage","images/navigation/sub/2u-nav_nav3.gif","images/navigation/sub/2u-nav-A_nav3.gif","images/navigation/pictures/7foto_nav3.jpg");	
uberSub[3]=new SubMenu("press","images/navigation/sub/3u-nav_nav3.gif","images/navigation/sub/3u-nav-A_nav3.gif","images/navigation/pictures/8foto_nav3.jpg");	
uberSub[4]=new SubMenu("offene","images/navigation/sub/4u-nav_nav3.gif","images/navigation/sub/4u-nav-A_nav3.gif","images/navigation/pictures/9foto_nav3.jpg");
uberSub[5]=new SubMenu("standort","images/navigation/sub/5u-nav_nav3.gif","images/navigation/sub/5u-nav-A_nav3.gif","images/navigation/pictures/10foto_nav3.jpg");
//Build Menu 3
myMenu["uber"] = new MainMenu("uber","images/navigation/main/3-nav-A.gif","images/navigation/main/3-nav.gif",uberSub,"images/navigation/titles/claim3_nav3.gif","images/navigation/pictures/5foto_nav3.jpg");

//Build Sub Menu 4
var unsereSub=new Array();
//Build Menu 4
myMenu["unsere"] = new MainMenu("unsere","images/navigation/main/4-nav-A.gif","images/navigation/main/4-nav.gif",unsereSub,"images/navigation/titles/claim4_nav4.gif","images/navigation/pictures/11foto_nav4.jpg");

//Build Sub Menu 5
var kontaktSub=new Array();
kontaktSub[0]=new SubMenu("kontactform","images/navigation/sub/1u-nav_nav5.gif","images/navigation/sub/1u-nav-A_nav5.gif","images/navigation/pictures/13foto_nav5.jpg");
//Build Menu 5
myMenu["kontakt"] = new MainMenu("kontakt","images/navigation/main/5-nav-A.gif","images/navigation/main/5-nav.gif",kontaktSub,"images/navigation/titles/claim5_nav5.gif","images/navigation/pictures/12foto_nav5.jpg");
	
//PreCache Main Images
imageA = new Image();
imageA.src = "images/navigation/main/AKTUELL_nav-A.gif";

//Calss to build main menu
function BuildMainMenu()
{
	var nav = document.getElementById('navigation');
	var buildHtml = "";		
	for (myItem in myMenu)
	{
		buildHtml+="<BR /><img src='" + myMenu[myItem].img + "' onmouseover=\"JavaScript:MouseOverImage(this,'" + myMenu[myItem].imgMo + "')\" ";
		buildHtml+="onmouseout=\"JavaScript:MouseOverImage(this,'" + myMenu[myItem].img + "')\"onclick=\"NavClicked(this,'"+ myItem +"')\"	class=\"navMouse\" id=\"mn_" + myMenu[myItem].name + "\"/>";
	}
	nav.innerHTML = buildHtml;
	
}

//Builds the sub menu
function BuildSubMenu(menu)
{
	var nav = document.getElementById('subNav');
	var buildHtml = "";		
	for (myItem in myMenu[menu].subMenus)
	{
		buildHtml+="<BR /><img src='" + myMenu[menu].subMenus[myItem].img + "' onmouseover=\"JavaScript:MouseOverImage(this,'" + myMenu[menu].subMenus[myItem].imgMo + "',1)\" ";
		buildHtml+="onmouseout=\"JavaScript:MouseOverImage(this,'" + myMenu[menu].subMenus[myItem].img + "',1)\"onclick=\"SubNavClicked(this,'"+ menu +"','"+ myItem +"')\"	class=\"navMouse\"/>";
	}
	nav.innerHTML = buildHtml;	
}

// Called when Main Navigation Menu is clicked
function NavClicked(obj,menu)
{
	// hide ticker
	//$('#ticker').hide();
	
	// Changes the background image
	document.getElementById('main').className='main2';
	// Stores the menu item selected
	if (selectedMenu!=null)
	{
		selectedMenu.selected = null;
		selectedMenu.src = selectedMenu.oldSrc;
	}
	selectedMenu=obj;
	obj.selected = true;
	//Dynamically builds the sub menu
	BuildSubMenu(menu);
	name = myMenu[menu].name;
	// Sets the title, picture and text
	document.getElementById('title').src=myMenu[menu].titleImg;
	document.getElementById('picture').src=myMenu[menu].pic;
	var myText = document.getElementById('lyr1');
	myText.innerHTML = document.getElementById('txt' + name ).innerHTML;
	DisplayArrows()	
}

// Call to reset display and menus
function Reset()
{
	document.getElementById('main').className='main';	
	document.getElementById('subNav').innerHTML="";
	document.getElementById('lyr1').innerHTML="";
	document.getElementById('title').src="images/page_elements/transparent.gif";
	document.getElementById('picture').src="images/page_elements/transparent.gif";
	document.getElementById('arrows').className='arrowsHidden';	
	document.getElementById('personal').className="personal";
	document.getElementById('email').className="personal";
	// hide ticker
	// $('#ticker').show();
	BuildMainMenu()
}

//Called when sub navigation menu is clicked
function SubNavClicked(obj,menu,myItem)
{
	// Stores the sub menu item selected
	if (selectedSubMenu!=null)
	{
		selectedSubMenu.selected = null;
		selectedSubMenu.src = selectedSubMenu.oldSrc;
	}
	selectedSubMenu=obj;
	obj.selected = true;
	// Sets the picture and text
	document.getElementById('picture').src=myMenu[menu].subMenus[myItem].pic;
	
	// Sets the contents for the text except for the kontact form
	if (myMenu[menu].subMenus[myItem].name=="kontactform")
	{
		em = document.getElementById('email');
		em.innerHTML = "<iframe src='email.html' frameborder='0' height='307px' width='351px' ></iframe>"
		em.className ="personalShow"
	}
	else if (menu=="referenz")
	{
		em = document.getElementById('email');

		em.innerHTML = "<div id=\"FlabellComponent\"><p>Um diese Funktionalität nutzen zu können, benötigen Sie Flash Player 9+!</p><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\"/></a></div>"
		var cacheBuster = "?t=" + Date.parse(new Date());		
		var stageW = "351";
		var stageH = "307";
		var attributes = {};
		attributes.id = 'FlabellComponent';
		attributes.name = attributes.id;
		var params = {};
		params.bgcolor = "#ffffff";
		var flashvars = {};				
		flashvars.componentWidth = stageW;
		flashvars.componentHeight = stageH;
		flashvars.pathToFiles = "fadeinout/";
		flashvars.xmlPath = "xml/"+myMenu[menu].subMenus[myItem].name+".xml";						
		swfobject.embedSWF("preview.swf"+cacheBuster, attributes.id, stageW, stageH, "9.0.124", "javaScript/expressInstall.swf", flashvars, params);
		if(swfmacmousewheel) swfmacmousewheel.registerObject(attributes.id);
		document.getElementById('title').src="images/page_elements/transparent.gif";

		em.className ="personalShow"
	}
	else

	{
		document.getElementById('lyr1').innerHTML = document.getElementById('txt' + myMenu[menu].subMenus[myItem].name).innerHTML;
		DisplayArrows()	
	}
	
}


// Function displays the arrows if needed
function DisplayArrows()
{
	initScrollLayer()
	document.getElementById('personal').className="personal";
	document.getElementById('personImage').src="images/page_elements/transparent.gif";
	document.getElementById('email').className="personal";
	var myText=document.getElementById('lyr1');

	var x,y;
	var test1 = myText.scrollHeight;
	var test2 = myText.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		x = myText.scrollWidth;
		y = myText.scrollHeight;
	}
	else // Explorer Mac;
		 //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		x = myText.offsetWidth;
		y = myText.offsetHeight;
	}
	
	if (y>302)
	{
		document.getElementById('arrows').className='arrowsShow';	

		
	}
	else 
	{
		document.getElementById('arrows').className='arrowsHidden';	
	
	}

}


//Changes the imaage on mouse over
function MouseOverImage(obj,newImage,type)
{
	var imageLoc=  newImage;;
	if (obj.selected==null)
	{
		obj.src = imageLoc
	}
	else
	{
		if (type==null)
		{
			selectedMenu.oldSrc=imageLoc;
		}
		else 
		{
			selectedSubMenu.oldSrc=imageLoc;
		}
	}
}

// Function displays text on team menu click
function DisplayText(display)
{
	document.getElementById('picture').src="images/navigation/pictures/teamseite_nav3.jpg";
	document.getElementById('lyr1').innerHTML = document.getElementById(display).innerHTML;
}

// Mouse over .. spec changed that why this is here
function TeamMouseOver(objT,classT)
{
		objT.className=classT;
}


// Called when you need to display a specific person
function ShowPerson(pImage,pName,pDesc)
{
	document.getElementById('personImage').src="images/personel/"+pImage+".jpg"
	document.getElementById('personTitle').innerHTML = pName
	document.getElementById('personDesc').innerHTML = pDesc
	document.getElementById('personal').className="personalShow"	
}

/* This function is called when you need to show a refence*/
function ShowReference(pImage)
{
	document.getElementById('personTitle').innerHTML = ""
	document.getElementById('personDesc').innerHTML = ""
	document.getElementById('personImage').src="images/reference/"+pImage+".png"
	document.getElementById('personal').className="personalShow"	
}


// Image displayed when Aktuel is clicked
function AktuelClick(pImage)
{
	// hide ticker
	// $('#ticker').hide();
	
	DisplayArrows();
	BuildMainMenu();
	document.getElementById('main').className='main2';
	//document.getElementById('email').innerHTML="<img src='images/reference/"+pImage+".png' onclick=\"ShowContact()\" class=\"navMouse\" />"
	document.getElementById('email').innerHTML="<a href=\"http://www.ottostoffelag.ch/wassersparen\" target=\"_blank\"><img src='images/reference/"+pImage+".png' class=\"navMouse\" /></a>"
	document.getElementById('email').className="personalShow"
	document.getElementById('picture').src = "images/navigation/pictures/15foto_aktuell.jpg";
	document.getElementById('title').src="images/page_elements/transparent.gif";
	document.getElementById('subNav').innerHTML="";
	 
}

// Reference Display
function RefClick(refID)
{
	
	DisplayArrows();
	BuildMainMenu();




	 
}


// show contact
function ShowContact()
{
	
	NavClicked(document.getElementById('mn_kontakt'),'kontakt');

}

// ticker

jQuery.fn.ticker = function(optionen){
	var e = $(this);
	var destination = 0;

	if ($('#ticker').data('direction') == 0)
	{
		destination = optionen.leftStop;
		$('#ticker').data('direction', 1);
	} else {
		destination = optionen.rightStop;
		$('#ticker').data('direction', 0);
	}

	e.animate({
		'left': destination
	}, {
		duration: optionen.dauer,
		complete: function(){
			e.ticker({ leftStop: optionen.leftStop, rightStop: optionen.rightStop, dauer: optionen.dauer });
		}
	});
}

$(document).ready(function(){
	$('#ticker').click(function() {
		document.location = 'http://wassersparen.ottostoffelag.ch';
	});

	$('#ticker').data('direction', 0);
	$('#ticker').ticker({
	leftStop: 18,
	rightStop: 409,
	dauer: 8000
	});
});

