﻿//获取首页焦点图是第几侦
function Slideid() {
    var url = location.search;
    if (url.length > 1) {
        url = url.substring(1);
        var Url__ = url.split("&");
        var oid = "";
        for (var i = 0; i < Url__.length; i++) {
            var Url___ = Url__[i].split("=");
            if (Url___.length > 1) {
                if (Url___[0].toLowerCase() == "oid") {
                    oid = Url___[1] - 1;
                }
            }
        }
        if (oid < 0) {
            oid = -1;
            //alert("s1:"+oid);
        }
    } else {
        oid = -1;
        //alert("s3:"+oid);
    }
    return oid;
}

//新品上架
var cp = 1;
function ShowRNp() {

    $("#NP" + cp).hide();
    $("#Class" + cp).removeClass("on");
    cp = cp + 1;
    if (cp == 6) {
        cp = 1;
    }
    $("#Class" + cp).addClass("on");
    $("#NP" + cp).show();


}
function ShowLNp() {
    $("#NP" + cp).hide();
    $("#Class" + cp).removeClass("on");
    cp = cp - 1;
    if (cp == 0) {
        cp = 5;
    }
    $("#Class" + cp).addClass("on");
    $("#NP" + cp).show();
}
function Showclick(cpid) {

    $("#NP" + cp).hide();
    $("#Class" + cp).removeClass("on");
    $("#Class" + cpid).addClass("on");
    $("#NP" + cpid).show();
    cp = cpid;
}

//顶部10000个免费购物名额大幅广告
var time = time2 = 500;
var h = h2 = 0;
function addCount() {
    if (time > 0) {
        time--;
        h = h + 15;
    }
    else {
        return;
    }
    if (h > 551)  //高度
    {
        return;
    }
    document.getElementById("ads").style.display = "";
    document.getElementById("ads").style.height = h + "px";
    setTimeout("addCount()", 30);
}
function addCount2() {
    if (time2 > 0) {
        time2--;
        h2 = h2 + 10;
    }
    else {
        return;
    }
    if (h2 > 80)  //高度
    {
        return;
    }
    document.getElementById("ads2").style.display = "";
    document.getElementById("ads2").style.height = h2 + "px";
    setTimeout("addCount2()", 30);
}

function showAds() {
    //addCount("ads");
    setTimeout("noneAds()", 3000); //停留时间自己适当调整
}

var T = 551;
var N = 551; //高度
function noneAds() {
    if (T > 0) {
        T--;
        N = N - 35;
    }
    else {
        return;
    }
    if (N < 0) {
        document.getElementById("ads").style.display = "none";
        addCount2();
        return;
    }

    document.getElementById("ads").style.height = N + "px";
    setTimeout("noneAds()", 30);
}

//小焦点图轮换
function moveElement(elementID, final_x, final_y, interval) {
    if (!document.getElementById) return false;
    if (!document.getElementById(elementID)) return false;
    var elem = document.getElementById(elementID);
    if (elem.movement) {
        clearTimeout(elem.movement);
    }
    if (!elem.style.left) {
        elem.style.left = "0px";
    }
    if (!elem.style.top) {
        elem.style.top = "0px";
    }
    var xpos = parseInt(elem.style.left);
    var ypos = parseInt(elem.style.top);
    if (xpos == final_x && ypos == final_y) {
        return true;
    }
    if (xpos < final_x) {
        var dist = Math.ceil((final_x - xpos) / 10);
        xpos = xpos + dist;
    }
    if (xpos > final_x) {
        var dist = Math.ceil((xpos - final_x) / 10);
        xpos = xpos - dist;
    }
    if (ypos < final_y) {
        var dist = Math.ceil((final_y - ypos) / 10);
        ypos = ypos + dist;
    }
    if (ypos > final_y) {
        var dist = Math.ceil((ypos - final_y) / 10);
        ypos = ypos - dist;
    }
    elem.style.left = xpos + "px";
    elem.style.top = ypos + "px";
    var repeat = "moveElement('" + elementID + "'," + final_x + "," + final_y + "," + interval + ")";
    elem.movement = setTimeout(repeat, interval);
}

