﻿$(document).ready(function() {
//leftmenu js
	$("#leftmenu li").each(function() {
				var withMouseEnter = "";
			  $(this).mouseover(function(){
				  if(withMouseEnter=="") {
				  withMouseEnter=$(this).attr("id");
				  var subheight = $(this).children("div").height()>50?$(this).children("div").height():50;
				  subheight = 100;
				  $(this).stop(true,true);
				  $(this).children("h3").stop(true,true);
				  $(this).children("span").stop(true,true);
				  $(this).children("div").stop(true,true);
				  $(this).siblings("li").removeClass("active").animate({backgroundColor:"#fff",color:"#000",height:"25px"}, 1000);
				  $(this).siblings("li").children("h3").animate({paddingTop:"0"}, 1000);
				  $(this).siblings("li").children("span").fadeOut(1000);
				  $(this).siblings("li").children("div").animate({"width":"0"},100);
				  $(this).addClass("active").animate({backgroundColor:"#000",color:"#fff",height:subheight+20+"px"}, {duration:1000,complete:function(){$(this).children(".left_menu_sub_panel").animate({"width":"372px"},500);}});
				  $(this).children("h3").animate({paddingTop:subheight/3+"px"}, 1000);
				  $(this).children("span").fadeIn(1000);
				  }
				  });
				 $(this).mouseleave (function () {
					if(withMouseEnter==$(this).attr("id")) {
				  $(this).siblings("li").stop(true,true);
				  $(this).siblings("li").children("h3").stop(true,true);
				  $(this).siblings("li").children("span").stop(true,true);
				  $(this).siblings("li").children("div").stop(true,true);
				  $(this).stop(true,true);
				  $(this).children(".left_menu_sub_panel").stop(true,true);
				  $(this).children("h3").stop(true,true);
				  $(this).children("span").stop(true,true);
				  $(this).children(".left_menu_sub_panel").animate({"width":"0"},100);
				  $(this).removeClass("active").animate({backgroundColor:"#fff",color:"#000",height:"25px"}, {duration:1000,complete:function(){withMouseEnter=""}});
				  $(this).children("h3").animate({paddingTop:0} , 1000);
				  $(this).children("span").fadeOut(1000);
				  //$(this).children(".left_menu_sub").fadeOut('fast');
					}
			  });
		});	
//rightmenu js		
		$("#rightmenu li").each(function(id) {
			$(this).hover(function(){
				$(this).siblings("li").stop(true,true);
				$(this).siblings("li").children(".number").stop(true,true);
				$(this).siblings("li").find(".main_title2").stop(true,true);
				$(this).siblings("li").find(".sub_title2").stop(true,true);
				$(this).siblings("li").children(".right_menu_links").stop(true,true);
				$(this).siblings("li").children(".right_menu_img").stop(true,true);
				$(this).siblings("li").children(".bground").stop(true,true);
				$(this).stop(true,true);
				$(this).children(".number").stop(true,true);
				$(this).find(".main_title").stop(true,true);
				$(this).find(".sub_title").stop(true,true);
				$(this).children(".right_menu_links").stop(true,true);
				$(this).children(".right_menu_img").stop(true,true);
				$(this).children(".bground").stop(true,true);
				$(this).siblings("li").removeClass("active");
				$(this).siblings("li").animate({height:"60px"},1500);
				$(this).siblings("li").children(".number").show().animate({width:"40px"}, 1500);
				$(this).siblings("li").find(".main_title2").switchClass( "main_title2", "main_title", 1500 );
				$(this).siblings("li").find(".sub_title2").switchClass( "sub_title2", "sub_title", 1500 );
				$(this).siblings("li").children(".right_menu_links").fadeOut("fast");
				$(this).siblings("li").children(".right_menu_img").animate({left:"242px"}, 1500);
				$(this).siblings("li").children(".bground").show().animate({opacity:1}, 1500);
				$(this).animate({height:"142px"},1500);
				$(this).addClass("active");
				$(this).children(".number").animate({width:"0px"}, 1500).hide();
				$(this).find(".main_title").switchClass( "main_title", "main_title2", 1500 );
				$(this).find(".sub_title").switchClass( "sub_title", "sub_title2", 1500 );
				$(this).children(".right_menu_links").fadeIn(1000);
				$(this).children(".right_menu_img").animate({left:"180px"}, 1500);
				$(this).children(".bground").animate({opacity:0}, {duration:1500,complete:function(){$(this).hide()}});
			});
		});	
		
		
		$('div.about_item').each(function(id){
			$(this).click(function(){
				$('.about_banner_img').fadeOut("slow");
				$('.page_content').hide();
				$('.left_menu_sub_nav a').removeClass('active');
				$(this).siblings(".about_item").animate({height:"62px",marginTop:"10px"}, 500);
				$(this).siblings(".about_item").children("a").css({color:"#fff"});	
				$(".about_item").removeClass('active');
				$('#about_banner_img'+id).fadeIn("slow");
				$('#page_content'+id).slideDown(500);
				$(this).animate({height:"72px",marginTop:"0px"}, 500);
				$(this).addClass('active');
				$('#left_about_item'+id).addClass('active');
				$(this).children("a").css({color:"#01a4e7"});				
			});
		});
		$('div.about_item').each(function(id){
			$(this).hover(function(){
				$(this).siblings(".about_item").stop(true, true);
				$(this).siblings(".about_item").animate({height:"62px",marginTop:"10px"}, 500);
				$(this).siblings(".about_item").children("a").css({color:"#fff"});	
				$(this).animate({height:"72px",marginTop:"0px"}, 500);
				$(this).children("a").css({color:"#01a4e7"});				
			},
				function() {
				$(this).siblings(".about_item").stop(true, true);
				$(this).not('.active').animate({height:"62px",marginTop:"10px"}, 500);
				$('.about_item.active').animate({'width':'161px'}, 200).animate({height:"72px",marginTop:"0"}, 500);
				$(this).not('.active').children("a").css({color:"#fff"});
				$('.active').children("a").css({color:"#01a4e7"});	
			});
		});
		
//		$('div.contact_logo img').each(function(id){
//			$(this).click(function(){
//				$('.contact_map').hide();				
//				$('#contact_map'+id).slideDown(500);		
//			});
//		});
//		
		
		$('#product_list_nav li').each(function(){
			$(this).hover(
			function(){
			var url = $(this).children("div.product_image").children("a").attr("href");
				$(this).children(".pmask").fadeIn(500);
				$(this).click(
				function(){
					window.location.href = url;
				});
			},
			function () {
				$(".pmask").fadeOut();
			});
		});
		
		
		/*
		$("#opener").click(function() {	
			$("#dialog-message").dialog({
				width:680,
				height:220,
				resizable: false,
				modal: true		
			});
		});
		*/
		
		
		var getbrandlist = '';
		var arrbrandlist = new Array();

		$("#cleckallimg a").each(function(index){
			$(this).click(function() {
				getbrandlist = $('#brandlist').val();
				if (getbrandlist)
				{
					arrbrandlist = getbrandlist.split(",");
				}
				if ($(this).hasClass("filter"))
				{					
					$('#check').attr('checked', false);
					//$('.ui-button').removeClass("ui-state-active");
					for (var i=0; i<arrbrandlist.length; i++)
					{
						if (parseInt($('#brand_value_'+index).text()) == arrbrandlist[i])
						{
							arrbrandlist.splice(i,1);
						}
					}
				}
				else
				{
					if ($("#cleckallimg li").find('a.filter').length == $("#cleckallimg a").length-1)
					{
						$('#check').attr('checked', true);
						$('#filter_checkbox > label.ui-button').addClass("ui-state-active");
					}
					arrbrandlist.push(parseInt($('#brand_value_'+index).text()));
				}

				getbrandlist = arrbrandlist.join();
				
				$('#brandlist').val(getbrandlist);
				$(this).toggleClass("filter");

				getProduct();
			});

		});

		//$('#keyword').keyup(function(){
			//getProduct();
		//});

		$('#resetbutton').click(function(){
			$('#cleckallimg a').removeClass('filter');
			$('#brandlist').val('');
			$(":checkbox").attr("checked", false);
			$('.filter_checkbox label').removeClass('ui-state-active');
			$('#search_keyword').val('');
			getProduct();
		});
		
		$("#partner_nav a").click(function() {
			$("#partner_nav a").removeClass("active");
			$(this).addClass("active");
			var partnerName = $(this).attr("title");
			var partnerUrl = $(this).attr("rel");
			var partnerUrlhtml = "<a href='http://"+partnerUrl+"'>"+partnerUrl+"</a>";
			$('#partner_name').html(partnerName);
			$('#partner_url').html(partnerUrlhtml);
		});	

		$('#partner_nav img').hover(function() {
			grayscale.reset( $(this) );
		}, function() {
			grayscale( $(this) );
		});

		$(".index_service_nav li").click(function() {
			$(this).siblings("li").removeClass("service_active");
			$(this).siblings("li").find(".index_service_info").css({"width":"270px","height":"42px"})
			$(this).siblings("li").find(".valign_panel").addClass("valign_line").css({"width":""});
			$(this).siblings("li").find("p.service_title").css({"width":""});
			$(this).siblings("li").find("img.service_img").hide();
			$(this).siblings("li").find("p.service_content").hide();
			$(this).addClass("service_active");
			$(this).find(".index_service_info").css({"width":"180px","height":"80px"})
			$(this).find(".valign_panel").removeClass("valign_line").css({"width":"180px"});
			$(this).find("p.service_title").css({"width":"180px"});
			$(this).find("img.service_img").show();
			$(this).find("p.service_content").show();
		});		


		$("#search_keyword").autocomplete(
			"getresult.php",
			{
				delay:10,
				minChars:1,
				matchSubset:1,
				matchContains:1,  
				cacheLength:10,
				onItemSelect:selectItem,
				onFindValue:findValue,
				formatItem:formatItem,
				autoFill:false 
  
			}
		);
});

