/**
* home.js
* This file is used to load the javascript content for homepage
* @Author: Andrew Chan
* Created @ 2008-08-02
*/

window.url_location = "/home";
window.image_box = 1;
window.first_menu = "";
window.second_menu = "";
window.third_menu = "";

function switchPanel(status)
{
	if(status == 'open') {
		$("#expand_panel").slideToggle();
		$("#panelSwitcher").hide();
		}
	else if(status == 'close') {
		$("#expand_panel").slideUp();
		$("#panelSwitcher").show();
	}
}
	
function reloadPage()
{
	window.location.href = window.url_location;
	}	
	
function clickDetector(evt)
{	
	clearTimeout(window.ttt);
	evt=evt?evt:window.event;
	var srcElem=(evt.target)?evt.target:evt.srcElement;
	while(srcElem.tagName.toUpperCase()=="A" && srcElem.parentNode.tagName.toUpperCase()=="LI")
	{
		//exchange the srcElement's href
		if(srcElem.getAttribute("lang")!=null) src_href = srcElem.getAttribute("lang");
		else{
			src_href = srcElem.href;
			srcElem.setAttribute("lang",src_href);
			srcElem.lang = src_href;
			srcElem.href="#";
		}
		
		if(srcElem.parentNode.getAttribute("lang")!=null && srcElem.parentNode.className!="firstMenu")
		{
				window.url_location = src_href;
				window.ttt = setTimeout(reloadPage,"3000");
			}
		else if(srcElem.parentNode.className!="firstMenu") srcElem.href = src_href;		
		break;
		}
		
	}
	

//if(document.attachEvent) document.attachEvent("onclick", clickDetector);
//Else document.addEventListener("click", clickDetector, false);
	

//make navigation expand to proper section when in a subsection

  $(document).ready(function(){
	cur_location = window.location.href;
	cur_location = cur_location.replace("http://","");
	cur_location = cur_location.replace("#","");
	location_arr = cur_location.split("/");
	window.first_menu = location_arr[1];
	window.second_menu = location_arr[2];
	if(location_arr[3]!=undefined) window.third_menu = location_arr[3];
	resetMenuLocation();
	var flagi,flagj;
	//loop the first menu to check the current location
	$(".firstMenu a").each(function(i){
		var menu_text = this.innerHTML.toLowerCase();
		menu_text = menu_text.replace("|","");
		menu_text = menu_text.replace(" ","-");
		menu_text = menu_text.replace("&nbsp;&nbsp;","");
		menu_text = escape(menu_text).replace("%A0%A0","");
		//alert(menu_text);
		if(menu_text == window.first_menu){
				window.first_menu_num = $(this).parent().attr("lang");	
				$("#menu").children("li[lang="+window.first_menu_num+"]").css("display","inline");//.show();
				$(this).css("color","#336699").addClass("firstA");
				}
			}
		);
		
		//loop the sendMenu to check the current location
		$(".secondMenu[lang="+window.first_menu_num+"] a").each(function(i){
		var menu_link = this.href.toLowerCase();
		menu_link = menu_link.replace("http://","");
		menu_link = menu_link.replace("#","");
		var link_arr = menu_link.split("/");
		var menu_label = link_arr[link_arr.length-1];
	 	if(menu_label == window.second_menu){
	 			window.second_menu_num = $(this).parent().attr("lang");	
				flagi = $("#menu").children("li[lang="+window.second_menu_num+"]");
	 			$("#menu").children("li[lang="+window.second_menu_num+"]").css("display","inline");//.show();
	 			cur_html = $(this).html();
	 			$(this).css("color","#336699").addClass("secondANow");
	 			if(!window.third_menu){new_html = cur_html+"<img src='/_gr/_universal/arrow_left.gif' />";
	 					$(this).html(new_html);
	 				}
	 			}
			}
			);	
			
		//loop the thirdMenu to check the current location
		$(".thirdMenu[lang="+window.second_menu_num+"] a").each(function(i){
		var menu_link = this.href.toLowerCase();
		menu_link = menu_link.replace("http://","");
		menu_link = menu_link.replace("#","");
		var link_arr = menu_link.split("/");
		var menu_label = link_arr[link_arr.length-1];
	 	if(menu_label == window.third_menu){
	 			cur_html = $(this).html();
	 			$(this).css("color","#336699").addClass("secondANow");
	 			new_html = cur_html+"<img src='/_gr/_universal/arrow_left.gif' />";
	 			$(this).html(new_html);
	 			}
			}
			);			
				
		$("#image1_1").hide();
		$("#image1_2").hide();
		$("#image1_3").hide();
		imageBoxFadeIn();
		
	if(window.third_menu.indexOf("photos")>=0 || window.third_menu.indexOf("videos")>=0){
		$(".anyClass").jCarouselLite({
       	 	btnNext: ".next",
        	btnPrev: ".prev",
        	visible: 3,
        	circular: true,
        	vertical: true,
        	scroll: 3
    		});
			}

		
		//clear the search keyword when user click it
		$("#search_keyword").click(
		function(){
			$(this).attr("value","");
			}
		);
	});

	
//define the atimation function for specific page 
function imageBoxFadeIn(){
		if(window.image_box<=3){ 
			if(window.image_box!=0) $("#image1_"+window.image_box).fadeIn("slow");
			window.image_box++;
			if(window.image_box==0) setTimeout(imageBoxFadeIn,"100");
			else setTimeout(imageBoxFadeIn,"500");
		}
	}	
	
//define the function to reset the menu location
function resetMenuLocation(){
	if(window.first_menu=="seafood" && window.second_menu==undefined && window.third_menu==undefined){
		window.first_menu = "programs";
		window.second_menu = "seafood";
		}	
	else if(window.first_menu=="seafood" && window.second_menu=="seafood-guide"){
		window.first_menu = "programs";
		window.second_menu = "seafood";
		window.third_menu = "seafood-guide";
		}	
	else if(window.first_menu=="seafood"){
		window.first_menu = "programs";
		window.second_menu = "seafood";
		}	
	if(window.first_menu=="sushi" && window.second_menu==undefined && window.third_menu==undefined){
		window.first_menu = "programs";
		window.second_menu = "seafood";
		window.third_menu = "sushi";
		}
	//alert(window.second_menu);
	}	
	
function resetSearchForm(obj){
	if(obj.value=="Search") obj.value="";
	}	