﻿/*==================================================*
A series of functions to handle cookies
-createCookie(name, value, days)
-readCookie(name)
-eraseCookie(name)
*==================================================*/

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

/*==================================================*
A series of functions to handle font resizing 
(Larger and Smaller Text)
-resizeText(multiplier) - Make the text bigger or smaller
-restoreTextSize() - On page reload restore the text to the last size that was set
-returnTextSize() - Return the text size to the "normal" text size.
*==================================================*/
 function resizeText(multiplier) {
     var fontsz = "1.0em"; //Default to 1em
     
     // Set fontsz to the cookie value if it exists
     fontsz = readCookie('aussoft_site_font_size');
     if (fontsz != null) {
         if (parseFloat(fontsz) == 0)
             fontsz = "1.0em";
     }
     else
         fontsz = "1.0em";

     //Limit how big or small it goes.
     if (multiplier > 0) {
         if (parseFloat(fontsz) < 1.4)
             fontsz = parseFloat(fontsz) + (multiplier * 0.2) + "em";
     }
     else {
         if (parseFloat(fontsz) > 0.7)
             fontsz = parseFloat(fontsz) + (multiplier * 0.2) + "em";
     }

     // Change body text size
     document.body.style.fontSize = fontsz;

     //Set a new cookie
     var myCookie = createCookie('aussoft_site_font_size', fontsz,  365); //Save for 1 year
 }

 function restoreTextSize() {
    var fontsz = "1.0em"; //Default to 1em
    
    // Set fontsz to the cookie value if it exists
    fontsz = readCookie('aussoft_site_font_size');
    if (fontsz != null) {
        if (parseFloat(fontsz) == 0)
            fontsz = "1.0em";
    }
    else
        fontsz = "1.0em";

    // Change body text size to the saved font size
    document.body.style.fontSize = fontsz;

    //Set a new cookie
     var myCookie = createCookie('aussoft_site_font_size', fontsz,  365); //Save for 1 year
 }

 function returnTextSize() {
     var fontsz = "1.0em"; //Default to 1em

     // Change body text size to the saved font size
     document.body.style.fontSize = fontsz;

     //Set a new cookie
     var myCookie = createCookie('aussoft_site_font_size', fontsz, 365); //Save for 1 year
 }
        
//function resizeText(multiplier) {
//    var c = document.getElementById("aspnetForm");
//    if (c != null) {
//
//        if (c.style.fontSize == "") {
//            c.style.fontSize = "1.0em";
//        }
//         c.style.fontSize = parseFloat(c.style.fontSize) + (multiplier * 0.2) + "em";
//     }
//} 

/*==================================================*
*==================================================*/

 //Function to animate Main Nav menu - Accordian
// $(document).ready(function () {

//     $('#sidebar li.menu_head').click(function () {
//         $(this)
//        .next("li.menu_box")
//        .slideToggle(300)
//        .siblings("li.menu_box")
//        .slideUp("slow")
//        .siblings("li.menu_box_expand")
//        .slideUp("slow");
//     });

//     $('#sidebar li.menu_head_expand').click(function () {
//         $(this)
//        .next("li.menu_box_expand")
//        .slideToggle(300)
//        .siblings("li.menu_box")
//        .slideUp("slow");
//     });

