﻿jQuery(function($) {
    if (window.XMLHttpRequest) {
        $("#slbk").css({ "background-image": "url(../Img/slider-trans.png)" });
    }
    $(".sdbbox").bind("mouseover", movesdb2);
    hoverImg_home();

    $(".inputw339 textarea").bind("click", service_input);
    $("#sv_drop").bind("mouseup", service_unput);

    $("#phonepad").bind("click", function() {
        window.open("Line_123.html");
    $("#sh_bt").bind("click", reSearch);
      
    $(".inputtip").bind("click", from_tip_focus);
//    $(".new_year").bind("click", harf01s);
    });

    setTimeout(fl_timer, 1000);
    setTimeout(fs_timer, 2000);
    setTimeout(fo_timer, 3000);
    setTimeout(ff_timer, 4000);

    $("#slider").bind("click", harf01);
    setInterval(sdbbox1, 20000);
    setTimeout(initsdbbox2, 5000);
    setTimeout(initsdbbox3, 10000);
    setTimeout(initsdbbox4, 15000);
});

 var reSearch = function()
        {
            var st_id = $("#Dp_StartId").get(0).selectedIndex+1;
            var query = $("#ads_search").val();
            location.href = "/SearchList.aspx?query="+query+"&sdd="+st_id;
        }
        var from_tip_focus = function() 
        {
            $(this).hide();
            $(this).prev(".form_text").addClass("form_text_focus").focus();
        }
        
        var harf01s = function() {
            window.open('NewYear/NewYear.aspx');
        }

var initsdbbox2 = function() {
    $(".sdbbox:eq(1)").mouseover();
    $("#slider").unbind().bind("click", harf02);
    setInterval(sdbbox2, 20000);
}
var initsdbbox3 = function() {
    $(".sdbbox:eq(2)").mouseover();
    $("#slider").unbind().bind("click", harf03);
    setInterval(sdbbox3, 20000);
}
var initsdbbox4 = function() {
    $(".sdbbox:eq(3)").mouseover();
    $("#slider").unbind().bind("click", harf04);
    setInterval(sdbbox4, 20000);
}
var sdbbox1 = function() {
    $(".sdbbox:eq(0)").mouseover();
    $("#slider").unbind().bind("click", harf01);
}
var sdbbox2 = function() {
    $(".sdbbox:eq(1)").mouseover();
    $("#slider").unbind().bind("click", harf02);
}
var sdbbox3 = function() {
    $(".sdbbox:eq(2)").mouseover();
    $("#slider").unbind().bind("click", harf03);
}
var sdbbox4 = function() {
    $(".sdbbox:eq(3)").mouseover();
    $("#slider").unbind().bind("click", harf04);
}
var harf01 = function() {
//window.open('line_12150.html');
}
var harf02 = function() {
//window.open('line_12155.html');
}
var harf03 = function() {
//window.open('line_12202.html');
}
var harf04 = function() {
//window.open('line_12175.html');
}
var currenm = 0;
var movesdb2 = function () {
    var num = $(".sdbbox").index($(this)[0]);
    if (currenm != num) {
        $(".sdbbox:eq(" + currenm + ") img").animate({ bottom: "0px" }, 500);
        $(".sdbbox:eq(" + num + ") img").animate({ bottom: "20px" }, 500);
        $(".sdmag:eq(" + currenm + ")").fadeOut("slow");
        $(".sdmag:eq(" + num + ")").fadeIn("slow");
        switch (num) {
            case 0:
                $("#slider").unbind().bind("click", harf01);
                break;
            case 1:
                $("#slider").unbind().bind("click", harf02);
                break;
            case 2:
                $("#slider").unbind().bind("click", harf03);
                break;
            case 3:
                $("#slider").unbind().bind("click", harf04);
                break;
        }
        currenm = num;
    }
}
var fl_timer = function(){
    longtravel = new LineAJAX($("#first_longtravel .first_box"));
    //longtravel.FirstRun();
}
var fs_timer = function(){
    shorttravel = new LineAJAX($("#first_shorttravel .first_box"));
    //shorttravel.FirstRun();
}
var fo_timer = function(){
    OutTravel = new LineAJAX($("#first_OutTravel .first_box"));
    //OutTravel.FirstRun();
}
var ff_timer = function(){
    freetravel = new LineAJAX($("#first_freetravel .first_box"));
    //freetravel.FirstRun();
}
var LineAJAX = function (boxer) {
    this.boxer = boxer;
    $(boxer).children(".first_itme").bind("click",this.OpAjax);
}
LineAJAX.prototype.OpAjax = function(){
    var id = $(this).children(".none").text();
    var pucker = $(this).next(".first_ajax");
    if(pucker.css("height") == "0px"){
        if($(pucker).find(".f_num").text() == "编号："){
            $.ajax({
                url: "Home.aspx/GetLineByID",
                data: "{'id':'" + id + "'}",
                success: function(msg) {
                    var val = ConvertJson(msg);
                    $(pucker).children(".f_img").attr("src", "store/100/"+val.ImageUrl);
                    $(pucker).find(".f_num").append(val.Id);
                    $(pucker).find(".f_price").append(val.Price);
                    $(pucker).find(".f_sads").append(val.StartAddress);
                    $(pucker).find(".f_long").append(val.TimeLong);
                    $(pucker).find(".f_trade").append(val.Trader);
                    $(pucker).find(".f_type").append(val.Type);
                    $(pucker).children(".f_dis").append(val.Directions);
                }
            });
        }
        $(pucker).animate({
            height: "162px"
        }, 1000);
        $(this).css("background-image", "url(../Img/cheapico.png)");
    } else {
        $(pucker).animate({
            height: "0px"
        }, 1000, function() {
            $(this).css("display", "none");
        });
      //  $(this).css("background-image", "url(../Img/addico.png)"); 显示背景图片
    }
}
LineAJAX.prototype.FirstRun = function(){
    $(this.boxer).children(".first_itme").eq(0).click();
}

var hoverImg_home = function() {
    $(".first_itme").bind("mouseover", function() { $(this).addClass("first_itme_hover"); });
    $(".first_itme").bind("mouseout", function() { $(this).removeClass("first_itme_hover"); });
    $("#tool_c span").bind("mouseover", function() { $(this).addClass("sphover"); });
    $("#tool_c span").bind("mouseout", function() { $(this).removeClass("sphover"); });
    $("#phonepad,#phonetext").bind("mouseover", function() { $("#phonepad").addClass("phonepad_hover"); });
    $("#phonepad,#phonetext").bind("mouseout", function() { $("#phonepad").removeClass("phonepad_hover"); });
}
var service_input = function() {
    $("#service_hide").hide();
    $(".service_box").show();
}
var service_unput = function() {
    $("#service_hide").show(); 
    $(".service_box").hide();
}
