var FEATURED_POS = 0;
var ABS_PATH;
$(window).load(function(){
    $.setOverlay();
    $(document).everyTime("10s", "rotateFeature", function(){
        $.featureGo()
    }, 0);
    $("#loveFootballSwf").flash({
        swf: ABS_PATH + "/flash/header_flash_piece.swf",
        width: $("#loveFootballSwf").width(),
        height: 41,
        params: {
            play: true,
            wmode: "transparent"
        }
    })
});
$(window).resize(function(){
    $.setOverlay()
});
$(window).scroll(function(){
    $.setOverlay()
});
$(document).ready(function(){
    ABS_PATH = $("#siteRoot").html();
	
    $(".itemFeaturette .contentArea").pngFix();
    $(".itemShadow").pngFix();
    $("#puma_main_subscribe_email").focus(function(){
        if (this.value == this.defaultValue) {
            this.value = ""
        }
    }).blur(function(){
        if (!this.value.length) {
            this.value = this.defaultValue
        }
    });
    $("#s").focus(function(){
        if (this.value == this.defaultValue) {
            this.value = ""
        }
    }).blur(function(){
        if (!this.value.length) {
            this.value = this.defaultValue
        }
    });
    $("#navFirst").hover(function(){
        $("#navFirst ul").animate({
            height: "505px"
        }, 500)
    }, function(){
        $("#navFirst ul").animate({
            height: "0px"
        }, 500)
    });
    $("#puma_main_subscribe").submit(function(){
        if (this.email.value.split("@").length > 1) {
            email = escape(this.email.value)
        }
        else {
            email = ""
        }
        dest = "http://resources.puma.com/mailing_list.jsp?css=" + escape(this.css.value) + "&site=" + this.site.value + "&email=" + email + "&TB_iframe=true&height=500&width=450";
        tb_show("Post preview", dest, false);
        return false
    });
    $(".videoArea a").click(function(){
        var b = $(this).siblings(".vid").html();
        $(this).parent().flash({
            swf: ABS_PATH + "/videoplayer/video.swf",
            width: 631,
            height: 380,
            flashvars: {
                playSt: b
            },
            params: {
                play: true,
                wmode: "transparent",
                allowFullScreen: "true"
            }
        });
        return false
    });
    $(".flashPiece").click(function(){
        var b = $(this);
        $("#overlaySwf").flash({
            swf: b.siblings("h6:eq(0)").html(),
            width: b.siblings("h6:eq(1)").html(),
            height: b.siblings("h6:eq(2)").html(),
            params: {
                play: true,
                wmode: "transparent"
            }
        });
        $("#overlay").show();
        $("#overlayFiller").show();
        return false
    });
    $("#overlay a").click(function(){
        $("#overlay").hide();
        $("#overlayFiller").hide();
        $("#overlaySwf").html("");
        return false
    });
    $("#overlayFiller").click(function(){
        $("#overlay").hide();
        $("#overlayFiller").hide();
        $("#overlaySwf").html("");
        return false
    });
    $(".featureControls a").click(function(){
        $(document).stopTime("rotateFeature");
        var b = this.id.split("_");
        var b = b[1];
        $.featureGo(b);
        return false
    });
    var a;
    $(".itemGallery").each(function(){
        a = new Gallery($(this))
    })
});
var Gallery = function(a){
    this.elem = a;
    this.size = $(".carousel ul li", a).length;
    this.pos = 0;
    this.bindHandlers()
};
Gallery.prototype.bindHandlers = function(){
    var a = this;
    $(".backBtn a", a.elem).click(function(){
        a.pos = (a.pos - 1) < 0 ? a.size - 1 : a.pos - 1;
        var b = (a.pos * 631) * -1;
        $(".carousel ul", a.elem).animate({
            left: b + "px"
        }, 500);
        $(".controls span", a.elem).html((a.pos + 1) + "/" + a.size);
        return false
    });
    $(".fwdBtn a", a.elem).click(function(){
        a.pos = (a.pos + 1) >= a.size ? 0 : a.pos + 1;
        var b = (a.pos * 631) * -1;
        $(".carousel ul", a.elem).animate({
            left: b + "px"
        }, 500);
        $(".controls span", a.elem).html((a.pos + 1) + "/" + a.size);
        return false
    });
    $(".carousel a", a.elem).click(function(){
        a.pos = (a.pos + 1) >= a.size ? 0 : a.pos + 1;
        var b = (a.pos * 631) * -1;
        $(".carousel ul", a.elem).animate({
            left: b + "px"
        }, 500);
        $(".controls span", a.elem).html((a.pos + 1) + "/" + a.size);
        return false
    })
};
$.featureGo = function(b){
    var a = $(".featureControls a").size();
    if (b == null) {
        FEATURED_POS = (FEATURED_POS + 1) >= a ? 0 : FEATURED_POS + 1
    }
    else {
        FEATURED_POS = b
    }
    var c = FEATURED_POS * 959 * -1;
    $(".itemFeature .contentArea ul").animate({
        left: c + "px"
    }, 400);
    $(".featureControls a").removeClass("on");
    $(".featureControls a:eq(" + FEATURED_POS + ")").addClass("on")
};
$.setOverlay = function(){
    $("#overlayFiller").height($.getDocHeight());
    var b = $(window).scrollLeft();
    var a = $(window).scrollTop();
    var d = $("#overlay").outerWidth();
    var f = $("#overlay").outerHeight();
    var c = window.innerWidth;
    var e = window.innerHeight;
    a = a + ((e - 600) / 2);
    b = $("#header").position().left;
    $("#overlay").css("left", b);
    $("#overlay").css("top", a)
};
function clone(c){
    if (c == null || typeof(c) != "object") {
        return c
    }
    var a = new c.constructor();
    for (var b in c) {
        a[b] = clone(c[b])
    }
    return a
}

$.getDocWidth = function(){
    return Math.max($(document).width(), $(window).width(), document.documentElement.clientWidth)
};
$.getDocHeight = function(){
    return Math.max($(document).height(), $(window).height(), document.documentElement.clientHeight)
};
function hidediv(){
	$("#takeover").remove();
}
