﻿// JavaScript Document
$(function() {

	$("select#catIds").niceSelect({
		virtualSelectClass:"stateDown",
		virtualInputClass: "stateDownInput",
		selectCallback: callbackFunction
	});	


	if(document.getElementById("tabs") != null){
		$('#tabs').tabs();
	}
	/*$(".content .first").click(function(){
		window.open("http://www.vichy.com.cn/biwhite2010/index.aspx");		
	})
	$(".content .second").click(function(){
		window.open("http://www.vichy.com.cn/aqualia2010/index.aspx");						   
	})
	$(".content .third").click(function(){
		window.open("http://www.vichy.com.cn/normaderm2010/index.aspx");						   
	})*/
	$(".navDetail").bgiframe();
	$('dd.fourth').cycle({ 
	    fx: 'fade',
		speed: 700,
		timeout: 5000,
	    delay: -700,
		autostop: 0,
		autostopCount: 0,
	    prev: '.contentSNav .pre',
		next: '.contentSNav .next',
		after:test1
	});		
	$('.content').cycle({ 
	    fx: 'fade',
		speed: 700,
		timeout: 5000,
	    delay: -700,
		autostop: 0,
		autostopCount: 0,
	    prev: '.contentNav .pre',
		next: '.contentNav .next',
		after:test
	});	
	$('.doctor').cycle({ 
	    fx: 'fade',
		speed: 700,
		timeout: 5000,
	    delay: -700,
		autostop: 0,
		autostopCount: 0,
	    prev: '.conSNav a.pre',
		next: '.conSNav a.next',
		pager: ".dorctrl",
		after:test2,
		pagerAnchorBuilder: function(idx, slide) { 
        return '<span style="display:block;width:202px;height:88px;z-index:100;float:left;margin-left:30px;cursor:pointer;"><img src="/Portals/0/images/blank.gif" width="202" height="88"/></span>'; 
		} 
	});

	//search auto complete
	var later ;


	$(".search_complete").positionBy({
		target: $(".searchText"),
		targetPos: 3,
		elementPos:0
	}).hide(); 
	$(".searchText").bind("keyup", function(){
		if(later!=null) clearTimeout(later);
		later = setTimeout(function(){
			var keyword = $(".searchText").val();
			if(keyword!=""){
				$.get("/skin.aspx", {keywords: keyword}, function(data){
					var resHtml = "";
					if($(data).find("keyword").length > 0){
						$(data).find("keyword").each(function(index){
							resHtml += "<li onmouseover=\"rs_event.hover()\" onmouseout=\"\" onclick=\"rs_event.click('"+$(this).find("name").text()+"')\">"+$(this).find("name").text()+"</li>\n";	
						});
						$(".search_complete").html("").append(resHtml).show();
						if($(data).find("keyword").length>20){
							$(".search_complete").css({height:'400px', overflowY:'auto'});
						}else{
							$(".search_complete").css({height:'auto'});
						}
					}else{
						$(".search_complete").hide();
					}
				});
			}else{
				$(".search_complete").hide();

			}
		}, 800) ;
		
	});
	$(document).bind("click", function(){
		$(".search_complete").hide();
	});

	function test(){
		$('.content > div').each(function (i, n){
			if($(n).css("display")=="block"){
				$('.contentNav span.next').html("0"+(i+1));
			}
		});
	}
	function test1(){
		$('dd.fourth > div').each(function (i, n){
			if($(n).css("display")=="block"){
				$('.contentSNav span.next').html("0"+(i+1));
			}
		});
	}
	function test2(){
		$('div.doctor > div').each(function (i, n){
			if($(n).css("display")=="block"){
				$('.conSNav span.next').html("0"+(i+1));
			}
		});
	}
	var tmp = "";
	var tmp1 = "";

	$('.nav a').hover(
		function(){
			var i = 0;
			var s = '-'+($(this).width()+7)+'px';
			var ie = false;
			if(jQuery.browser.msie && $.browser.version != "8.0") {
				ie = true;
			}
			if($(this).attr("class") == "fifth"){
				i = 1;
				s = '7px';
				$('.navDetail .fifth').css("display","block");
				tmp = '.navDetail .fifth';
				$(".stateDown").css("visibility", "hidden");
			}
			if($(this).attr("class") == "fourth"){
				/* $('.navDetail .fourth').css("display","block");
				tmp = '.navDetail .fourth';
				$(".stateDown").css("visibility", "hidden"); */
			}
			if($(this).attr("class") == "third"){
				$('.navDetail .third').css("display","block");
				tmp = '.navDetail .third';
				$(".stateDown").css("visibility", "hidden");
			}
			if($(this).attr("class") == "second"){
				$('.navDetail .second').css("display","block");
				tmp = '.navDetail .second';
				$(".stateDown").css("visibility", "hidden");
			}
			if($(this).attr("class") == "first"){
				$('.navDetail .first').css("display","block");
				tmp = '.navDetail .first';
				$(".stateDown").css("visibility", "visible");
			}
			$('.navDetail .bottom').css("display","block");
			$('.navDetail').css({'display': 'block', 'margin-top': '9px'}).positionBy({
				target: $(this),
				targetPos:1,
				elementPos:i
			});
			$('.navDetail').css('margin-left', s);
			if(ie){
				$('.navDetail').css('margin-top', '52px');
			}
			if($.browser.version == "8.0"){
				$('.navDetail').css('margin-top', '-5px');	
			}
			tmp1 = $(this).children();
			mouseover(tmp1);			
		},
		function(){
			$('.navDetail').css("display","none");
			$('.navDetail div').css("display","none");
			$('.navDetail div div').css("display","block");
			mouseout($(this).children());
		}
	);
	function mouseover(obj){
		var temp = obj.attr('src');
		if(temp.indexOf(".jpg")!=-1){
			var url = temp.substring(0, temp.indexOf(".jpg"))+"-on.jpg";
			obj.attr('src',url);
			$("input").blur();
		}
	}
	function mouseout(obj){
		var temp = obj.attr('src');
		if(temp.indexOf("-on.jpg")!=-1){
			var url = temp.substring(0, temp.indexOf("-on.jpg"))+".jpg";
			obj.attr('src',url);
		}
	}
	$('.navDetail').hover(
		function(){
			mouseover(tmp1);
			$(this).css("display","block");
			$(tmp).css("display","block");
			$('.navDetail .bottom').css("display","block");
		},
		function(){
			$(this).css("display","none");
			$('.navDetail div').css("display","none");
			$('.navDetail div div').css("display","block");
			mouseout(tmp1);
		}
	);
	$(".searchText").click(function(){
		$(this).val("");								
	})
	$(".mainInfo .search").click(function(){
		if($.trim($(this).prev().val())=="请输入关键字"){
			return false;
		}
		if($.trim($(this).prev().val())==""){
			$(this).prev().val("请输入关键字");
			return false;
		}
	})
	$(".productSearch").click(function(){
		$(this).val("");								
	})
	$(".last .search").click(function(){
		if($.trim($(".productSearch").val())=="请输入关键字"){
			return false;
		}
		if($.trim($(".productSearch").val())==""){
			$(this).prev().val("请输入关键字");
			return false;
		}
	})
});

function callbackFunction(){
}
//search complet choose event
var rs_event = {
	click: function(val){
		$(".searchText").val(val);
		$(".search_complete").hide();
	},
	hover: function(e){
		 var evt=getEvent();
		 var element=evt.srcElement || evt.target;
		$(element).parent().find("li").removeClass("hover");
		$(element).addClass("hover");
	}
};



function getEvent()
{
if(document.all)    return window.event;//如果是ie
func=getEvent.caller;
        while(func!=null){
            var arg0=func.arguments[0];
            if(arg0){if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){return arg0;}}
            func=func.caller;
        }
       return null;
}
