﻿
stuHover = function() {
    var cssRule;
    var newSelector;
    for (var i = 0; i < document.styleSheets.length; i++)
        for (var x = 0; x < document.styleSheets[i].rules.length; x++) {
        cssRule = document.styleSheets[i].rules[x];
        if (cssRule.selectorText.indexOf("LI:hover") != -1) {
            newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
            document.styleSheets[i].addRule(newSelector, cssRule.style.cssText);
        }
    }
    var getElm = document.getElementById("nav").getElementsByTagName("LI");
    for (var i = 0; i < getElm.length; i++) {
        getElm[i].onmouseover = function() {
            this.className += " iehover";
        }
        getElm[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" iehover\\b"), "");
        }
    }
}
$(function() { stuHover; });

var tao = {
    //playswf
    playswf: function(sFile, sWidth, sHeight) {
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0/#version=7,0,19,0/" width="' + sWidth + '" height="' + sHeight + '">  ');
        document.write(' <param name="movie" value="' + sFile + '">  ');
        document.write(' <param name="quality" value="high">  ');
        document.write(' <param name="wmode" value="transparent">  ');
        document.write(' <embed src="' + sFile + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + sWidth + '" height="' + sHeight + '"></embed>  ');
        document.write('</object> ');
    },

    //playimg
    playimg: function(sFile, sWidth, sHeight) {
        document.write('<div id="adimg" style="background-image:url(' + sFile + '.jpg);background-repeat:no-repeat;height:' + sHeight + 'px;width:' + sWidth + 'px;">');
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0/#version=6,0,29,0/" width="' + sWidth + '" height="' + sHeight + '">  ');
        document.write(' <param name="movie" value="' + sFile + '.swf">  ');
        document.write(' <param name="quality" value="high">  ');
        document.write(' <param name="wmode" value="transparent">  ');
        document.write(' <embed src="' + sFile + '.swf" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + sWidth + '" height="' + sHeight + '"></embed>  ');
        document.write('</object> ');
        document.write('</div> ');
    }
}


$(function() {
    //topMenu效果
    var topPath = 0, subPath = 0;
    var href = window.location.pathname;
    var re = /([^\d]+)(\d{2,6})+[^\d]?[^\.]*(\.aspx)/;
    var path = href.match(re);
    if (path) {
        topPath = path[2].substring(0, 2);
        allPath = path[2];
        $("#nav>li>a[href*='" + topPath + "']").addClass("top_linkpath");
        if (path[2].length > 2) {
            subPath = path[2].substring(0, 4);
            var x = $("#left_nav>ul>li>a[href*='" + subPath + "']").addClass("v").next("img");
            //alert(x.next("img")[0].src)
            if (x) {
                x.next().find("a[href*='" + allPath + "']").addClass("v");
                x.attr("src", "images/ar_down.gif");
                x.next().slideDown("slow");
            }
        }
    }
    else {
        $("#nav>li>a[href*='default']").addClass("top_linkpath");
    }
    getheight();
    $("#left_nav").find("img").toggle(
              function() {
                  //$("#left_nav>ul>ul:visible").hide();
                  $("#left_nav ul").find("ul:visible").hide().prev("img").attr("src", "images/ar_right.gif");
                  $(this).attr("src", "images/ar_down.gif");
                  $(this).next().slideDown("slow");
              },
              function() {
                  $(this).attr("src", "images/ar_right.gif");
                  $(this).next().slideUp("slow");
              }
            );

    // more
    $("#outer").find("div.more").toggle(
              function() {
                  $(this).find("i.show").hide();
                  $(this).find("i.hide").show();
                  $(this).find("table").slideDown("slow");
              },
              function() {
                  $(this).find("i.hide").hide();
                  $(this).find("i.show").show();
                  $(this).find("table").slideUp("slow");
              }
            );
    //newsAsk

    $("#dlnewsAsk").find("dt").toggle(
              function() {
                  $(this).toggleClass("current");
                  $(this).next("dd").slideDown("slow");
                  $("#foot").css("position", "static");
              },
              function() {
                  $(this).toggleClass("current");
                  $(this).next("dd").slideUp("slow");
              }
            );
    //其它
    $(".defaultnews").eq(0).find("a").eq(0).css("color", "red");
    //$("#tag").trigger("click");

    //vip	          
    if ($.cookie('ybuser')) {
        var showvip = ($.cookie('ybuser').split("&")[0]).split("=")[1];
        if (showvip) {
            $("#showlog").hide();
            $("#showvip").show().prepend("欢迎您：" + showvip + "<em>|</em><a href=\"userCart.aspx?code=9901\"><img src=\"images/buy_in.gif\" alt=\"查看订单\"/></a><em>|</em><a id='logout' href=\"#\">退出</a>");

        }
        else {
            $("#showlog").show();
            $("#showvip").hide();
        }
    }; 
    
    $("#logout").click(function() {
        $.cookie('ybuser', null);
        $.ajax({
            type: "POST",   //访问WebService使用Post方式请求
            dataType: 'json',
            contentType: "application/json", //WebService 会返回Json类型
            url: "vip/vipAjax.asmx/logout",  //注册
            data: "{}",
            error: function(response) {
                alert("系统了出错，请下次再试");
            },
            success: function(msg) {
                //alert($.cookie("ybuser"));
                window.location.reload();
            }
        });
        return false;
    });


  


});
//footer位置		
function getheight() {
    var h3 = $(window).height();
    //alert(h3);
    //alert($("#foot").offset().top);
    if ($("#foot").offset().top + 80 < h3) {
        $("#foot").css('top', h3 - 80);
    }
    $("#foot").show();
};
function updated() {//ajax
    tb_remove();
    window.location.href = window.location.href;
};

//插件
// Used on pre-formated <DIV><UL.tabsul><DIVs></DIV> section
jQuery.fn.Tabs = function() {
    return this.each(function() {
        x = $(this);
        var targets = x.children("div").addClass("tabsdiv").hide();

        x.children(".tabsul").children("li").each(function(i) {
            this.target = targets[i];
            $(this).click(function() {
                if ($(this).is(".on")) return;

                y = $(this).siblings(".on");
                y.add(this).toggleClass("on");

                $(this.target).add(y.size() > 0 ? y[0].target : null).toggle();
            });
        });
        x.children(".tabsul").children("li:visible").eq(0).click();

    });
};