var old_tab = '1';
var old_con = '1';
var push_height = 220;
var gallery_length = 21;

$(document).ready(function(){

	//$(document).pngFix();
	$('.president_control').children('.prev').css('visibility', 'hidden');
	$('.scroller').jScrollPane({showArrows:true, scrollbarWidth: 36, dragMinHeight:0, dragMaxHeight: 0, reinitialiseOnImageLoad: true});
	$('.scroller2').jScrollPane({showArrows:true, scrollbarWidth: 36, dragMinHeight:0, dragMaxHeight: 0, reinitialiseOnImageLoad: true});
	$('.scroller3').jScrollPane({showArrows:true, scrollbarWidth: 36, dragMinHeight:0, dragMaxHeight: 0, reinitialiseOnImageLoad: true});
	$('.scroller4').jScrollPane({showArrows:true, scrollbarWidth: 36, dragMinHeight:0, dragMaxHeight: 0, reinitialiseOnImageLoad: true});
	
	$('.enlarge a').lightBox({fixedNavigation:true});
	$('#gallery a').lightBox({fixedNavigation:true});
	
	for (var i=1; i<=gallery_length; i++){
		$('.gallery'+i+' a').lightBox({fixedNavigation:true});
	}
	
	$('img.btn_over').mouseover(function(){
		if ($(this).parent('a').hasClass('selected')){
		}
		else
			$(this).attr('src', $(this).attr('src').toString().replace('.gif','_over.gif').replace('.jpg','_over.jpg').replace('.png','_over.png'));
	}).mouseout(function(){
		if ($(this).parent('a').hasClass('selected')){}
		else
			$(this).attr('src', $(this).attr('src').toString().replace('_over.gif','.gif').replace('_over.jpg','.jpg').replace('_over.png','.png'));
	});
	$('img.btn_over').each(function(){
		if ($(this).parent('a').hasClass('selected')){
			$(this).attr('src', $(this).attr('src').toString().replace('.gif','_over.gif').replace('.jpg','_over.jpg').replace('.png','_over.png'));
		}
	})
	$('.tab').children('div:gt(1)').hide();
	
	$('.img_container').children('a').children('img').hover(
		function(){
			if(jQuery.browser.version == '6.0'){
				//alert(currentLang);
				if($(this).attr('id').toString().search('1') != -1){
					$('.img').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product01_l.png');
					$('.section').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product01_banner.png');
				}else if($(this).attr('id').toString().search('2') != -1){
					$('.img').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product02_l.png');
					$('.section').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product02_banner.png');
				}else if($(this).attr('id').toString().search('3') != -1){
					$('.img').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product03_l.png');
					$('.section').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product03_banner.png');
				}else if($(this).attr('id').toString().search('4') != -1){
					$('.img').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product04_l.png');
					$('.section').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product04_banner.png');
				}else if($(this).attr('id').toString().search('5') != -1){
					$('.img').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product05_l.png');
					$('.section').children('img').attr('src' , '../../filemanager/template/'+currentLang+'/images/skin_product05_banner.png');
				}
			}
			else{
				var src=$(this).attr('src').replace('_over.png','_l.png');
				var banner = $(this).attr('src').replace('_over.png','_banner.png');
				$('.img').children('img').attr('src' , ''+src+'');
				$('.section').children('img').attr('src' , ''+banner+'');
			}
		},function(){
			//$('.img').children('img').attr('src' , '');
		}
	);
	var height = $('#left_nav').innerHeight();
	height -= 128;
	if (height > $('.word').innerHeight())
	{
		var add_height = height - $('.word').innerHeight();
		$('.push').css('height', add_height);
		//$('.word').css('width', $('.word').innerWidth()-50);
	}
	
	$('.faci_detail').hide();
	$('.faci_open').children('img').bind('click', function(){
		$(this).parent('div').parent('div').parent('div').addClass('on');
		$(this).parent('div').parent('div').parent('div').children('.faci_detail').show();
		$(this).hide();
		var added = parseInt($(this).parent('div').parent('div').parent('div').children('.faci_detail').innerHeight());
		push_height = push_height + added;
		if(jQuery.browser.version == '6.0'){
			push_height -= 400;
			$('.faci_push').css('height' , push_height);
		}else
			$('.faci_push').css('height' , push_height);
	});
	$('.faci_close').children('img').bind('click', function(){
		var minus = parseInt($(this).parent('div').parent('div').parent('div').children('.faci_detail').innerHeight());
		$(this).parent('div').parent('div').parent('div').children('.faci_detail').hide();
		push_height -= minus;
		if(jQuery.browser.version == '6.0'){
			push_height -= 400;
			$('.faci_push').css('height' , push_height);
		}else
			$('.faci_push').css('height' , push_height);
		$(this).parent('div').parent('div').parent('div').removeClass('on');
		$(this).parent('div').parent('div').parent('div').children('.facial_title').children('.faci_open').children('img').show();
	});
	
	$('.news').children('.img_align_center').each(function(){
		$(this).css('width', $(this).children('img').innerWidth());
		$(this).parent('.news').children('.enlarge').css('width', $(this).children('img').innerWidth());
	});
	
	$('.president_control').children('.next').bind('click', function(){
		$('#cont'+old_con).css('visibility', 'hidden');
		if (parseInt(old_con) == 3)
			alert('');
		else if(parseInt(old_con) == 2)
		{
			old_con = '3';
			$('.president_control').children('.prev').css('visibility', 'visible');
			$('#cont'+old_con).css('visibility', 'visible');
			$('.president_control').children('.next').css('visibility', 'hidden');
		}else{
			old_con = '2';
			$('.president_control').children('.prev').css('visibility', 'visible');
			$('#cont'+old_con).css('visibility', 'visible');
		}
	});
	
	$('.president_control').children('.prev').bind('click', function(){
		$('#cont'+old_con).css('visibility', 'hidden');
		if (parseInt(old_con) == 3){
			old_con = '2';
			$('.president_control').children('.next').css('visibility', 'visible');
			$('#cont'+old_con).css('visibility', 'visible');
		}else if(parseInt(old_con) == 2){
			old_con = '1';
			$('.president_control').children('.next').css('visibility', 'visible');
			$('#cont'+old_con).css('visibility', 'visible');
			$('.president_control').children('.prev').css('visibility', 'hidden');
		}//else 
			
	});
});