function findValue(li) {
	if( li == null ) return alert("No match!");
	if( !!li.extra ) var sValue = li.extra[0];
	else var sValue = li.selectValue;
}
function selectItem(li) { 
	findValue(li);
}
function formatItem(row) { 
	return row[0];
}

checkAllPrettyCheckboxes = function(caller, container){
	if($(caller).is(':checked')){
		// Find the label corresponding to each checkbox and click it
		$('label.label_style').addClass('ui-state-active');
		$(container).find('input[type=checkbox]:not(:checked)').each(function(){
			//$('label[for="'+$(this).attr('id')+'"]').addClass('ui-state-active');
			//if($.browser.msie){
				$(this).attr('checked',true);
			//}else{
				//$(this).trigger('click');
			//};
		});
	}else{
		$('label.label_style').removeClass('ui-state-active');
		$(container).find('input[type=checkbox]:checked').each(function(){
			//$('label[for="'+$(this).attr('id')+'"]').removeClass('ui-state-active');
			//if($.browser.msie){
				$(this).attr('checked',false);
			//}else{
				//$(this).trigger('click');
			//};
		});
	};
	getProduct();
};

function getProductBySolutions()
{
	var alllength = $(":checkbox[name='solutions[]']").length;
	var checklength = $(":checkbox[name='solutions[]']:checked").length;
	if (checklength < alllength)
	{
		$('#check1').attr('checked', false);
		$('#filter_checkbox2 > label.ui-button').removeClass("ui-state-active");
	}
	else
	{
		$('#check1').attr('checked', true);
		$('#filter_checkbox2 > label.ui-button').addClass("ui-state-active");
	}
	getProduct();
}