// });
 $(document).ready(function () {

     $('ul.Accordion li.menu_head').click(function () {
         $(this)
        .next("li.menu_box")
        .slideToggle(300)
        .siblings("li.menu_box")
        .slideUp("slow")
        .siblings("li.menu_box_expand")
        .slideUp("slow");
     });

     $('ul.Accordion li.menu_head_expand').click(function () {
         $(this)
        .next("li.menu_box_expand")
        .slideToggle(300)
        .siblings("li.menu_box")
        .slideUp("slow");
     });

 });
 
 //SuperFish Navigation Scripts (includes hoverIntent.js, superfish.js and supersubs.js)
 // initialise Superfish 

 $(document).ready(function () {
     $("ul.sf-menu").supersubs({
         minWidth: 12,   // minimum width of sub-menus in em units 
         maxWidth: 27,   // maximum width of sub-menus in em units 
         extraWidth: 1     // extra width can ensure lines don't sometimes turn over 
                            // due to slight rounding differences and font-family 
     }).superfish();  // call supersubs first, then superfish, so that subs are 
                        // not display:none when measuring. Call before initialising 
                     // containing tabs for same reason. 
 });

 //MegaMenu Code
 $(document).ready(function () {

     //On Hover Over
     function megaHoverOver() {
         $(this).find(".MegaMenu_Sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
         (function ($) {
             //Function to calculate total width of all ul's
             jQuery.fn.calcSubWidth = function () {
                 rowWidth = 0;
                 //Calculate row
                 $(this).find("ul").each(function () { //for each ul...
                     rowWidth += $(this).width(); //Add each ul's width together
                 });
             };
         })(jQuery);

         if ($(this).find(".row").length > 0) { //If row exists...

             var biggestRow = 0;

             $(this).find(".row").each(function () {	//for each row...
                 $(this).calcSubWidth(); //Call function to calculate width of all ul's
                 //Find biggest row
                 if (rowWidth > biggestRow) {
                     biggestRow = rowWidth;
                 }
             });

             $(this).find(".MegaMenu_Sub").css({ 'width': biggestRow }); //Set width
             $(this).find(".row:last").css({ 'margin': '0' });  //Kill last row's margin

         } else { //If row does not exist...

             $(this).calcSubWidth();  //Call function to calculate width of all ul's
             $(this).find(".MegaMenu_Sub").css({ 'width': rowWidth }); //Set Width

         }
     }
     //On Hover Out
     function megaHoverOut() {
         $(this).find(".MegaMenu_Sub").stop().fadeTo('fast', 0, function () { //Fade to 0 opactiy
             $(this).hide();  //after fading, hide it
         });
     }

     //Set custom configurations
     var config = {
         sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
         interval: 100, // number = milliseconds for onMouseOver polling interval
         over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
         timeout: 500, // number = milliseconds delay before onMouseOut
         out: megaHoverOut // function = onMouseOut callback (REQUIRED)
     };

     //Trigger functions
     $("ul.MegaMenu li .MegaMenu_Sub").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
     $("ul.MegaMenu li").hoverIntent(config); //Trigger Hover intent with custom configurations
});


 /*==================================================*
 Used when images are not being showed on the website
 and we want to stop display the images that where 
 added by the stylesheet.
 *==================================================*/
 function removeChildBackgrounds(parent) {
     var oStyle = parent.style;
     if (oStyle != null) {
         parent.style.backgroundImage = "none";
     }
     var childNodes = parent.childNodes;
     if (childNodes != null) {
         for (var i = 0; i < childNodes.length; i++) {
             removeChildBackgrounds(childNodes[i]);
         }
     }
 }

 /*==================================================*
 --Are JavaScript functions built by Dreamweaver 
 --MM_preloadImages()
 --MM_swapImgRestore()
 --MM_findObj(n, d)
 --MM_swapImage()
 *==================================================*/

 function MM_preloadImages() { //v3.0
     var d;
     d = document;
     if (d.images) {
         if (!d.MM_p)
             d.MM_p = new Array();
         var i, j, a;
         j = d.MM_p.length;
         a = MM_preloadImages.arguments;
         for (i = 0; i < a.length; i++)
             if (a[i].indexOf("#") != 0) {
                 d.MM_p[j] = new Image;
                 d.MM_p[j++].src = a[i];
             }
     }
 }

 function MM_swapImgRestore() { //v3.0
     var i, x, a;
     a = document.MM_sr;
     for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
         x.src = x.oSrc;
 }

 function MM_findObj(n, d) { //v4.01
     var p, i, x;
     if (!d)
         d = document;
     if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
         d = parent.frames[n.substring(p + 1)].document;
         n = n.substring(0, p);
     }
     if (!(x = d[n]) && d.all)
         x = d.all[n];
     for (i = 0; !x && i < d.forms.length; i++)
         x = d.forms[i][n];
     for (i = 0; !x && d.layers && i < d.layers.length; i++)
         x = MM_findObj(n, d.layers[i].document);
     if (!x && d.getElementById)
         x = d.getElementById(n);
     return x;
 }

 function MM_swapImage() { //v3.0
     var i, j, x, a;
     j = 0;
     a = MM_swapImage.arguments;
     document.MM_sr = new Array;
     for (i = 0; i < (a.length - 2); i += 3)
         if ((x = MM_findObj(a[i])) != null) {
             document.MM_sr[j++] = x;
             if (!x.oSrc)
                 x.oSrc = x.src;
             x.src = a[i + 2];
         }
 }

/*==================================================*

*==================================================*/
