// required vars
var nav_left = 0;
var nav_left_increment = 90;
var nav_width = 740;
var nav_active = 0;

jQuery(document).ready(function()
{
    // nifty corners
    jQuery("div.action").nifty("big transparent top");
    jQuery("div.promotion, div.highlight").nifty("big transparent fixed-height");

    FLIR.init( { path: '/js/facelift/' } );
    jQuery('h1, h2, h3').each( function() { FLIR.replace(this); } );

    // applying some actions

    // action tab hover
    jQuery("div.action").hover(
        function() {

            // over

            // add class
            jQuery(this).addClass("hover");
        },
        function() {

           // out

           // remove class
           jQuery(this).removeClass("hover");
        }
    );

    // action tab slide
    jQuery("div.action > div.inner > h2").click(function(){

        // work out if we are going up or down
        if (jQuery(this).parent().parent().css("top") == "60px") {

            jQuery(this).parent().parent().addClass("active");

            jQuery(this).parent().parent().animate(
                {
                    top: 0
                },
                'slow'
            );

        } else {

            jQuery(this).parent().parent().removeClass("active");

            jQuery(this).parent().parent().animate(
                {
                    top: 60
                },
                'slow'
            );
        }

    });

	// attaching rollover to nav main elements
	// would be nice to eventually do this once for all that need it
	// but no time now
	jQuery('div#nav_main > div.inner > ul > li').hover(
	    function() {
	        //over
	        jQuery(this).find('a').find('img.imgOff').hide();
	        jQuery(this).find('a').find('img.imgOn').show();

	        // show the sub menu as well
	        jQuery(this).addClass("hover");

	    },
	    function() {
	        //out
	      	jQuery(this).find('a').find('img.imgOn').hide();
	        jQuery(this).find('a').find('img.imgOff').show();

	        // hide the sub menu
	        jQuery(this).removeClass("hover");
	    }
	);

	jQuery('div#nav_util > div.inner > ul > li').hover(
	    function() {
	        //over
	        jQuery(this).find('a').find('img.imgOff').hide();
	        jQuery(this).find('a').find('img.imgOn').show();

	    },
	    function() {
	        //out
	      	jQuery(this).find('a').find('img.imgOn').hide();
	        jQuery(this).find('a').find('img.imgOff').show();

	        // hide the sub menu
	        jQuery(this).removeClass("hover");
	    }
	);

    // moving the sub menus across to their rightful positions
	jQuery('div#nav_main > div.inner > ul > li > ul').each(function(i){

        var nav_shift_left = nav_left + 'px';
        jQuery(this).css('padding-left',nav_shift_left);

        var nav_new_width = nav_width - nav_left;
        nav_new_width = nav_new_width + 'px';
        jQuery(this).css('width',nav_new_width);

        nav_left += nav_left_increment;

	});

	// making li's in main nav active
	jQuery('div#nav_main a.active').each(function(i){

        jQuery(this).parent().addClass("active");

	});

	// applying rollover to utils nav
	// as mentioned above, would be nice to only do this once
	jQuery('div#nav_util > div.inner > ul > li > a').hover(
	    function() {
	        //over
	        jQuery(this).find('a').find('img.img0').hide();
	        jQuery(this).find('a').find('img.img1').show();

	    },
	    function() {
	        //out
	      	jQuery(this).find('a').find('img.img1').hide();
	        jQuery(this).find('a').find('img.img0').show();
	    }
	);

	// applying the scrollpane function to elements that require it
	jQuery('.scrollable').jScrollPane(
        {
            showArrows: true,
            scrollbarMargin: 10
        }
    );

    // promotion rollover
    jQuery("div.promotion").hover(
        function() {

            // over

            // set h3 colour
            jQuery(this).find("div.half_top > h3").css("color","#000");

            // set background color
            jQuery(this).find("div.half_bottom").css("background-color","#000");

            // switch more arrow
            var p_more = jQuery(this).find("div.half_bottom > p.more");
            p_more.removeClass("more");
            p_more.addClass("more_on");
        },
        function() {

           // out

            // set it back
            jQuery(this).find("div.half_top > h3").css("color","#fff");

           // set it back
           jQuery(this).find("div.half_bottom").css("background-color","transparent");

            // set it back
            var p_more = jQuery(this).find("div.half_bottom > p.more_on");
            p_more.removeClass("more_on");
            p_more.addClass("more");
        }
    );

    // promotion click
    jQuery("div.promotion > div.text > div").click(function(){

        var highlight_link = jQuery(this).parent().find("p.hidden a").attr("href");
        location.href = highlight_link;
        //location.href = '/nodes/view/12';

    });

    // highlight rollover
    jQuery("div.highlight").hover(
        function() {

            // over

            // switch class
            jQuery(this).removeClass("inactive");
            jQuery(this).addClass("active");
        },
        function() {

           // out

           // switch class
           jQuery(this).removeClass("active");
           jQuery(this).addClass("inactive");
        }
    );

    // highlight click
    jQuery("div.highlight").click(function(){

        var highlight_link = jQuery(this).find("div.text > div.inner > p.more > a").attr("href");
        location.href = highlight_link;
        //location.href = '/nodes/view/12';

    });

    // make buttons have a hover state
    jQuery("div.submit input").hover(
        function() {

            // over

            // switch class
            //jQuery(this).addClass("frm_but_hover");
            jQuery(this).css('background-color','#ff1100');
            jQuery(this).css('border','1px solid #4b0014');
            jQuery(this).css('color','#000');
        },
        function() {

           // out

           // switch class
           //jQuery(this).removeClass("frm_but_hover");
           jQuery(this).css('background-color','#80001c');
           jQuery(this).css('border','none');
           jQuery(this).css('color','#fff');
        }
    );

    // list li click
    jQuery("div.list > ul > li").click(function(){

        location.href = jQuery(this).find("span.list_link > a").attr("href");

    });

    // splash click
    jQuery("div#splash_click").click(function(){

        fadeSplash();

    });

   /* stripey li stuff */
    jQuery(".stripey li, .jq_stripey li").hover(
        function() {

            /* over */

            /* switch class */
            jQuery(this).addClass("hover");
        },
        function() {

           /* out */

           /* switch class */
           jQuery(this).removeClass("hover");
        }
    );

    jQuery(".stripey li:even, jq_stripey li:even").addClass("altrow");

   /* stripey table stuff */
    jQuery(".stripey tr, .jq_stripey tr").hover(
        function() {

            /* over */

            /* switch class */
            jQuery(this).addClass("hover");
        },
        function() {

           /* out */

           /* switch class */
           jQuery(this).removeClass("hover");
        }
    );

    jQuery(".stripey tr:even, .jq_stripey tr:even").addClass("altrow");

    // set flash to disappear no matter what
    setTimeout('fadeSplash()', 8000);

});

function splash_DoFSCommand(command, args) {
	if (command == "fadesplash") {
		fadeSplash();
	}
}

function fadeSplash() {
	jQuery("div#splash").fadeOut('normal');
	jQuery("div#splash_click").hide();
}
