jQuery(function($){
    $(window).bind("scroll", backToTopFun);
    backToTopFun();
    $(".yest_index_top_input").focus(function(){
        if($.trim(this.value) == this.getAttribute("empty"))
            this.value = "";
    }).blur(function(){
        if($.trim(this.value) == "" || $.trim(this.value) == this.getAttribute("empty")){
            this.value = this.getAttribute("empty");
        }
    });
    $(".site-cates li.i").click(function(){
        $(".site-cates li").removeClass("current");
        $(this).addClass("current");
        if(this.getAttribute("rel") != "")
        {
            $("#site-list .item").hide();
            $("#site-list .item[rel='"+this.getAttribute("rel")+"']").show();
        }
    });
	
    $("#links .close").click(function(){
        $("#links").hide();
    });
	
    $("#city-change-div").click(function(event){
        if($("#city-list").css("display") == "none"){
            $("#city-list").show();
            $("#city-change-div span").attr('class','uptip');
            $(document).one("click", function(event){
                $("#city-list").hide();
                $("#city-change-div span").attr('class','downtip');
            }); 
        }else{
            $("#city-list").hide();
            $("#city-change-div span").attr('class','downtip');
        }
        this.blur();
        return false;
    });
    $("#city-list .all_letter a").click(function(){
        $('#city-list .all_letter .current').removeClass('current');
        $(this).addClass('current');
        $('#city-list .all_city_con').hide();
        $('#city-list #city-con'+$(this).text()).show();
        return false;
    });   
	
    $(".e-item").each(function(i){
        $(this).hover(function(){
            $(this).addClass("cur");
        },function(){
            $(this).removeClass("cur");
        });
    });
	
    if($(".settime").length > 0)
        updateEndTime();
});
function backToTopFun() {
    var st = $(document).scrollTop(), winh = $(window).height();
    (st > 0)? $('#fudong').fadeIn(): $('#fudong').fadeOut();    
    //IE6下的定位
    if (!window.XMLHttpRequest) {
        $('#fudong').css("top", st + winh - 166);    
    }
}
function updateEndTime()
{
    var date = new Date();
    var time = date.getTime();
	
    $(".settime").each(function(i){
        var endDate =new Date(this.getAttribute("endTime"));
        var endTime = endDate.getTime();
        var lag = (endTime - time) / 1000;
        if(lag > 0)
        {
            var second = Math.floor(lag % 60);     
            var minite = Math.floor((lag / 60) % 60);
            var hour = Math.floor((lag / 3600) % 24);
            var day = Math.floor((lag / 3600) / 24);
            $(this).html('<span class="bg">'+day+"</span>天<span>"+hour+"</span>小时<span>"+minite+"</span>分<span>"+second+"</span>秒");
        }
        else
            $(this).html("团购已经结束啦！");
    });
	
    setTimeout("updateEndTime()",1000);
}

function clockTime()
{
    var date = new Date();
    var D="";
    switch(parseInt(date.getDay()))
    {
        case 0:
            D="天";
            break;
        case 1:
            D="一";
            break;
        case 2:
            D="二";
            break;
        case 3:
            D="三";
            break;
        case 4:
            D="四";
            break;
        case 5:
            D="五";
            break;
        case 6:
            D="六";
            break;
    }
	
    var year = date.getFullYear();
    var month = date.getMonth()+1;
    if(month < 10)
        month = "0"+ month;
		
    var date1 = date.getDate();
    if(date1 < 10)
        date1 = "0"+ date1;
		
    var hours = date.getHours();
    if(hours < 10)
        hours = "0"+ hours;
		
    var minutes = date.getMinutes();
    if(minutes < 10)
        minutes = "0"+ minutes;
		
    var seconds = date.getSeconds();
    if(seconds < 10)
        seconds = "0"+ seconds;
	
    var str=year+"年"+month+"月"+date1+"日 "+"星期"+D+" "+hours+":"+minutes+":"+seconds;
	
    $("#clock_box").html(str);
	
    setTimeout("clockTime()",1000);
}

