/***************************************
 * @Script    Module & Basic Show
 * @Site      http://www.22vs.com
 * @Author    WANG Ping
 * @Updated   $Date: 2011-12-05 14:43
 * @Updated   $by:LIGUITUAN
 ***************************************/
(function($) {
    $.fn.bgIframe = $.fn.bgiframe = function(s) {
        if ($.browser.msie && /6.0/.test(navigator.userAgent)) {
            s = $.extend({
                top: 'auto',
                left: 'auto',
                width: 'auto',
                height: 'auto',
                opacity: true,
                src: 'javascript:false;'
            },
            s || {});
            var prop = function(n) {
                return n && n.constructor == Number ? n + 'px': n
            },
            html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="' + s.src + '"style="display:block;position:absolute;z-index:-1;' + (s.opacity !== false ? 'filter:Alpha(Opacity=\'0\');': '') + 'top:' + (s.top == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')': prop(s.top)) + ';left:' + (s.left == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')': prop(s.left)) + ';width:' + (s.width == 'auto' ? 'expression(this.parentNode.offsetWidth+\'px\')': prop(s.width)) + ';height:' + (s.height == 'auto' ? 'expression(this.parentNode.offsetHeight+\'px\')': prop(s.height)) + ';"/>';
            return this.each(function() {
                if ($('> iframe.bgiframe', this).length == 0) this.insertBefore(document.createElement(html), this.firstChild)
            })
        }
        return this
    }
})(jQuery);
function allCategory()
{
	$('.allCategory').each(function(){
									    var ___acg=$(this);
									    var lis=$(this).find('.itemlist li');
									    var display=$(this).find('.itemsub > div');
										lis.hover(function() {
											var liCur = lis.index(this);
											lis.eq(liCur).addClass("current").siblings().removeClass("current");
											display.eq(liCur).stop().show().bgiframe().siblings().stop().hide()
										});
										$(this).hover(function() {
											display.hide();
											lis.removeClass("current")
										});
										$(this).find(".allCategory h2").hover(function() {
											display.hide();
											lis.removeClass("current")
										})
									});
	$('.category').each(function(){
									    var ___cg=$(this);
									    var lis=$(this).find('.itemlist li');
									    var display=$(this).find('.itemsub > div');
										___cg.hover(function() {
											___cg.find(".itemlist").show().bgiframe();
											___cg.find(".viewall").addClass("current")
										},
										function() {
											___cg.find(".itemlist").hide();
											___cg.find(".viewall").removeClass("current");
											display.hide();
											lis.removeClass("current")
										});
										lis.hover(function() {
											var liCur = lis.index(this);
											lis.eq(liCur).addClass("current").siblings().removeClass("current");
											display.eq(liCur).stop().show().bgiframe().siblings().stop().hide()
										});
								 })
};
function mSericesItems(Sitem,SCitem)
{
    $(Sitem+' li').each(function() {
        $(this).hover(function() {
			for(var i=0;i<$(Sitem+' li').length;i++)
			{
				if(i!=$(this).index())
				{
					$(Sitem+' li').eq(i).removeClass("Scurrent");
					$(SCitem+' div').eq(i).removeClass("mycontent");
					$(SCitem+' div').eq(i).hide()
				}
			}
            $(this).addClass("Scurrent");
			$(SCitem+' div').eq($(this).index()).addClass("mycontent");
            $(SCitem+' div').eq($(this).index()).show().bgiframe()
        },
        function() {
			
			for(var i=0;i<$(Sitem+' li').length;i++)
			{
				if(i!=$(this).index())
				{
					$(Sitem+' li').eq(i).removeClass("Scurrent");
					$(SCitem+' div').eq(i).removeClass("mycontent");
					$(SCitem+' div').eq(i).hide()
				}
			}
        })
    })
}
function lgtitemsss()
{
	$('.liguituanitems').each(function(){
									   var ___lgti=$(this);
									   var ___scdiv=___lgti.find('.SCitems div');
									   var ___sli=___lgti.find('.Sitems li');
			                           ___sli.each(function(){
															$(this).hover(function(){
																					for(var i=0;i<___sli.length;i++)
																					{
																						if(i!=$(this).index())
																						{
																							___sli.eq(i).removeClass("Scurrent");
																							___scdiv.eq(i).removeClass("mycontent");
																							___scdiv.eq(i).hide()
																						}
																					}
																				   $(this).addClass("Scurrent");
																				   ___scdiv.eq($(this).index()).addClass("mycontent");
																				   ___scdiv.eq($(this).index()).show().bgiframe()
																				   },
																					function() {
																						for(var i=0;i<___sli.length;i++)
																						{
																							if(i!=$(this).index())
																							{
																								___sli.eq(i).removeClass("Scurrent");
																								___scdiv.eq(i).removeClass("mycontent");
																								___scdiv.eq(i).hide()
																							}
																						}
																					})
													 })
	 });
    $(".afterover").each(function() {
        $(this).hover(function() {
            $(this).addClass("current");
            $(this).find(".showlayer").show().bgiframe()
        },
        function() {
            $(this).removeClass("current");
            $(this).find(".showlayer").hide()
        })
    })
}
$(function() {
    allCategory();
	mSericesItems('#Sitems','#SCitems');
	mSericesItems('#HSitems','#HSCitems');
    lgtitemsss()
});

