$(document).ready(function () {

    // For each link containing -off, set up a -on hover
    $("img[src*='-off']").each(function () {

        // Preload on state
        var img = new Image();
        img.src = $(this).attr("src").replace(/-off/, "-on");

        // Set up the hover switcher
        $(this).hover(function () {
            $(this).attr("src", $(this).attr("src").replace(/-off/, "-on"));
        }, function () {
            $(this).attr("src", $(this).attr("src").replace(/-on/, "-off"));
        });


    });



    $('.homepageSliders').after('<ul id="circle_nav">').cycle({
        speed: 200,
        timeout: 8000,
        pager: '#circle_nav',
        // callback fn that creates a nav to use as pager links 
        pagerAnchorBuilder: function (idx, slide) {
            return '<li><a href="#"></a></li>'; // *NOTE: we add a background to the anchor thru CSS
        }

    });


    //SETUP HOVER EVENT ON PILLARS
    /*	$('.pillars-navUL li').hover(
    function () {
    // if we're hovering over any pillar except the big red first one... "area of focus"
    if($(this).index() > 0){
    var curIndex = $(this).index();
    //do minus one to compensate for zero based index of cycle
    $('.homepageSliders').cycle(curIndex - 1);
    $('.homepageSliders').cycle('pause');
    }
    },
    function () {
    $('.homepageSliders').cycle('resume');
    }
    );*/


    //SETUP TOP LEFT CORNER ON MAIN NAV
    $('.main-navUL').corner('cc:#492f92 tl');


    //FIX IE7 MENU STICKY BUG FOR MAIN DROP DOWNS
    $(".main-navUL > li").hover(
      	function () { $(this).find("ul").css("left", 'auto'); },
      	function () { $(this).find("ul").css("left", '-999px'); }
   );
    //FIX IE7 MENU STICKY BUG FOR PILLAR DROP DOWNS
    $(".pillars-navUL > li").hover(
      	function () { $(this).find("ul").css("left", 'auto'); },
      	function () { $(this).find("ul").css("left", '-999px'); }
   );

    //FIX LAST PILLAR DROP DOWN MENU TO GO LEFT
    $(".pillars-navUL > li:last").hover(
      	function () { $(this).find("ul").css("right", '0'); },
      	function () { $(this).find("ul").css("left", '-999px'); }
   );

    //keep the parent in the main menu in on state as sub menu is being used			
    $(".main-navUL > li > ul").hover(
	function () {
	    $(this).parent().children('a').css("background", 'url("images/wrapper/main-nav-bg-nocurve-on.png") repeat-x scroll left top transparent');
	},
	function () {
	    $(this).parent().children('a').css("background", 'url("images/wrapper/main-nav-bg-nocurve.png") repeat-x scroll left top transparent');
	}
	);

    //ENSURE THE MAIN NAV HOVER COMES ON, CSS FLAKES OUT A BIT
    $(".main-navUL > li > a").hover(
      	function () { $(this).css("background", 'url("images/wrapper/main-nav-bg-nocurve-on.png") repeat-x scroll left top transparent'); },
      	function () { $(this).css("background", 'url("images/wrapper/main-nav-bg-nocurve.png") repeat-x scroll left top transparent'); }
   );


    /* AREAS OF FOCUS FLYOUT
    *-----------------------------------------------------------------------------------------------
    */
    //hide on load
    $(".pillarsBoxGradientBottom").hide();

    //toggle visibility
    $('.areasOfFocus_btn').toggle(function () {
        $(".pillarsBoxGradientBottom").show();
        $(this).attr("src", $(this).attr("src").replace(/-closed/, "-open"));
    }, function () {
        $(".pillarsBoxGradientBottom").hide();
        $(this).attr("src", $(this).attr("src").replace(/-open/, "-closed"));
    });


});







