/*V.08102502/A.Zed Gu/D.VI Operation*/
var ajaxdomain = top.location.href.match(/^(\w+:\/\/)?(\w+\.)+(\w+)/i);
document.domain = ajaxdomain[2] + ajaxdomain[3];
var sideSwitch = {is:false,turn:function() {
    if (sideSwitch.is) {
        $('navigation').setS('display', 'none');
        $('itemInfo').setA('className', 'w');
        $('itemInfo').setS('width', '965px');
        this.className = '';
        sideSwitch.is = false
    } else {
        $('navigation').setS('display', 'block');
        $('itemInfo').setA('className', 'n');
        $('itemInfo').setS('width', '780px');
        this.className = 'c';
        sideSwitch.is = true
    }
    sideSwitch.fixHeight()
},fixHeight:function() {
    if ($('switch').length) {
        $('switch').setS('height', $('itemInfo').getA('offsetHeight').toPx())
    }
},apply:function() {
    if ($('switch').length) {
        $('switch').getTags('a')[0].onmousedown = sideSwitch.turn;
        $('switch').getTags('a')[0].onclick = function() {
            return false
        };
        $('switch').setS('height', $('main').getA('offsetHeight').toPx());
        var a = $('seller')[0].cloneNode(true);
        var x = $('outad')[0].cloneNode(true);
        x.style.display = "block";
        if ($('seller')[0].parentNode.id == 'navigation')
        {
            sideSwitch.is = true;
            $('itemInfo').setS('width', '780px');
            $('switch').getTags('a')[0].className = 'c';
            $('itemDetail').append(a);
            a.id = 'seller';
        }
        else if ($('seller')[0].parentNode.id == 'itemDetail')
        {

            if ($('nav').length)
            {
                $('navigation')[0].insertBefore(a, $('nav'));
                $('navigation')[0].insertBefore(x, $('nav'));
            } else
            {
                document.getElementById('navigation').appendChild(a);
                document.getElementById('navigation').appendChild(x);
            }
            a.id = 'newSeller';
            x.id = 'newOutad';
        }
        LIM.init()
    }
}
};
var itemInfoSwitch = {now:0,blocks:['itemDesc','escrowInfo','itemSale','itemFeedback'],tabs:function() {
    return $('itemInfoTab').getTags('a')
},turn:function(e) {
    if (this == itemInfoSwitch.tabs()[0]) {
        for (var i = 0;
             i < itemInfoSwitch.tabs().length;
             i++) {
            $(itemInfoSwitch.blocks[i]).setS('display', 'block');
            $(itemInfoSwitch.tabs()[i])[0].parentNode.className = ''
        }
    } else {
        for (var i = 0;
             i < itemInfoSwitch.tabs().length;
             i++) {
            $(itemInfoSwitch.tabs()[i])[0].parentNode.className = '';
            $(itemInfoSwitch.blocks[i]).setS('display', 'none');
            if (this == itemInfoSwitch.tabs()[i]) {
                itemInfoSwitch.now = i
            }
        }
        $(itemInfoSwitch.blocks[itemInfoSwitch.now]).setS('display', 'block')
    }
    this.parentNode.className = 'c';
    sideSwitch.fixHeight();
    return false
},apply:function() {
    for (var i = 0;
         i < itemInfoSwitch.tabs().length;
         i++) {
        itemInfoSwitch.tabs()[i].onclick = itemInfoSwitch.turn
    }
}};
var storeInfo = {mod:['links'],blocks:{'links':'友情链接'},xmlNode:{'links':['link','linkName','linkURL']},storeID:null,xmlPath:'',i:0,get:function() {
//    var storeInfo = {mod:['category','links'],blocks:{'category':'商品目录','links':'友情链接'},xmlNode:{'category':['level','cateName','cateID'],'links':['link','linkName','linkURL']},storeID:null,xmlPath:'',i:0,get:function() {

    var a = 'xml';
    if (!document.all) {
        a = 'text'
    }
    $('apStore')[0].contentWindow.eja.get((storeInfo.xmlPath + storeInfo.mod[storeInfo.i] + storeInfo.storeID + '.xml'), null, function(p) {
        if (!document.all) {
            p = (new DOMParser()).parseFromString(p, "text/xml")
        }
        if(p==null||p.lastChild==null||storeInfo==null||storeInfo.mod==null)
        {
                return ;
        }
        if (p.lastChild.nodeName == storeInfo.mod[storeInfo.i]) {
            storeInfo.addBlock(storeInfo.mod[storeInfo.i], p.lastChild);
            storeInfo.i++;
            if (storeInfo.i < storeInfo.mod.length) {
                storeInfo.get()
            }
        }
    }, a)
},addBlock:function(a, p) {
    if (p.getElementsByTagName(storeInfo.xmlNode[a][0]).length > 0) {
        var b = document.createElement('div');
        $('nav').append(b);
        var h = document.createElement('h3');
        b.appendChild(h);
        h.innerHTML = storeInfo.blocks[a];
        storeInfo.addLi(p, b, storeInfo.xmlNode[a])
    }
},addLi:function(p, b, c) {
    if (p.getElementsByTagName(c[0]).length > 0) {
        var d = document.createElement('ul');
        b.appendChild(d);
        if (b.nodeName == 'LI') {
            var s = document.createElement('span');
            s.title = '折叠/展开';
            s.className = 's';
            b.insertBefore(s, b.childNodes[0]);
            s.onclick = storeInfo.liSwitch
        }
        for (var i = 0;
             i < p.childNodes.length;
             i++) {
            if (p.childNodes[i].nodeType == 1 && p.childNodes[i].nodeName == c[0]) {
                var e = document.createElement('li');
                var a = document.createElement('a');
                a.innerHTML = p.childNodes[i].getElementsByTagName(c[1])[0].firstChild.nodeValue;
                if (c[0] == 'level') {
                    a.href = storeserver + '/shop/proList.do?shopId=' + storeInfo.storeID + '&sortId=' + p.childNodes[i].getElementsByTagName(c[2])[0].firstChild.nodeValue
                } else if (c[0] == 'link') {
                    a.href = p.childNodes[i].getElementsByTagName(c[2])[0].firstChild.nodeValue
                }
                a.target = '_blank';
                e.appendChild(a);
                d.appendChild(e);
                storeInfo.addLi(p.childNodes[i], e, c)
            }
        }
    }
},liSwitch:function() {
    if (this.className == 's') {
        this.parentNode.getElementsByTagName('ul')[0].style.display = 'none';
        this.className = 'p'
    } else {
        this.parentNode.getElementsByTagName('ul')[0].style.display = 'block';
        this.className = 's'
    }
},apply:function(a) {
    if ($('navigation').length) {
        this.storeID = a;
        this.xmlPath = picserver + '/vi/store/' + a.charAt(a.length - 2) + a.charAt(a.length - 1) + '/' + a.charAt(a.length - 1) + '/';
        if (this.storeID && this.storeID != 0 && this.storeID != '0' && storeindex != '2' && storeindex != 2) {
            var b = document.createElement('div');
            b.id = 'nav';
            $('navigation').append(b);
//            $('navigation').append($('hotsort'));
            this.get()
        }
    }
}};
var sidefloat = {cart:{added:false,add:function(a, b, c, d) {
    if (!sidefloat.cart.added && $('apCart')) {
        sidefloat.cart.added = true;
        $('apCart')[0].contentWindow.eja.get(mycartserver + "/AddPrdFromCart.do?prdId=" + a + "&imgs=" + b + "&names=" + c + "&values=" + d, null, function(p) {
            if (p == '1') {
                $('itemProperty').append(JEND.DOM.create('p', {className:'hl'}, '已加入购物车。'))
            }
        })
    }
},show:function() {
}},show:function() {
}};
var hl = {c:function() {
}};
document.onReady(function() {
    sideSwitch.apply();
    itemInfoSwitch.apply()
});