$.fn.extend({
    GetRandomInt: function(b, a) {
        return parseInt(Math.random() * (a - b), 10) + b
    },
    RandomImgListPlayer: function(g) {
        var j = {
            select: "div[name='focus_img_list']",
            timer: 5000,
            menu: "#play_text",
            imgsrc: "originalsrc"
        };
        g = g || {};
        $.extend(j, g);
        var c = $("'" + j.select + "'", this);
        var e = 0;
        var b = 1;
        c.hide();
        if (c.length > 0) {
            var a = null;
            var h = this.GetRandomInt(0, c.length);
            if (h >= c.length) {
                h = c.length - 1
            }
            var f = c.eq(h);
            f.show();
            var d = $("a > img", f);
            b = d.length;
            d.each(function(m) {
                var n = d.eq(m).attr(j.imgsrc);
                if (n != null && this.src == "") {
                    this.src = n
                }
            });
            var l = "<ul>";
            for (i = 1; i <= b; i++) {
                l = l + "<li>" + i + "</li>"
            }
            l = l + "</ul>";
            $(j.menu).html(l);
            $("a:not(:first-child)", this).hide();
            $(j.menu + " li").eq(0).css({
                background: "#7f0019",
                color: "#fff",
                "font-weight": "bolder"
            });
            $(j.menu + " li").mouseover(function() {
                i = $(this).text() - 1;
                e = i;
                if (e >= b) {
                    return
                }
                $(this).css({
                    background: "#7f0019",
                    color: "#fff",
                    "font-weight": "bolder"
                }).siblings().css({
                    background: "#fff",
                    color: "#7f0019",
                    "font-weight": "normal"
                });
                $("a", f).filter(":visible").fadeOut(200,
                function() {
                    $(this).parent().children().eq(e).animate({left: 0, opacity: 'show'}, 1000);
                })
            });
            var a = setInterval(k, j.timer);
            f.hover(function() {
                clearInterval(a)
            },
            function() {
                a = setInterval(k, j.timer)
            })
        }
        function k() {
            e = e >= (b - 1) ? 0 : ++e;
            $(j.menu + " li").eq(e).trigger("mouseover")
        }
    },
    RandomImgIsInit: false,
    RandomImgList: new Object(),
    AddRandomImg: function(d, c, b, a) {
        if (this.RandomImgIsInit == false) {
            this.RandomImgList.imgAry = new Array();
            this.RandomImgList.max = 0;
            this.RandomImgIsInit = true
        }
        var e = new Object();
        e.url = d;
        e.scale = parseInt(c);
        e.link = b;
        if (a == null) {
            e.aparam = ""
        } else {
            e.aparam = a
        }
        index = this.RandomImgList.imgAry.length;
        this.RandomImgList.imgAry[index] = e;
        this.RandomImgList.imgAry[index].scalemin = this.RandomImgList.max;
        this.RandomImgList.max = this.RandomImgList.max + this.RandomImgList.imgAry[index].scale;
        this.RandomImgList.imgAry[index].scalemax = this.RandomImgList.max
    },
    GetRandomImg: function() {
        ran = this.GetRandomInt(1, this.RandomImgList.max + 1);
        if (ran > this.RandomImgList.max) {
            return this.RandomImgList.imgAry[this.RandomImgList.imgAry.length - 1]
        } else {
            for (i = 0; i < this.RandomImgList.imgAry.length; i++) {
                if (ran > this.RandomImgList.imgAry[i].scalemin && ran <= this.RandomImgList.imgAry[i].scalemax) {
                    return this.RandomImgList.imgAry[i]
                }
            }
        }
    },
    GetRandomImgHTML: function() {
        var a = this.GetRandomImg();
        return "<a href='" + a.link + "' " + a.aparam + " target='_blank'><img src='" + a.url + "'/></a>"
    },
    GetRandomImgListHtml: function() {
        var a = this.GetRandomImg();
        var b = "";
        b = b + "<a href='" + a.link + "' " + a.aparam + " target='_blank'><img src='" + a.url + "'/></a>";
        this.RandomImgList.imgAry.sort(function(c, d) {
            if (c.scale != d.scale) {
                return d.scale - c.scale
            } else {
                return c.Index - d.Index
            }
        });
        for (i = 0; i < this.RandomImgList.imgAry.length; i++) {
            if (this.RandomImgList.imgAry[i].url != a.url) {
                b = b + "<a href='" + this.RandomImgList.imgAry[i].link + "' " + this.RandomImgList.imgAry[i].aparam + " target='_blank'><img src='" + this.RandomImgList.imgAry[i].url + "'/></a>"
            }
        }
        return b
    },
    RandomImgPlayer: function(a) {
        var b = {
            multiImg: false
        };
        a = a || {};
        $.extend(b, a);
        if (b.multiImg == true) {
            this.html(this.GetRandomImgListHtml())
        } else {
            this.html(this.GetRandomImgHTML())
        }
    },
    RandomHotKindPlayer: function(d) {
        var f = {
            select: "div.hotKindsArea div.hotKindsConArea"
        };
        d = d || {};
        $.extend(f, d);
        var a = $(f.select, this);
        if (a.length <= 0) {
            return
        }
        var c = 0;
        var b = new Array();
        a.each(function(h) {
            var g = 0;
            var k = a.eq(h).attr("scale");
            if (k != null && k != "") {
                g = parseInt(a.eq(h).attr("scale"), 10)
            } else {
                if (!a.eq(h).is(":hidden")) {
                    g = 100
                }
            }
            if (isNaN(g)) {
                g = 0
            }
            var j = b.length;
            b[j] = a.eq(h);
            b[j].scalemin = c;
            b[j].scalemax = c + g;
            c = b[j].scalemax
        });
        var e = this.GetRandomInt(0, c);
        if (e < 0 || e >= c) {
            e = 0
        }
        $.each(b,
        function(g, h) {
            if (h.scalemin != h.scalemax && e >= h.scalemin && e < h.scalemax) {
                h.show()
            } else {
                h.hide()
            }
        })
    }
});

