﻿var maxz = getZMax() + 2;
var menuzindex = maxz - 1;

$(document).ready(function() {
    //swap png images
    SwapPNGs();

    //activate drop down menu
    $("ul.top-nav").superfish({
        //dropShadows: true,
        autoArrows: false,
        onBeforeShow: function() {
            //$(this).find("a:last").corner("keep bottom");
            //$(this).find("a:last").addClass("black-corner");
        },
        onHide: function() {
            //$(this).find("a:last").uncorner();
        }
    });
    $("ul.sub-nav").superfish({
        autoArrows: false,
        delay: 300,
        speed: 'fast',
        onBeforeShow: function() {
            //add curve to bottom of menu
            //$(this).find("a:last").corner("bottom keep");

            //set sub menu to be the width of parent button
            var w = parseInt($(this).parent().find("img").width()) - 11;
            w = w + "px";
            //$(this).css({ "width": w });

            //set parent's z-index so that we can place the drop down menu under it
            $(this).parent().find("img").css({ "position": "relative", "zIndex": maxz });

            //set the menu's z-index to be less than the parents
            $(this).css({ "zIndex": menuzindex, "width": w });
        },
        onHide: function() {

        }
    });

    if (!($.browser.msie && $.browser.version.substr(0, 1) == "6")) {
        //add rounded borders to images
        AddBorder();
        //add rounded corners to elements
        AddRoundedCorners();
    } else {
        //fix css limitations
        UpdateIE6CSSLimitations();
    }
});

/*
 add rounded border to images
 TODO: make border thicker in photoshop
*/
function AddBorder() {

    $(".photo-border").each(function() {
        var offset = $(this).offset();
        var x = offset.left - 3;
        var y = offset.top - 3;
        if ($().flash.hasFlash()) {
            //alert('has flash');
            y = offset.top + 16;
        }
        var w = $(this).width() + 6;
        var h = $(this).height() + 6;
        $(this).after($("<img src='/images/corner.png'></img>").addClass("photo-border-wrapper").css({ "left": x, "top": y, "width": w, "height": h }));
    });  
    
    
    /*
    $(".photo-border-red").each(function() {
        var offset = $(this).offset();
        var x = offset.left - 3;
        var y = offset.top + 15;
        var w = $(this).width() + 6;
        var h = $(this).height() + 8;
        $(this).after($("<img src='/images/corner.png' alt='corner'></img>").addClass("photo-border-wrapper").css({ "left": x, "top": y, "width": w, "height": h }));
    });*/
}
/*
 add rounded corners to element
*/
function AddRoundedCorners() {
    if ($(".fire-house").length > 0) {
        $(".fire-house").corner("cc:#ffffff");
        $(".fire-house > .inner").corner();
    }
    if ($(".winners-prizes").length > 0) {
        $(".winners-prizes").corner("cc:#ffffff");
        $(".winners-prizes > .inner").corner();
    }
    if ($(".slide-show-box").length > 0) {
        $(".slide-show-box").corner("cc:#ffffff");
        $(".slide-show-box > .inner").corner();
    }
    if ($(".red-box").length > 0) {
        $(".red-box").corner("cc:#ffffff");
        $(".red-box > .inner").corner();
    }
}
/*
close slideshow popup window
*/
function CloseSlideShow() {
    modalWindow.close();
}
/*
swap out png images for gif images in IE6
*/
function SwapPNGs() {
    if ($.browser.msie && $.browser.version.substr(0, 1) == "6") {
        $(".swap-png").each(function() {
            var currentSrc = $(this).attr("src");
            var length = currentSrc.length;
            currentSrc = currentSrc.slice(0, length - 4);
            var newSrc = currentSrc + ".gif";
            $(this).attr({ "src": newSrc });
            $(this).css({ "display": "inline" });
        });
    }
}
/*
get the max z-index on the page
*/
function getZMax() {
    var zmax = 0;
    $('*').each(function() {
        var cur = parseInt($(this).css('zIndex'));
        zmax = cur > zmax ? $(this).css('zIndex') : zmax;
    });
    return zmax;
}
/*
 update ie6 css limitations
*/
function UpdateIE6CSSLimitations() {
}
