
(function($){
    $(document).ready(function(){
    $(".main-list-header .current").next().children('a').css("border","0px");
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

	$("#txtNavSearch").focus(function(){
		$(this).attr("value","");
	});
	
	$("#txtNavSearch").blur(function(){
	    if( $(this).val() == "" || $(this).val() == "关键词搜索" )
	    {
		$(this).attr("value","关键词搜索");
	    }
	});
	
	$("#full-search-form").find(".submit").click(function(){
	    if( $("#txtNavSearch").val() == "" || $("#txtNavSearch").val() == "关键词搜索" ) 
	    {
	    	alert("请输入关键词！");
		$("#txtNavSearch").focus();
		return false;
	    }
	    else
	    {
	    	$("#full-search-form").submit();
	    }
	});

  //设置首页
   $("#set-homepage").click(function(e){
   e.preventDefault();
   setHomepage("http://www.marieclairechina.com/");
   }); 
/*
	if( $("#home-mctv").length > 0 ) {
	    $("#home-mctv .b-images").jCarouselLite({
	          btnPrev: "#home-mctv .prev",
	          btnNext: "#home-mctv .next",
	          visible: 3
	    });
	    $("#home-mctv .bottom-i-c li").each(function(){
		  $(this).mouseover(function(){
			  //$(this).css("border","3px solid #bebebe");
        $("#home-mctv .bottom-i-c li").removeClass("current");
        $("#home-mctv .bottom-i-c li a span").removeClass("icon-hover");
        $("a.small-tv-mask","#home-mctv .bottom-i-c li").removeClass("mask-hover");
        var big_image=$("a.small-tv img",this).attr("src");
        $("#tv-big-image img").attr({ src: big_image , alt: "" });
        var big_link=$("a.small-tv",this).attr("href");
        $("a.larger-tv-mask").attr({ href: big_link , alt: "" });
			  $("span",this).addClass("icon-hover");
        $(this).addClass("current");
        $("a.small-tv-mask",this).addClass("mask-hover");
		  });
		  $(this).mouseout(function(){
		      if( !$(this).hasClass("current") ) {
			  //$(this).css("border","3px solid #707070");
			  $("p",this).css("background","#000");
			  $("span",this).removeClass("icon-hover");
        		  $("a.small-tv-mask",this).removeClass("mask-hover");
		      }
		  });
	    });
	}
*/

	if( $("#home-beauty-product").length > 0 ) {
	    
	    if( $("#home-beauty-product .top-content-3").length > 0)
	    {
                $("#home-beauty-product .top-content-3 .b-images").jCarouselLite({
	          	btnPrev: "#home-beauty-product .b-prev",
	          	btnNext: "#home-beauty-product .b-next",
	          	visible: 6
	        });
	    }

	    $(".whats-new-list").each(function(i){
		$(".comment-open",this).toggle(
		function(){
           $(this).parents('.l-r-c-1').children('.comment-text').hide();
           $(this).parents('.l-r-c-1').children('.comment-all').show();
		       $(this).html("折叠&gt;&gt;");
		},
		function(){
           $(this).parents('.l-r-c-1').children('.comment-all').hide();
           $(this).parents('.l-r-c-1').children('.comment-text').show();
		       $(this).html("展开&gt;&gt;");
		}	
		);
	    });

	    idTabsEffect("#home-beauty-product .category1");
	    idTabsEffect("#home-beauty-product .category2");

	    dlMouseover("#home-tryout-box");


/*
      $(".top-content-1 .right-i .col").each(function(i){
                      $(this).mouseover(function(){
                              if( !$(this).parent().hasClass("current"))
                              {
                              $(".top-content-1 .current div").hide();
                              $(".top-content-1 .current .arrowhead").hide();
                              $(".top-content-1 .right-i .current a.col").css("background","url(/design/mariecn_phase2/images/beauty_products/category-col1.png) no-repeat");
                              $(this).append("<span class=\"arrowhead\"></span>");
                              $(this).next().show();
                              }

                              });
                      $(this).mouseout(function(){
                        if( !$(this).parent().hasClass("current"))
                              {
                              $(this).html("");
                              $(this).next().hide();
                              $(".top-content-1 .right-i .current div").show();
                              $(".top-content-1 .right-i .current .arrowhead").show();
                              $(".top-content-1 .right-i .current a.col").css("background","url(/design/mariecn_phase2/images/beauty_products/category-col1-hover.png) no-repeat");
                              }
                              });
      });
      */

                   $('.top-content-1 .right-i .col').each(function(i){
                                  $(this).mouseover(function(){
                                         $('.top-content-1 .arrowhead').remove();
                                          $('.top-content-1 .current').removeClass("current");
                                  $(this).parent().addClass('current');
                                  $('.top-content-1 .col-content').hide().eq(i).show();
                                  $(this).append("<span class=\"arrowhead\"></span>");
                                          });
                                   
                                   });



                   $('.top-content-1 .right-i .col-content').each(function(i){
                                  $(this).mouseover(function(){
                                  $('.top-content-1 >right-i>div').removeClass('current');
                                  $(this).parent().addClass('current');
                                  $('.top-content-1 .right-i .col-content').hide().eq(i).show();
                                          }); 
                                   
                                   
                                   });













  }

	$("#contrast-clear-all").click(function(){
             for(j=0;j<4;j++)
             {
                  $("#contrast_hidden_"+(j+1)).attr("value",'');
                  $("#contrast-float .contrast_ul_list li").remove(".li_contrast"+j);
             }
             $("#contrast-float .contrast_number").html('0');
             $("#contrast-chk-box .v-align").each(function(i){
             	  $(this).removeAttr("checked");
             });
	});

        showPopupBeautyContrastBox($("#contrast-chk-box .v-align"));

	//add by start	
	$(".parent").click(function(){
		$(this).next("div").slideToggle("slow").siblings(".child-content:visible").slideUp("slow");
		$(this).toggleClass("expand-parent");
		$(this).siblings(".expand-parent").removeClass("expand-parent");

	});	

	if( $("#form-member").length > 0 ) {
	    $("#form-member .login-btn").click(function(){
		 $.ajax({
		         type: "POST",
			 url: "/action/login",
			 data: $("#form-member").serialize(),
			 success: function( ajax ){
			      memberLoginSuccess(ajax);
			 },
			 error: function(){
			      memberLoginError();
			 }
		 });
	    });

	    $("#form-member .mc-tv-password").keydown(function(e){
                 if (e.keyCode == "13") {
                        $("#form-member .login-btn").click();
                        return false;
                 }
            });
	}	

	if( $("#mc-tv-body").length > 0 ) {
	    var video_count = $("#video-count").html();
	    if( video_count > 3 )
	    {
	       $("#mc-tv-body .b-images").jCarouselLite({
	          	btnPrev: "#mc-tv-body .prev",
	          	btnNext: "#mc-tv-body .next",
	          	visible: 3
	    	});
	    }

	    $("#mc-tv-body .bottom-i-c li").each(function(){
		  $(this).mouseover(function(){
		      if( !$(this).hasClass("current") ) {
			  $(this).css("border","2px solid #b20000");
			  $("p",this).css("background","#b20000");
			  $("span",this).addClass("icon-hover");
		      }
		  });
		  $(this).mouseout(function(){
		      if( !$(this).hasClass("current") ) {
			  $(this).css("border","2px solid #727071");
			  $("p",this).css("background","#000");
			  $("span",this).removeClass("icon-hover");
		      }
		  });
	    });

	    $("#form-tv-comment").find(".submit").click(function(){
		var id = $("#form-tv-comment #tv_nodeID").val();
	        var commentid = $("#form-tv-comment #tv_commentID").val();

		if( $(".mc-tv-comment #ckbAnonymity").attr("checked") == true )
	  	{
	      	    var isanonymous = "checked";
	  	}	
		else 
		{
		    var isanonymous = "";
		}

		var comment_content = $.trim($("#form-tv-comment #tv_comment").val());
		var comment_content_length=getLength(comment_content);
	        if( comment_content == '' || comment_content == "请在此发表评论，限500字内。" )
		{
		       alert("抱歉!评论文字不能为空，感谢您的支持！");
		       $("#form-tv-comment #tv_comment").focus();
	        }
		else if(comment_content_length > 1000 )
		{
		       alert("字数过多，建议您分段发表。谢谢支持！");
			
		       $("#form-tv-comment #tv_comment").focus();
		}
		else
		{

			$.ajax({
			        type: "POST",
			        url: "/zbeautyguide/common_post",
				data: $("#form-tv-comment").serialize(),
			        success: function( responseText ){
			     	     $("#form-tv-comment #tv_comment").attr("value","");
				     var res = eval('('+responseText+')');
				     if(res.res)
				     {
                                          alert("感谢您的留言！留言需经过审核，请稍后查看。");
				          if( $("#form-tv-comment #tv_url_redirect").val() != "" )
				          {
				                location.href = $("#form-tv-comment #tv_url_redirect").val();
				          }
				          else
				          {
				                location.reload();
				          }
				      }else{
				          alert(res.conetnt);
				      }
				}
		       });

		       /*$.ajax({
			        type: "POST",
			        url: "/commanage/add_comment/" + id + "/" + commentid,
				data: "isanonymous=" + isanonymous + "&add=add&comment=" + encodeURIComponent($("#form-tv-comment #tv_comment").val()),
			        success: function( responseText ){
			             alert("感谢您的留言！留言需经过审核，请稍后查看。");
			     	     $("#form-tv-comment #tv_comment").attr("value","");
				     var res = eval('('+responseText+')');
				     if(res.res)
				     {
				          if( $("#form-tv-comment #tv_url_redirect").val() != "" )
				          {
				                location.href = $("#form-tv-comment #tv_url_redirect").val();
				          }
				          else
				          {
				                location.reload();
				          }
				      }
				}
		       });*/
		 }
	    });
	}

	function memberLoginSuccess(ajax) {
		var resObj=JSONstring.toObject(ajax);
		$("#form-member .loading").show();
		$("#form-member .login-btn").hide();
		if(resObj.res > 0){
		      if( $("#form-member .returnUrl").val() == '' )
			   window.location.reload();
		      else
		      	   window.location.href=$("#form-member .returnUrl").attr("value");
		}else{
		     $("#form-member .loading").hide();
		     $("#form-member .login-btn").show();
		     alert(user.messages.login.invalid);
		}
	}
	function getLength(value){
		var   len   =   0;
		for(i=0;i<value.length;i++){
			if(value.charCodeAt(i)>256){
				len += 2;
			}else{
				len++;
			}
		}
		return len;
	};

	
	function memberLoginError() {
	     alert(user.messages.login.invalid);
	}
	//add by end

	function idTabsEffect(parentObj) {
	    $.each($(parentObj + " li a"), function(i, n){
	        $(n).click(function(e){
		    if (e)
		       e.preventDefault();
		    else
		      window.event.returnValue = false;
	        });
	    });
	    try {
	        $(parentObj + " ul").idTabs("!mouseover");
	    }
	    catch (e) {
	    }
	}

	function dlMouseover(parentObj){
	    var dt=$(parentObj+" dt");
	    $(parentObj+" dd").hide();
	    $(parentObj+" dt:first").hide();
	    $(parentObj+" dd:first").show();
	    $.each(dt,function(i,n){
		$(n).mouseover(function(){
		    $(parentObj+" dt").show();
		    $(parentObj+" dd").hide();
		    $(this).next().show();
		    $(this).hide();
		});
	    });
	}

 $("#tryout_product_sortstyle").change(function(){
                  if($(this).val()!=""){
                  var url ='/beauty/product/(tryout_list)/beauty_tryout_product_list/' + '(sortstyle)/' + $(this).val();
                  window.location.href=url;
                  }
                  });

	function showPopupBeautyContrastBox(o)
        {
            o.click(function(){
                var flag=false;
                var val_array = new Array();
                var name_array = new Array();
                var num = 0;
                $("#contrast-chk-box :checkbox").each(function(i){
                      if($(this).attr("checked")==true){
                           flag=true;
                           val_array[i] = $(this).val();
                           name_array[i] = $("#contrast_"+(i+1)).val();
                           num ++;
                      }
                      else
                      {
                           val_array[i] = '';
                           name_array[i] = '';
                      }
                });

             	$("#contrast-float .contrast_number").html(num);
             	for(j=0;j<val_array.length;j++)
             	{
                     $("#contrast_hidden_"+(j+1)).attr("value",val_array[j]);
                     $("#contrast-float .contrast_ul_list li").remove(".li_contrast"+j);
                     if(val_array[j] != '')
                     {
                           $("#contrast-float .contrast_ul_list").append("<li class='li_contrast"+j+"'><div class='float-list-line'><div class='product-name'>"+name_array[j]+"</div><div class='del'><a href='javascript:void(0)'>删除</a></div></div></li>");
                           removeContrastCurrent($("#contrast-float .del"),(j+1),val_array[j]);
                     }
              	}

              	if(flag){
                     $("#contrast-float").css("display","block");
	        } 
                else{
                     $("#contrast-float").css("display","none");
                }
            });

            $("#contrast-float .div-close a").click(function(){
                  $("#contrast-float").css("display","none");
            });
          }
	 
	function ContrastBeautyButtonBox(o)
	 {
              o.click(function(){
                 var val_array = new Array();
		 var num=0;
		 for(i=1; i<5; i++)
		 {
                     if($("#contrast_hidden_"+i).val() != '')
		     {
		         
		         num++;
			 val_array[i]=$("#contrast_hidden_"+i).val();
		     }
		 }
		 if(num > 3)
		 {
                     $(this).attr("href","javascript:void(0)");
		     alert("最多只能同时选择三个产品进行对比！");
		     return false;

		 }
		 else
		 {
		     var report_url = '/beauty/product/product_contrast_report/(product)/'+$("#contrast_hidden_current").val();
		     var temp_num = 0;
		     for(k=0; k<val_array.length; k++)
		     {
		         if(val_array[k] != undefined)
			 {
                            if(temp_num == 0)
                                report_url += '/(pli)/'+val_array[k]; 
                            if(temp_num == 1)
                                report_url += '/(plii)/'+val_array[k]; 
			    if(temp_num == 2)
                                report_url += '/(pliii)/'+val_array[k]; 
			    temp_num ++;
			 }
		     }
		     window.open(report_url);
		 }
             });
	 }


	  function removeContrastCurrent(o,num,value)
	  {
	         o.click(function(){
	              var count=$("#contrast-float .contrast_number").html()-1;
	              $(this).parent().parent().remove();
	              $("#contrast_hidden_"+num).attr("value",'');
	              $("#contrast-chk-box #contrast_"+value).next().removeAttr("checked");
	              $("#contrast-float .contrast_number").html(''+count);
	         });
	  }
	ContrastBeautyButtonBox($("#contrast-floatConBut-begin"));

//tv-kv star
if($('#tv-big-image').length){
           var spacing=175;
           var now=false;
           var auto=false;
           var link=$('#tv-big-image').next();
           $('#tv-home-tvnav li').each(function(i){
                           $(this).css({"position":"absolute","left":i*spacing});
                           $(this).mouseover(function(){
                                   clearInterval(auto);
                                   auto=false;
                                   $(this).parent().children('li').removeClass('current');
                                   $(this).addClass('current');
                                   var src=$(this).children('a').children('img').attr("src");
                                   var href=$(this).children('a').eq(0).attr("href");
                                   $('#tv-big-image img').attr("src",src);
                                   link.attr("href",href)
                                   }).mouseout(function(){setTimeout(play,300)});
                           });      

           function right(){
               arguments.length==2?spd=0:spd=1000;
               if(!now){
               now=true;
               var big=$('#tv-big-image');
               var node=$('#tv-home-tvnav li');
                   node.eq(0).animate({"left":-spacing},"slow",function(){$(this).appendTo($(this).parent())})
                   node.eq(1).animate({"left":0},"slow",function(){
                                  node.removeClass("current");  
                                  $(this).addClass("current");  
                                  link.attr("href",$(this).children('a').eq(0).attr("href"))
                                  var src=$(this).children('a').children('img').attr("src");
                                  big.css({"background-image":"url("+src+")"});
                                  big.children('img').fadeTo(spd,0,function(){$(this).attr("src",src).fadeTo(0,1);now=false;});
                                   });
                   node.eq(2).animate({"left":spacing},"slow");
                   node.eq(3).css("left",spacing*3).animate({"left":2*spacing},"slow");
               }
           }

          function left(){
               if(!now){
               now=true;
               var big=$('#tv-big-image');
               var node=$('#tv-home-tvnav li');
                   node.eq(0).animate({"left":spacing},"slow");
                   node.eq(1).animate({"left":2*spacing},"slow",function(){
                                  node.removeClass("current");  
                                  $(this).addClass("current");  
                                  link.attr("href",$(this).children('a').eq(0).attr("href"))
                                  var src=$(this).children('a').children('img').attr("src");
                                  big.css({"background-image":"url("+src+")"});
                                  big.children('img').fadeTo(0,0,function(){$(this).attr("src",src).fadeTo(0,1);now=false;});
                                   });
                   node.eq(2).animate({"left":3*spacing},"slow");
                   node.eq(node.length-1).css("left",-spacing).animate({"left":0},"slow",function(){now=false; $(this).prependTo($(this).parent())});
               }
           }
      $('#tv-home-tvnav .next').click(function(){
                   right(1,2);               
                   return false;
                   clearInterval(auto);
                   auto=false;
                   setTimeout(play,300);
                    });
      $('#tv-home-tvnav .prev').click(function(){
                   left();               
                   clearInterval(auto);
                   auto=false;
                   setTimeout(play,300);
                   return false;
                    });
    function play(){
         if(!auto){
       auto=setInterval(right,2000);
         }
    }
    lastimg=$('#tv-home-tvnav li img').eq($(this).length-1);
    if(lastimg[0].complete){play()
    }else{lastimg.bind('load',play())
    }
    }
    });
})(jQuery);
