﻿/// <reference path="jquery-1.3.2.js" />
/// <reference path="jquery.jmsajax.js" />

function GetProducts(id, categoryNo, typeIdNo, countNo, idData, idLoading) {
    $("#" + id).click(function() {
        ShowClickImg(id);
        var img = $('<img src="Images/loading.gif" alt="加载中" id="' + id + 'Loading" class="loading" />');
        var dvData = $("#" + idData);
        $.jmsajax({
            url: "Service/Mall.asmx",
            method: "GetProducts",
            data: { categoryId: categoryNo, typeId: typeIdNo, count: countNo },
            success: function(data) {
                if (data[0] == 0) { dvData.html(data[1]); }
                else alert(id + "error");
            },
            error: function(data) { alert('(' + data.status + ')' + data.statusText); },
            beforeSend: function() { dvData.html("").append(img); },
            complete: function() { $("#" + idLoading).hide(); }
        });
    });
}

$().ready(function() {
    DealProShow();
    AjustLeft();
});

$(window).resize(function() {
    AjustLeft();
});

function DealProShow() {
    var ids = ['Digital', 'Computer', 'Phone', 'Housedigital', 'Jewlery', 'House', 'Cosmetic'];
    var suffix = ['New', 'Hot', 'Special'];
    for (var i = 0; i < ids.length; i++) {
        for (var j = 0; j < suffix.length; j++) {
            GetProducts(ids[i] + suffix[j], $("#hd" + ids[i] + "Id").val(), $("#hd" + suffix[j] + "Id").val(), 3, ids[i] + "Data", ids[i] + "Loading");
        }
        $("#" + ids[i] + suffix[0]).trigger("click");
    }
}

function ShowClickImg(imgId) {
    var $parent = $("#" + imgId).parent().parent();
    $parent.find("a:eq(0)").css("background-position", "0 -510px");
    $parent.find("a:eq(1)").css("background-position", "0 0");
    $parent.find("a:eq(2)").css("background-position", "0 -240px");
    switch (imgId) {
        case "DigitalNew": $("#" + imgId).css("background-position", "0 -540px");
            break;
        case "DigitalHot": $("#" + imgId).css("background-position", "0 -60px");
            break;
        case "DigitalSpecial": $("#" + imgId).css("background-position", "0 -300px");
            break;
        case "ComputerNew": $("#" + imgId).css("background-position", "0 -600px");
            break;
        case "ComputerHot": $("#" + imgId).css("background-position", "0 -120px");
            break;
        case "ComputerSpecial": $("#" + imgId).css("background-position", "0 -360px");
            break;
        case "PhoneNew": $("#" + imgId).css("background-position", "0 -690px");
            break;
        case "PhoneHot": $("#" + imgId).css("background-position", "0 -210px");
            break;
        case "PhoneSpecial": $("#" + imgId).css("background-position", "0 -450px");
            break;
        case "HousedigitalNew": $("#" + imgId).css("background-position", "0 -660px");
            break;
        case "HousedigitalHot": $("#" + imgId).css("background-position", "0 -180px");
            break;
        case "HousedigitalSpecial": $("#" + imgId).css("background-position", "0 -420px");
            break;
        case "JewleryNew": $("#" + imgId).css("background-position", "0 -480px");
            break;
        case "JewleryHot": $("#" + imgId).css("background-position", "0 -30px");
            break;
        case "JewlerySpecial": $("#" + imgId).css("background-position", "0 -270px");
            break;
        case "HouseNew": $("#" + imgId).css("background-position", "0 -570px");
            break;
        case "HouseHot": $("#" + imgId).css("background-position", "0 -90px");
            break;
        case "HouseSpecial": $("#" + imgId).css("background-position", "0 -330px");
            break;
        case "CosmeticNew": $("#" + imgId).css("background-position", "0 -630px");
            break;
        case "CosmeticHot": $("#" + imgId).css("background-position", "0 -150px");
            break;
        case "CosmeticSpecial": $("#" + imgId).css("background-position", "0 -390px");
            break;
        default: break;
    }
}

function AjustLeft() {
    if (isIE6()) {
        $("#gotop").hide();
    }
    else {
        var $width;
        ScrollJust();
        Showhide();
        $(window).scroll(function() {
            ScrollJust();
            Showhide();
        });
        $("#gotop").click(function() {
            $(window).scrollTop(0);
        });
    }
}
function Showhide() {
    if (0 < $(window).scrollTop()) {
        $("#gotop").show();
    }
    else {
        $("#gotop").hide();
    }
}
function ScrollJust() {
    if ($(window).width() > 950) {
        $width = $(window).width() / 2 + 455;
    } else {
        $width = 930 - $(window).scrollLeft();
    }
    $("#gotop").css({ left: $width });
}
function isIE6() {  
    return navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie 6.0")=="-1"?false:true;  
}
