// JavaScript Document
// Common Site Code for HVDHB V1.0
// (C)2010 DataTorque Limitied, Wellington, New Zealand
// Developer: Craig Ray

//Switchable Style Sheets
var currentStyeSheet = $.cookie('stylesheet');
//alert('Cookie StyleSheet = ' + currentStyeSheet);
if (currentStyeSheet == null) {
    /* Clear All Style Sheets */
    ClearAllStyles();
    /* Enable the default style sheet */
    document.styleSheets[0].disabled = false;

}
else {
    /* Clear All Style Sheets */
    ClearAllStyles();
    /* Enable the default style sheet */
    document.styleSheets[currentStyeSheet].disabled = false;
};


//////////////////////////////
// Document Ready Functions //
//////////////////////////////
$(document).ready(function() {
    ClearAllStyles();

    //Initial Show / Hide
    $("#urgent_show").hide();
    $("#show_notifications").hide();

    //Open and CLose Text Optinos
    $("#textoptions").click(function() {
        $("#accessability").slideDown();
    });
    $("#access_close").click(function() {
        $("#accessability").slideUp();
    });
    
    //IE6 Fix to photo newslist transparent white bar
    $(".homecontent_features_bar_image").hide();

    $(".homecontent_features_bar_image").show();

    //Scrollto Top of Page

    $("#backtotop").click(function() {
        $.scrollTo("#header", 500);
    });

    //Hide and Show Urgent Notifications

    // Get Cookie Value
    var cookieNotifications = $.cookie('notifications');
    // Set Show / Hide Status
    if (cookieNotifications == 'hide') {
        $("#notifications").hide();
        $("#show_notifications").show();
    };
    if (cookieNotifications == 'show') {
        $("#notifications").show();
        $("#show_notifications").hide();
    };

    $("#urgent_hide").click(function() {
        $("#notifications").slideUp(200, function() {
            $("#show_notifications").fadeIn();
        });

        // Write Cookie - for expiry date user $.cookie('notifications', 'hide',{ expires: 10 }); = 10 days 
        $.cookie('notifications', 'hide');

    });
    $("#show_notifications").click(function() {
        $("#notifications").slideDown(200);
        $("#show_notifications").hide();
        // Write Cookie
        $.cookie('notifications', 'show');
    });

    //Clear Search box onclick
    $(".searchinput").focus(function() {
        $(".searchinput").val('');
    });

    // Urgent Items Cycle
    $('#notification_items').cycle({
        fx: 'scrollVert',
        speed: 1000,
        timeout: 6000,
        cleartype: 0,
        pause: true,
        prev: '#urgent_prev',
        next: '#urgent_next'
    });

    //Colorbox Styles
    $(".colorbox1").colorbox({ transition: "elastic", width: "600", height: "500" });
    // Close colourbox
    $(".colorboxclose").click(function() {
        alert('Closing');
        $.fn.colorbox.close();
    });

    // Set section title on left menu from the value of Level0Selected
    var SectionTitle = $(".Level0Selected a").text();
    $("#title_section").text(SectionTitle);

    //Print Page
    $("#printpage").click(function() {
        //Send Notice to IE6 Users						   
        if ($.browser.msie && $.browser.version == "6.0") {
            alert("Sorry,\r\rPlease print this page using the File > Print menu in the browser.\r\rIE6 Does not support the quick print icon.");
        };

        window.print();
    });


    //Switchable Style Sheets
    var currentStyeSheet = $.cookie('stylesheet');
    //alert('Cookie StyleSheet = ' + currentStyeSheet);
    if (currentStyeSheet == null) {
        /* Clear All Style Sheets */
        ClearAllStyles();
        /* Enable the default style sheet */
        document.styleSheets[0].disabled = false;

    }
    else {
        /* Clear All Style Sheets */
        ClearAllStyles();
        /* Enable the default style sheet */
        document.styleSheets[currentStyeSheet].disabled = false;
    };


    $('#selectstyle_1').click(function() {
        SetStyle(0);
    });
    $('#selectstyle_2').click(function() {
        SetStyle(1);
    });
    $('#selectstyle_3').click(function() {
        SetStyle(2);
    });
    $('#selectstyle_4').click(function() {
        SetStyle(3);
    });
    $('#selectstyle_5').click(function() {
        SetStyle(4);
        document.styleSheets[5].disabled = true;
    });

});
////////////////////////////////////
// Other Javascription Functions //
////////////////////////////////////

function ClearAllStyles () {
		document.styleSheets[0].disabled = true;
		document.styleSheets[1].disabled = true;
		document.styleSheets[2].disabled = true;
		document.styleSheets[3].disabled = true;
		document.styleSheets[4].disabled = true;
}

function SetStyle (SetStyleValue) {
		//alert('Passed Value = ' + SetStyleValue);
		ClearAllStyles ();
		document.styleSheets[SetStyleValue].disabled = false;
		document.styleSheets[5].disabled = false;
		$.cookie('stylesheet',SetStyleValue);
}
