

jQuery.noConflict();

jQuery(document).ready(function ($) {

    // =================================================================== Apply the PNG fix for IE6
    $(document).pngFix();

    // =================================================================== Last Item Classes for nav elements
    $(".header_util li:last").addClass("util_last");
    $(".footer li:last").addClass("foot_last");

    $("input:checkbox, input:radio").width("auto");

    // =================================================================== Assign unique classes for Dropdown menu behaviour / colour-coding
    var navC = 0;
    $(".primaryNav li:first").hasClass("current") == true ? $(".primaryNav li:first").addClass("current_0") : null;
    $(".primaryNav li").each(function () {
        if ($(this).parents(".nav_hover_wrapper").length == 0) {
            navC == ($(".primaryNav li").length - 1) ? $(this).addClass("nav_last") : null;
            navC++;
        }
    });
    $(".primaryNav li.nav_item").hover(
		function () { $(this).toggleClass("shover"); $(this).find(".nav_hover_wrapper").show() },
		function () { $(this).toggleClass("shover"); $(this).find(".nav_hover_wrapper").hide() }
	);



    // ===================================================================  When page loads...
    // If there's a reference in the URL, then open that tab.

    var theURL = document.URL;
    var theURLhash = theURL.indexOf("#");

    $(".tab_content").hide(); //Hide all content
    if (theURLhash < 0) {
        $("ul.tab_nav li:first").addClass("active").show(); //Activate first tab
        $(".tab_content:first").show(); //Show first tab content
    }
    else {
        jQuery("html, body").animate({ scrollTop: 0 }, 0);
        $(".tabs li a").each(function (i) {
            $(this).attr("href") == theURL.substr(theURLhash, theURL.length) ? $(this).parents("li").addClass("active") : null;
        });
        $(theURL.substr(theURLhash, theURL.length)).show();
    }

    //On Click Event
    $("ul.tab_nav li").click(function () {

        $("ul.tab_nav li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });

    $(".header_search_input").focus(function () {
        if (this.value == "Enter Search Terms") {
            this.value = "";
        }

        else {
            this.select();
        }
    });

    $(".header_search_input").blur(function () {
        if (this.value == "") {
            this.value = "Enter Search Terms";
        }
    });

    /*$(".primaryNav li").mouseover(function () {
        if (!$(this).hasClass("hover")) {
            $(this).addClass("hover");
        }
    });

    $(".primaryNav li").mouseout(function () {
        if ($(this).hasClass("hover")) {
            $(this).removeClass("hover");
        }
    });*/

    $(".primaryNav div li a").mouseover(function () {
        if (!$(this).parent().hasClass("hover")) {
            $(this).parent().addClass("hover");
        }
    });

    $(".primaryNav div li a").mouseout(function () {
        if ($(this).parent().hasClass("hover")) {
            $(this).parent().removeClass("hover");
        }
    });

//    $(".primaryNav div li a").mouseout(function () {
//        return false;
//    });

//    $(".primaryNav div li a").mouseover(function () {
//        return false;
//    });

});

