//Menu page images path.
var menuImgPath="images/menu/";

// Sidelink mouseover change class.
function changeClass(obj){
	var cls = String(obj.className);
	cls = cls.replace('Def','Mo');
	obj.className = cls;
}
// Sidelink mouseout restore class
function restoreClass(obj){
	var cls = String(obj.className);
	cls = cls.replace('Mo','Def');
	obj.className = cls;
}

//onclick of the tds
function gotoPage(pgURL){
	//alert(pgURL)
	window.location = pgURL;
}

//popup opener.
function popUp(URL,sbar,wd,ht,rz) {
	rz = (rz == "undefined")?0:1;
	//alert(rz)
	day = new Date();
	id = day.getTime();
	features = 'scrollbars='+sbar+',resizable='+rz+',toolbar=0,location=0,statusbar=1,menubar=0,left=20,top=20,width=' + wd + ',height='+ht;
	window.open(URL,id,features);
}

//no more in use
function getURL(obj){
	//alert(obj.selectedIndex);
	//alert(obj.options[obj.selectedIndex].text);
	selectedItem = obj.value;
	if(selectedItem != ""){
		//alert(obj.options[this.selectedIndex].text)
		///gotoPage(obj.options[obj.selectedIndex].text + '.htm');
		//gotoPage(selectedItem);
		//alert(selectedItem)
	}
}

//home page onload action.
function initPg(){
	if(init.arguments.length > 0){
		document.getElementById('home').display = "none";
	}
	MM_preloadImages('images/toplinks/aboutMo.gif','images/toplinks/menuMo.gif','images/toplinks/storesMo.gif','images/toplinks/carreersMo.gif','images/toplinks/cafeBeatMo.gif','images/toplinks/merchandiseMo.gif','images/toplinks/citizenMo.gif')
}

// Onselecting the item in menucard dropdown jump to menu-inside.htm and to the selected anchor.
// Also display proper text below the image.
function  showItem(obj){
	var locationStr = String(window.location);
	var	pgLocation = "menu-inside.htm";
	//if called from inside page calculate 
	// I can calculate the page loaction in following script.
	// menu-inside is the only page where this functionality is requires.
	// That is why pgLocation is hardcoded.
/*
	if(flag == "inside")
		pgLocation = String(window.location).substring(0,String(window.location).indexOf("#"))
	else
		pgLocation = "menu-inside.htm";
*/
	//alert(obj.options[obj.selectedIndex].text);
	//alert(document.getElementById("galleryImage").getAttribute("src"));
	displayImage(obj.value);
	
	if(obj.options[obj.selectedIndex].text == "Select")
		displayText("Caf&eacute; Coffee Menucard");
	else
		displayText(obj.options[obj.selectedIndex].text);
	
	//Calculate anchorname - remove extension of the image inside value of dropdown.			
	anchorName = obj.value.toString().substring(0,obj.value.toString().length-4);
	//alert(pgLocation);
	window.location = (pgLocation + "#" + anchorName);
}

// Onload of menu-inside page change the gallery image.
function changeItem(){
	var locationStr = String(window.location)
	//Get the anchor name which is image name.
	var itemName = locationStr.substring(locationStr.indexOf("#")+1,locationStr.length)
	displayImage(itemName)
	//alert(locationStr + " " + locationStr.indexOf("#") + " " +locationStr.length)
	//alert(itemName)
}

//Menupage text below the image.
function displayText(txt){
	document.getElementById("itemName").innerText = txt;
}

//Menupage change side image.
function displayImage(imgName){
	var imgSrc = menuImgPath + imgName;
	document.getElementById("dynamicImage").setAttribute("src",imgSrc);
}
// Show mouseover image in store locator.
function showLayer(x,y,imgSrc){
	var obj = document.getElementById('addressLayer');
	obj.style.pixelLeft = x;
	obj.style.pixelTop = y;
	obj.innerHTML = "<img src='images/stores/"+ imgSrc +"'>";
	obj.display = "block";	
}

// Hide mouseover image in store locator.
function hideLayer(){
	var obj = document.getElementById('addressLayer');
	obj.style.pixelLeft = -100;
	obj.style.pixelTop = -100;
	document.getElementById('addressLayer').display = "none";
}

// Show store address.
function showStoreAdd(storeLocation){
	//alert(address[storeLocation])
	document.getElementById('storeLocationDiv').innerHTML = address[storeLocation];
}

// Show all store addresses.
function viewAll(){
	var allAdd = ""
	for(i in address){
		allAdd += address[i];
	}
	document.getElementById('storeLocationDiv').innerHTML = allAdd;
}

//Loop right side images
function loopImages(){
	var imgPath = displayImgPath + prefix + imgCounter + ".jpg"
	document.getElementById('dynamicImage').setAttribute("src",imgPath);
	//document.getElementById('showCaseText').innerHTML = showCaseText[imgCounter];
	imgCounter++;
	if(imgCounter >= totalImges) imgCounter = 0;
	
	imgTimer = setTimeout("loopImages()",delayDuration * 1000)
}

/*
//Loop format image.
function loopFormatImages(){
	var imgPath = formatImgPath + 'format'  + imgFormatCounter + ".jpg"
	document.getElementById('formatImage').setAttribute("src",imgPath);

	imgFormatCounter++;
	if(imgFormatCounter >= totFormatImg) imgFormatCounter = 0;
	
	imgFormatTimer = setTimeout("loopFormatImages()",formateDuration * 1000)
}
*/
var obj = null;
var fadeTimer=null;
function intiFading(){
	obj = document.getElementById('dynamicImage');
	fadeInImage();
}

function fadeInImage(){
	//alert(obj);
	obj.filters.alpha.opacity += 10;
	//alert(obj.filters.alpha.opacity)
	if(obj.filters.alpha.opacity >= 100){
		clearTimeout(fadeTimer)
		fadeTimer=setTimeout('fadeOutImage()',delayDuration * 1000);
	}
	else{
		fadeTimer = setTimeout('fadeInImage()',opacityChanger*10)
	}
}

function fadeOutImage(){
	//alert(obj);
	obj.filters.alpha.opacity -= 10;
	//alert(obj.filters.alpha.opacity)
	if(obj.filters.alpha.opacity <= 0){
		clearTimeout(fadeTimer)
		changeShowcaseImage();
		//fadeOutImage();
	}
	else{
		fadeTimer = setTimeout('fadeOutImage()',opacityChanger*10)
	}
}

function changeShowcaseImage(){
	var imgPath = displayImgPath + prefix + imgCounter + ".jpg"
	document.getElementById('dynamicImage').setAttribute("src",imgPath);
	//document.getElementById('showCaseText').innerHTML = showCaseText[imgCounter];
	imgCounter++;
	if(imgCounter >= totalImges) imgCounter = 0;
	
	fadeInImage()
}