function switch_tab(tab_id){
	if (old_tab != tab_id){
		$('.push').css('height', 'auto');
		$('#tab'+old_tab).css('display','none');
		$('#tab_link'+old_tab).attr('class','');
		$('#tab_link'+old_tab).children('img').attr('src', $('#tab_link'+old_tab).children('img').attr('src').toString().replace('_over.gif','.gif').replace('_over.jpg','.jpg').replace('_over.png','.png'));
		$('#tab'+tab_id).css('display','block');
		//extendTab();
		$('#tab_link'+tab_id).attr('class','selected');
		old_tab = tab_id;
		extendTab();
		var height = $('#left_nav').innerHeight();
		height -= 128;
		if (height > $('.word').innerHeight())
		{
			var add_height = height - $('.word').innerHeight();
			$('.push').css('height', add_height);
		}
	}
}

function extendTab(){
	$('#tab'+old_tab+' .left').css('height', $('#tab'+old_tab+' .middle').innerHeight()+'px');
	$('#tab'+old_tab+' .right').css('height', $('#tab'+old_tab+' .middle').innerHeight()+'px');
}

function extendTab2(){
	$('.left').css('height', $('.mid').innerHeight()+'px');
	$('.right').css('height', $('.mid').innerHeight()+'px');
}

function extendTab3(tab_no){
	$('#tab'+tab_no+' .left').css('height', $('#tab'+tab_no+' .middle').innerHeight()+'px');
	$('#tab'+tab_no+' .right').css('height', $('#tab'+tab_no+' .middle').innerHeight()+'px');
}

function jumpNav(nav, lang){
	
	var temp = getPath();
	if (typeof(lang) == "undefined")
	{
		lang = temp[1];
	}
	var currentPath2 = temp[0] + '/';
	
	if (nav == 0)
		window.location.href = currentPath2 + "index.html";
	else if (nav == 1)
		window.location.href = currentPath2 + lang + "/food/index.html";
	else if(nav == 2)
		window.location.href = currentPath2 + lang + "/skin/index.html";
	else if(nav == 3)
		window.location.href = currentPath2 + lang + "/facial/index.html";
	else if(nav ==4 )
		window.location.href = currentPath2 + lang + "/share/index.html";
	else if(nav ==5 )
		window.location.href = currentPath2 + lang + "/news/index.html";
	else if(nav ==6 )
		window.location.href = currentPath2 + lang + "/president_share/index.html";	
	else if(nav ==7 )
		window.location.href = currentPath2 + lang + "/intro/index.html";	
}

function jumpLang(language){
	var url = window.location.toString();
	var isStaticURL = false;
	var langPaths = new Array("en", "tc", "sc");
	var oldLangPath = "";

	// Check url type (is static page or dynamic page)
	for (i=0; i < langPaths.length; i++){
		if (url.indexOf("/"+langPaths[i]+"/") != -1){
			oldLangPath = "/"+langPaths[i]+"/";
			isStaticURL = true;
			break;
		}
	}

	
		var path;
		path = window.location.href;
		window.location = path.replace(oldLangPath, "/"+language+"/");
		
}

function jumpDetail(detail, lang){
	//alert(detail+","+lang);
	var temp = getPath();
	var currentPath2 = temp[0] + '/';
	if (detail == 1){
		window.location.href = currentPath2 + lang + "/food/index.html";
	}else if (detail == 2){
		if(lang == 'en'){
			window.location.href = currentPath2 + lang + "/skin/index.html";
		}else{
			window.location.href = currentPath2 + lang + "/skin/squina_natural/index.html";
		}
	}else if (detail == 3){
		if(lang == 'en'){
			window.location.href = currentPath2 + lang + "/skin/index.html";
		}else{
			window.location.href = currentPath2 + lang + "/skin/cbon/index.html";
		}
	}else if (detail == 4){
		if(lang == 'en'){
			window.location.href = currentPath2 + lang + "/skin/index.html";
		}else{
			window.location.href = currentPath2 + lang + "/skin/sqa_natural/index.html";
		}
	}else if (detail == 0){
		if(lang == 'en'){
			window.location.href = currentPath2 + lang + "/skin/index.html";
		}else{
			window.location.href = currentPath2 + lang + "/skin/facialist/index.html";
		}
	}
}

function jumpFoot(page, lang){
	var temp = getPath();
	var currentPath2 = temp[0] + '/';
	if (page == 'shop')
		window.location.href = currentPath2 + lang + "/store/index.html";
	else if (page == 'Contact')
		window.location.href = currentPath2 + lang + "/contact_us/index.html";
		
}

function jumPop(){
	var temp = getPath();
	var currentPath2 = temp[0] + '/';
	var image = 'popup_ad.jpg';
	var url = '';
	url = currentPath2 + 'filemanager/template/common/images/' + image;
	window.open(url);
}
