$(document).ready(function(){
    //pre load images
    var images = 	[
    "images/pdfButton_hover.png",
    "images/eventDate_hover.png"
    ];
    for(i=0;i<images.length;i++)
    {
        var img = new Image();
        img.src=images[i];
    }
	
    resizeContents();
	
    $("a.resizableLink").click(function(){
        var id = $(this).attr("id").replace("_link","");
        var offset = $("#"+id).offset();

        //set button active
        $("#nav li").removeClass("active");
        $(this).parent("li").addClass("active")
        $("#nav").children("li").each(function(){
            var $link = $(this).children("a");

            if($(this).hasClass("active"))
            {
                Cufon.replace("#"+$link.attr("id"),{
                    fontFamily:"TS",
                    fontWeight:"bold",
                    forceHitArea:true
                })
            }
            else
            {
                Cufon.replace("#"+$link.attr("id"),{
                    fontFamily:"TS",
                    fontWeight:"normal",
                    forceHitArea:true
                })
            }
        });
	
        //animate scrolling
        $("html,body").animate({
            scrollTop:offset.top
        },800);
		
        return false;
    });
	
    //pdf rollover
    $("#pdfLink").hover(function(){
        var pdf = $(this).children('img');
		
        pdf.attr("src","images/pdfButton_hover.png");
    },function(){
        var pdf = $(this).children('img');
		
        pdf.attr("src","images/pdfButton.png");
    })
	
    //studio 385 rollover
    $("#eventDateLink").hover(function(){
        var date = $(this).children('img');
		
        date.attr("src","images/eventDate_hover.png");
    },function(){
        var date = $(this).children('img');
		
        date.attr("src","images/eventDate.png");
    });
    //children of war title hover
    $("#childrenOfWarLink").hover(function(){
        Cufon.replace('#childrenOfWarLink',{color:"#ffffff",fontFamily:"TS_BOLD",forceHitArea:true});
    },function(){
        Cufon.replace('#childrenOfWarLink',{color:"#c5c4b5",fontFamily:"TS_BOLD",forceHitArea:true});
    });

    //contact email hover function for cufon
    $("#contactEmailWrapper").hover(function(){
        Cufon.replace('#contactEmailWrapper span',{color:"#ffffff",fontFamily:"TS_BOLD",forceHitArea:true});
        Cufon.replace('#contactEmailWrapper a',{color:"#c5c4b5",fontFamily:"TS_BOLD",forceHitArea:true});
    },function(){
        Cufon.replace('#contactEmailWrapper span',{color:"#c5c4b5",fontFamily:"TS_BOLD",forceHitArea:true});
        Cufon.replace('#contactEmailWrapper a',{color:"#ffffff",fontFamily:"TS_BOLD",forceHitArea:true});
    });
    
    //header email rollover
    $("a.headEmail").hover(function(){
        Cufon.replace('a.headEmail',{color:"#c5c4b5",fontFamily:"TS",forceHitArea:true});
        Cufon.replace('a.headEmail span',{color:"#ffffff",fontFamily:"TS",forceHitArea:true});
    },function(){
        Cufon.replace('a.headEmail',{color:"#ffffff",fontFamily:"TS",forceHitArea:true});
        Cufon.replace('a.headEmail span',{color:"#c5c4b5",fontFamily:"TS",forceHitArea:true});
    });

    //emails hover function for cufon
    $('a.contactLink').hover(function(){
        Cufon.replace("#"+$(this).attr('id'),{color:"#c5c4b5",fontFamily:"TS",forceHitArea:true});
    },function(){
        Cufon.replace("#"+$(this).attr('id'),{color:"#ffffff",fontFamily:"TS",forceHitArea:true});
    });

    //video link
    $("a.showTrailer").colorbox({
        iframe:true,
        innerWidth:425,
        innerHeight:344,
        onComplete:function(){
            $("#cboxClose").css({
                background:"none"
            }).html('<span class="cbCloseText">CLOSE</span>')
        }
    });

    
});
$(window).resize(function(){
    resizeContents();
})

function resizeContents()
{
    var windowHeight = $(window).height();
    var minHeight = 1010;
    var tallest = minHeight;

    $("div.resizable").each(function(){
        if($(this).height() > tallest)
            tallest = $(this).height();
    });

    $("div.resizable").height(tallest);
}