checkAllPrettyCheckboxes2 = function(caller, container){
	var brandlist = '';
	if($(caller).is(':checked')){
		// Find the label corresponding to each checkbox and click it
		$(container).find('a').each(function(index){
			//$('label[for="'+$(this).attr('id')+'"]').trigger('click');
				$(this).addClass('filter');
				if (brandlist)
				{
					brandlist += ',';
				}
				brandlist += $('#brand_value_'+index).text();

		});
		$('#brandlist').val(brandlist);//set  brandlist value
	}else{
		$(container).find('a').each(function(){
			//$('label[for="'+$(this).attr('id')+'"]').trigger('click');
				$(this).removeClass('filter');
		});
		$('#brandlist').val('');//remove brandlist value
	};
	getProduct();
};

// goUrl add by lucky @2011-11-14
function goUrl(lang){
	var url = document.location.href;
	var query = window.location.search.substring(1);
	var urls2 = url.split("#");
	var urls = urls2[0].split("?");
	var vars = query.split("&");
	var query = "";
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] != "lang" && pair[0] != "") {
			query = query + pair[0] + "=" + pair[1] + "&";
		}
	}
	query = query + "lang=" + lang;
	location.href = urls[0]+"?"+query + (urls2[1] ? "#"+urls2[1] : "");
}

function getProduct()
{
	$('.product_info').ajaxStart(
		function(){
			$(this).html('loading...');
		}
	);
	$.ajax({
		type:"post",
		url:"products.php",
		data:$('#searchproduct').serialize(),
		success:function(data){
			$('.product_info').html(data);
			$('#product_list_nav li').each(function(){
				$(this).hover(
				function(){
				var url = $(this).children("div.product_image").children("a").attr("href");
					$(this).children(".pmask").fadeIn(500);
					$(this).click(
					function(){
						window.location.href = url;
					});
				},
				function () {
					$(".pmask").fadeOut();
				});
			});	
		}
	});
}


function changeContact(id, itude, geozoom)
{
	$('.contact_map').hide();				
	$('#contact_map'+id).slideDown(500);	
	$('#contactid').val(id);
	$('#contact_list').load('contact_us.php', {action:'loadcontent', id:id}, function(data)
	{
		var map;
		var itudeval = itude.split(",");
		var myLatlng = new google.maps.LatLng(itudeval[0], itudeval[1]);
		var myOptions = {
		  zoom: geozoom,
		  center: myLatlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
//		alert(document.getElementById("google_map"));
		map = new google.maps.Map(document.getElementById("google_map"), myOptions);
	 
		
		var marker = new google.maps.Marker({
			position: myLatlng, 
			map: map
		});

    });
			   
}