function classNormal(iFocusBtnID, iFocusTxID) {
    var iFocusBtns = document.getElementById(iFocusBtnID).getElementsByTagName('li');
    //var iFocusTxs = $(iFocusTxID).getElementsByTagName('li');
    for (var i = 0; i < iFocusBtns.length; i++) {
        iFocusBtns[i].className = 'normal';
        //iFocusTxs[i].className='normal';
    }
}

function classCurrent(iFocusBtnID, iFocusTxID, n) {
    var iFocusBtns = document.getElementById(iFocusBtnID).getElementsByTagName('li');
    //var iFocusTxs = $(iFocusTxID).getElementsByTagName('li');
    iFocusBtns[n].className = 'current';
    //iFocusTxs[n].className='current';
}

function iFocusChange() {
    if (!document.getElementById('ifocus')) return false;
    document.getElementById('ifocus').onmouseover = function () { atuokey = true };
    document.getElementById('ifocus').onmouseout = function () { atuokey = false };
    var iFocusBtns = document.getElementById('ifocus_btn').getElementsByTagName('li');
    var listLength = iFocusBtns.length;
    iFocusBtns[0].onmouseover = function () {
        moveElement('ifocus_piclist', 0, 0, 5);
        classNormal('ifocus_btn', 'ifocus_tx');
        classCurrent('ifocus_btn', 'ifocus_tx', 0);
    }
    if (listLength >= 2) {
        iFocusBtns[1].onmouseover = function () {
            moveElement('ifocus_piclist', 0, -175, 5);
            classNormal('ifocus_btn', 'ifocus_tx');
            classCurrent('ifocus_btn', 'ifocus_tx', 1);
        }
    }
    if (listLength >= 3) {
        iFocusBtns[2].onmouseover = function () {
            moveElement('ifocus_piclist', 0, -350, 5);
            classNormal('ifocus_btn', 'ifocus_tx');
            classCurrent('ifocus_btn', 'ifocus_tx', 2);
        }
    }
    /*	if (listLength>=4) {
    iFocusBtns[3].onmouseover = function() {
    moveElement('ifocus_piclist',0,-603,5);
    classNormal('ifocus_btn','ifocus_tx');
    classCurrent('ifocus_btn','ifocus_tx',3);
    }
    }*/
}

setInterval('autoiFocus()', 5000);
var atuokey = false;
function autoiFocus() {
    if (!document.getElementById('ifocus')) return false;
    if (atuokey) return false;
    var focusBtnList = document.getElementById('ifocus_btn').getElementsByTagName('li');
    var listLength = focusBtnList.length;
    for (var i = 0; i < listLength; i++) {
        if (focusBtnList[i].className == 'current') var currentNum = i;
    }
    if (currentNum == 0 && listLength != 1) {
        moveElement('ifocus_piclist', 0, -175, 5);
        classNormal('ifocus_btn', 'ifocus_tx');
        classCurrent('ifocus_btn', 'ifocus_tx', 1);
    }
    if (currentNum == 1 && listLength != 2) {
        moveElement('ifocus_piclist', 0, -350, 5);
        classNormal('ifocus_btn', 'ifocus_tx');
        classCurrent('ifocus_btn', 'ifocus_tx', 2);
    }
    if (currentNum == 2 && listLength != 3) {
        moveElement('ifocus_piclist', 0, -525, 5);
        classNormal('ifocus_btn', 'ifocus_tx');
        classCurrent('ifocus_btn', 'ifocus_tx', 3);
    }
    if (currentNum == 3) {
        moveElement('ifocus_piclist', 0, 0, 5);
        classNormal('ifocus_btn', 'ifocus_tx');
        classCurrent('ifocus_btn', 'ifocus_tx', 0);
    }
    if (currentNum == 1 && listLength == 2) {
        moveElement('ifocus_piclist', 0, 0, 5);
        classNormal('ifocus_btn', 'ifocus_tx');
        classCurrent('ifocus_btn', 'ifocus_tx', 0);
    }
    if (currentNum == 2 && listLength == 3) {
        moveElement('ifocus_piclist', 0, 0, 5);
        classNormal('ifocus_btn', 'ifocus_tx');
        classCurrent('ifocus_btn', 'ifocus_tx', 0);
    }
}
