﻿jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

/***** Preload images *****/
$.preloadImages(wpTemplatePath + '/_client/images/nav-arrow-over.png');


$(document).ready(function(){

    /***** Main Nav *****/
    // insert dropdowm menu buttons
    $("div#header > ul > li").append('<img src="' + wpTemplatePath + '/_client/images/spacer.gif" alt="" width="14" height="12" class="subnav" />');
    
    // wire up the click events
    $("div#header ul li img").click(function(){
        // determine direction
        var show = true;
        
        if($(this).parent().hasClass("expanded"))
            show = false;
        
        if(show)
        {   
            // hide any/all other active menus
            $("div#header > ul > li").removeClass("expanded");
            $("div#header > ul > li > ul").hide();
            
            // show the requested menu
            $(this).parent().addClass("expanded");
            $(this).siblings("ul").show();
        }
        else
        {
            $(this).parent().removeClass("expanded");
            $(this).siblings("ul").hide();
        }
    });
    
    // hide any active menus when user clicks elsewhere
	$("div#header > ul > li").hover(function(){},function(){
        $("div#header > ul > li").removeClass("expanded");
        $("div#header > ul > li > ul").hide();
    });
    $("div#header > ul > li > ul").hover(function(){},function(){
        $("div#header > ul > li").removeClass("expanded");
        $("div#header > ul > li > ul").hide();
    });
    
    
    /***** GutterBox rounded corners *****/
    // inserts a header and footer graphic into the gutterbox panels
    $("div#gutter div.gutterBox").prepend('<img src="' + wpTemplatePath + '/_client/images/gutterbox-top.png" class="topCorners" />'); 
    $("div#gutter div.gutterBox").append('<img src="' + wpTemplatePath + '/_client/images/gutterbox-bottom.png" class="bottomCorners" />');  
    
    /* Insert email address into any placeholders with enquiriesEmailAddress css class */
    $(".enquiriesEmailAddress").append('<a href="mailto:enquiries@highly-visible.net">enquiries@highly-visible.net</a>');
    
});