/*
* ECU Website Main Javascript Library
* Scott Hall [Squiz.net.au]
* February 2009
* 
* Modification history:
* 
* 2009-11-27: Scott Hall
*             - Reassigned jQuery alias $ to use jQuery to avoid prototype conflicts
* 2009-11-13: Scott Hall
*             - Updated page info pop up function
* 2009-11-11: Scott Hall
*             - Updated to new formatting
*             - Removed login condition to remove pop up link, now controlled via login and simple edit css.
* 2010-04-16: Andrew Dunbar
*             - Updated floated image width checker to look for image in div first.
* 2010-11-11: Scott Hall
*             - Pop up link in footer now appends query string params using jQuery.
*             - Left nav indicator arrows now displayed with jQuery instead of CSS.
*             - Add host notice function added.
*             - Section heading adjusted added to compenstate for long titles.
* 2011-02-24: Scott Hall
*             - Social Circle button appended to left nav.
* 2011-02-28: Scott Hall
*             - JS Lint 100% validated. Errors and problems cleaned up and corrected from prior versions.
* 2011-03-01: Scott Hall
*             - Main and txt pref files combined to reduce server requests and cleaned up to pass 100% jslint QA.
* 2011-03-28: Scott Hall
*             - New global attach events function for form elements added.
* 2011-04-06: Scott Hall
*             - Cleanup of addQaSystem function and asset id keyword fix.
* 2011-04-08: Andrew Dunbar
*             - Added final QA Review system code for version 1.0
* 2011-09-26: Andrew Dunbar
*             - Added new related-content / h2 div structure code
*             - Added removal of empty related content divs, 453, 601, 836
* 2011-10-19: Casey Farrell
*             - Added "Time in Perth" functionality
*
*/

/* --------------------------------------------------------------------------------------------- 
START: GLOBAL SCOPE VARIABLES
--------------------------------------------------------------------------------------------- */

// We know global vars are bad, but these are required for legacy support.

// Creates new jQuery alias to avoid conflict with other JS libraries that may use '$' like prototype.
// Any jQuery coded after this point should use the '$j' or 'jQuery' alias.

var $j = jQuery.noConflict();

// Text resize and user preference vars.

var fontSizes = [];
fontSizes[0] = "0.85em";
fontSizes[1] = "0.95em";
fontSizes[2] = "1.0em";
fontSizes[3] = "1.1em";
fontSizes[4] = "1.2em";

var themeNormal='normal';
var themeContrast='contrast';
var themeNone='none';

var searchAskUs='askus';
var searchCourses='courses';
var searchStaff='staff';
var searchWebsite='website';

var savedFontSize = jQuery.cookie('curFontSize');
var savedTheme = jQuery.cookie('curTheme');
var savedSearch = jQuery.cookie('curSearch');
var savedFontIndex = null;

var qa_websiteID = '';

/* --------------------------------------------------------------------------------------------- 
END: GLOBAL SCOPE VARIABLES
--------------------------------------------------------------------------------------------- */


/* --------------------------------------------------------------------------------------------- 
START: GLOBAL SCOPE FUNCTIONS
--------------------------------------------------------------------------------------------- */

/**
 * GLOBAL USE
 * Add social circle join button to end of left nav.
 */
function addSocialCircleButton() {
    var $leftNav = jQuery('#nav-local');
    var newHTML =
        '<div id="join-social-circle">' +
            '<a href="http://www.ecu.edu.au/social-circle/overview" target="_blank">Join our social circle</a>' +
        '</div>';
    jQuery('body').addClass('with-social-button');
    $leftNav.after(newHTML);
} // End addSocialCircleButton().


/**
 * GLOBAL USE
 * Adjust section headings for rare cases that wrap.
 */
function adjustSectionHeading() {
    var $sectionTitle = jQuery('#header h1.section-title');
    var headingHeight = $sectionTitle.height();
    // Normally about 32 pixels but give it a little more to compensate for cross browsers.
    if(headingHeight > 40){
        $sectionTitle.addClass('longTitle');
    }
} // End adjustSectionHeading().


/**
 * GLOBAL USE
 * Dynamically place domain notices at top of design based on domain 'map'.
 * For example, this will generate a notice at the top of the browser indicating you are in QA.
 */
function addHostNotice() {
    var myHost = location.hostname;
    // Dont place comma on last JSON property.
    var hostMap = {
        "wwwdev.ecu.edu.au":"ECU Web CMS QA",
        "www.example.com":"Example Message"
    };
    var key;
    for(key in hostMap){
        if (hostMap.hasOwnProperty(key)) {
            if(key === myHost){
                jQuery('body').prepend('<div id="ecuHostNotice">'+hostMap[key]+'</div>');
            }
        }
    }
} // End addHostNotice().

/**
 * GLOBAL USE
 * Dynamically place QAReview system at top of pages that are under review
 * For example, this will generate a notice at the top of the browser indicating you can leave QA reviews for this page.
 */
function addQAReviewSystem() {

    var myHost = location.hostname + location.pathname;
    var mySrc = (("https:" === document.location.protocol) ? "https://" : "http://");

    var hostMap = {
        //"www.ecu.edu.au/faculties/computing-health-and-science": "FCHS",
        //"www.ecu.edu.au/schools/computer-and-security-science": "FCHS",
        //"www.ecu.edu.au/schools/engineering": "FCHS",
        //"www.ecu.edu.au/schools/exercise-biomedical-and-health-sciences": "FCHS",
        //"www.ecu.edu.au/schools/natural-sciences": "FCHS",
        //"www.ecu.edu.au/schools/nursing-midwifery-and-postgraduate-medicine": "FCHS",
        //"www.ecu.edu.au/schools/psychology-and-social-science": "FCHS",
        //"www.ecu.edu.au/centres/learning-and-development": "CLD",
        //"intranet.ecu.edu.au/staff/centres/learning-and-development": "CLDIntranet",
        //"intranet.ecu.edu.au/learning": "CLDLearning",
        //"www.ecu.edu.au/centres/facilities-and-services": "FAS",
        //"intranet.ecu.edu.au/staff/centres/facilities-and-services": "FASIntranet",
        //"www.ecu.edu.au/faculties/education-and-arts": "FEA",
	//"www.ecu.edu.au/schools/communications-and-arts": "SCA",
	//"www.ecu.edu.au/schools/education": "ED",
        //"www.ecu.edu.au/testing/": "TESTING",  
//"www.ecu.edu.au/centres/planning-quality-and-equity-services": "PQESC",  
//"intranet.ecu.edu.au/staff/centres/planning-quality-and-equity-services": "PQESCIntranet",
"www.ecu.edu.au/centres/office-of-academic-governance": "OAG",
"intranet.ecu.edu.au/staff/centres/office-of-academic-governance": "OAGIntranet"
};

    function addToolbar() {

		// Load CSS
		var cssURL = mySrc + 'www.ecu.edu.au/_media/javascript/common/qa-comments-system/qacheck.css';
		jQuery('head').append('<link rel="stylesheet" type="text/css" href="'+cssURL+'" media="screen" />');    

        var toolbarHTML =
            '<div id="ees_toolBar" style="height:38px; overflow:hidden">' +
                '<div id="ees_toolBarLogo">' +
                    '<strong>QA Check - Business Owner Review</strong>' +
                '</div>' +
                '<div id="ees_modeSwitcher">' +
                    '<ul>' +
                        '<li>' +
                            '<a href="#" class="show-review-info">Current Comments ( <span id="ecuHostNoticeExisting">0</span> )</a>' +
                        '</li>' +
                        '<li>' +
                            '<a href="#" class="show-review-info">Leave Comment </a>' +
                        '</li>' +
                    '</ul>' +
                '</div>' +
            '</div>';
            
        jQuery('body').prepend(toolbarHTML);
        
        // Get current page asset id.
        var bodyClasses = jQuery('body').attr('class').split(' ');
        var assetId = bodyClasses[0].replace('asset-id_', '');
        
        // Dynamically get any comments existing on this page
        jQuery.ajax({
            url: mySrc + 'www.ecu.edu.au/apps/WebQAReview/qa-review.php?action=getCount&theAssetID=' + assetId,
            type: 'GET',
            success: function (data) {
                jQuery('#ecuHostNoticeExisting').html(data);
            }
        });
        
    } // End addToolbar.
    
    var key;
    for (key in hostMap) {
        if (hostMap.hasOwnProperty(key)) {
            var searchURL = new RegExp(key);
            if (searchURL.test(myHost)) {
                
                // Global var for qaSystem - we'll get rid of this from global namespace later.
                qa_websiteID = hostMap[key];
                
                addToolbar();
                
            }
        }
    } // End for.
    
} // End addQAReviewSystem().

/**
 * GLOBAL USE
 * Detects presence of direct sub uls of top level li's
 * and adds indicator arrow class, will hide/show depending on level of view.
 * Design generates sub nav markup but is initially removed from portal view using CSS.
 */
function indicateLeftNavSubs() {

    var $menuItemSubs = jQuery('#nav-local ul > li > ul');

    $menuItemSubs.each(function (index) {
        var $self = jQuery(this);
        var $parentLink = $self.prev();
        if ($parentLink.hasClass('current') || $parentLink.hasClass('hierarchy')) {
            $self.removeClass('remove-from-view');
            // Some legacy stuff from the main ECU site we need to help with current/heirarchy view.
            $parentLink.addClass("parent-with-subs");
        } else {
            $parentLink.addClass('hasSubs').addClass('parent-with-subs');
            $self.addClass('remove-from-view');
        }
    }); // End each.
    
} // End indicateLeftNavSubs.


/**
 * GLOBAL USE
 * Get logged in cookie using cookie plugin and generate portal links.
 */
function showPortalLogin() {
 
    // set to 1 for testing only
    // jQuery.cookie('ecu_portal', 1, { path: '/' });
    var portalLoggedIn = jQuery.cookie('ecu_portal');
    if (portalLoggedIn === '1') {
        var newHTML = 
            '<p>Signed into ' + 
                '<a href="https://portal.ecu.edu.au">Portal</a> | ' +
                '<a href="https://sso.ecu.edu.au/pls/orasso/orasso.wwsso_app_admin.ls_logout?p_done_url=http%3A%2F%2Fwww.ecu.edu.au">Logout</a>' +
            '</p>';
        jQuery("#portal-links").html(newHTML);
    }
    
} // End showPortalLogin.


/**
 * GLOBAL USE
 *
 */
function pageInfoPopUp() {
 
    // show page info pop up
    jQuery('a.show-page-info').click(function () {
        var documentWidth = jQuery(document).width();
        var windowHeight = jQuery(window).height();
        var popupWidth = 496;
        var popupHeight = 650;
        var posTop = windowHeight / 2 - popupHeight / 2;
        var posLeft = documentWidth / 2 - popupWidth / 2;
        var myURL = location.protocol + '//' + location.hostname + location.pathname;
        if (!myURL.match('_nocache')) {
            myURL += '/_nocache';
        }
        var queryString = 'SQ_DESIGN_NAME=body-only&SQ_PAINT_LAYOUT_NAME=page-info';
        newWindow = window.open(myURL + '?' + queryString, "mywindow", "location=0,status=0,scrollbars=1,width=" + popupWidth + ",height=" + popupHeight + ",left=" + posLeft + ",top=" + posTop);
        return false;
    }); // End click.
    
} // End pageInfoPopUp.

/**
 * GLOBAL USE
 *
 */
function qaReviewPopUp() {

    // show page info pop up
    jQuery('a.show-review-info').click(function () {
        var documentWidth = jQuery(document).width();
        var windowHeight = jQuery(window).height();
        var popupWidth = 920;
        var popupHeight = 720;
        var posTop = windowHeight / 2 - popupHeight / 2;
        var posLeft = documentWidth / 2 - popupWidth / 2;
        var myURL = location.protocol + '//' + location.hostname + location.pathname;
        if (!myURL.match('_nocache')) {
            myURL += '/_nocache';
        }
        var queryString = 'SQ_DESIGN_NAME=body-only&SQ_PAINT_LAYOUT_NAME=page-review&theWebsiteID='+qa_websiteID;
        newWindow = window.open(myURL + '?' + queryString, "mywindow", "menubar=0,toolbar=0,location=0,status=0,scrollbars=1,width=" + popupWidth + ",height=" + popupHeight + ",left=" + posLeft + ",top=" + posTop);
        return false;
    }); // End click.
    
} // End qaReviewPopUp.

/**
 * GLOBAL USE
 * Remove token from string.
 */
function removeTokenFromString(s, t) {
    s = String(s);
    var i = s.indexOf(t);
    var r = "";
    if (i === -1) {
        return s;
    }
    r += s.substring(0, i) + removeTokenFromString(s.substring(i + t.length), t);
    return r;
} // End removeTokenFromString.


/**
 * GLOBAL USE
 * Get index of value in array.
 */
function getIndex(varArray, varValue) {
    var i;
    for (i = 0; i < varArray.length; i++) {
        if (varArray[i] === varValue) {
            return i;
        }
    }
} // End getIndex.


/**
 * GLOBAL USE
 * Read a page's GET URL variables and return them as an associative array.
 * Example - var urlHash = getUrlVars(); alert(urlHash['hello']);.
 */
function getUrlVars() {
    var vars = [], hash, i;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
} // End getUrlVars.


/**
 * GLOBAL USE
 * Left and right trim.
 */
function trim(str) {
    str = String(str);
    return str.replace(/^\s+|\s+$/g, "");
} // End trim.


/**
 * GLOBAL USE
 * Fix some content issues dynamically.
 */
function contentFixes() {
 
    // ie6 and Firefox 3 on blur fix
    jQuery("#searchbox").focus(function () {
        if (this.value === this.defaultValue) {
            this.value = "";
        }
    }).blur(function () {
        if (!this.value.length) {
            this.value = this.defaultValue;
        }
    }); // End blur.

    // fix breadcrumb trail if displays last greater than char
    if (jQuery("#breadcrumb-links").length > 0) {
        var linkHTML = jQuery("#breadcrumb-links").html();
        var trimmedHTML = trim(linkHTML);
        var lastChar = trimmedHTML.charAt(trimmedHTML.length - 1);
        var newHTML = '';
        if (lastChar === ";") {
            newHTML = trimmedHTML.substring(0, trimmedHTML.lastIndexOf("&gt;"));
            jQuery("#breadcrumb-links").html(newHTML);
        }
        // for safari
        if (lastChar === ">") {
            newHTML = trimmedHTML.substring(0, trimmedHTML.lastIndexOf(">"));
            jQuery("#breadcrumb-links").html(newHTML);
        }
    }

    // fix the width of the floated image area container based on image size for '601'
    if (jQuery("#floated-image-area img").length !== 0) {
        var imgWidth = jQuery("#floated-image-area img:first-child").width();
        jQuery("#floated-image-area").width(imgWidth);
    }

    // remove 'related-content' '453' div if nothing in it */
    if (jQuery("#related-content").children().size() === 0) {  
      jQuery("#related-content").remove();
      // set the width of the content back to normal
      jQuery("#content-with-related").width("697px");
    }

    // remove 'related-content' '601' div if nothing in it */
    if (jQuery("#related-content-wrapped").children().size() === 0) {
      jQuery("#related-content-wrapped").remove();
    }   

    // remove '601' floated image from content if nothing in it */
    if (jQuery("#floated-image-area").children().size() === 0) {
      jQuery("#floated-image-area").remove();
    }

	// move h2 heading outside of content structure to allow for longer headings,
	// effectively means related-content now sits with actual content better.
    if (jQuery("#content-main #content-with-related h2").length > 0) {
        // move h2 to correct location for '453'
        jQuery('#skip-to-content').after(jQuery("#content-main #content-with-related h2"));
    } else if (jQuery("#content-main h2").not("#related-content-wrapped h2").length > 0) {
        // move h2 to correct location for '601'
        jQuery('#skip-to-content').after(jQuery("#content-main h2").not("#related-content-wrapped h2, #full-story-contents h2, #portalLoginContainer h2")); 
    }

    // add 'content-title' to h2 if not already attached for both '453' and '601'
    if (!jQuery("#content-main h2:first").hasClass("content-title")) {
        jQuery("#content-main h2:first").addClass("content-title");
        
    }

} // End contentFixes.


/**
 * GLOBAL USE
 * Dynamically submit the search website remote form.
 */
function submitSearch(){
    
    // Only submit if there are no children of cse-search-results
    if (jQuery("form.remote-search-website").length > 0 && jQuery("#cse-search-results").length > 0) {
        if (jQuery("#cse-search-results").children().length < 1) {
            jQuery("form.remote-search-website").submit();
        }
    }
	
} // End submitSearch.


/**
 * GLOBAL USE
 * Dynamically attach form events/event actions and styling based on user interaction.
 * Enhance user feedback for basic element interaction.
 */
function attachFormEvents(){
    
    var $contentContainer = jQuery('#content');
    
    // Provide visual feedback for when user clicks submit button.
    $contentContainer.find('input[type=submit]').click( function(){
        jQuery(this).addClass('buttonClicked');
    });
	
} // End attachFormEvents.

/**
 * GLOBAL USE
 * Gets current time in Perth and prints to #PerthTimeContainer where
 * the element exists
 */
function showPerthTime(){
  if(jQuery('#PerthTimeContainer').length>0){
    jQuery('#PerthTimeContainer').addClass('loading');
    jQuery.getJSON("https://webservices.web.ecu.edu.au/tools/time.php?callback=?", function(data) {
      //jQuery('#PerthTimeContainer').text('Time in Perth: '+data.hour24+':'+data.minute);
      jQuery('#PerthTimeContainer').text('Time in Perth: '+data.friendly);      
      jQuery('#PerthTimeContainer').removeClass('loading');
    });
  }
} // End showPerthTime


/**
 * USER PREFERENCE
 * Set font size.
 */
function setFontSize(selectedSize){
    
	jQuery('html').css('font-size', selectedSize);
	// Only save cookie with 30 day expiry when preferences are saved
	// See save click function later on
	jQuery.cookie('curFontSize', selectedSize, { path: '/', domain: 'ecu.edu.au' });
	savedFontSize = jQuery.cookie('curFontSize');
	
} // End setFontSize.


/**
 * USER PREFERENCE
 * Set search.
 */
function setSearch(selectedSearch){
    
        jQuery("#cse-search-box input#tab").val(selectedSearch);
        
} // End setSearch.

/**
 * USER PREFERENCE
 * Set theme.
 */
function setTheme(selectedTheme){
    
	switch(selectedTheme){
		case themeNormal:
			jQuery("link#h-contrast").attr('disabled', true); /*safari fix*/
			jQuery("link#h-contrast").remove();
			jQuery("link[rel*='stylesheet']").each(function(i){
				this.disabled = false;
			});
			break;
		case themeContrast:
			jQuery("link[rel*='stylesheet']").each(function(i){
				this.disabled = false;
			});
			var contStyleSource = "./?a=1813";
			jQuery("head").append('<link id="h-contrast" rel="stylesheet" type="text/css" href='+'"'+contStyleSource+'"'+' media="all" />');
			break;
		case themeNone:
			jQuery("link[rel*='stylesheet']").each(function(i){
				this.disabled = true;
			});
			jQuery("link#h-contrast").remove();
			jQuery("#search-site").next().remove();
			break;
	}
	
} // End setTheme.

/**
 * USER PREFERENCE
 * Change font size.
 */
function changeFontSize(direction){
    
	var fontIndex = getIndex(fontSizes, savedFontSize);
	var fontArrayLength = fontSizes.length;
	if((direction==="up") && (fontIndex < fontArrayLength)){
		fontIndex++;
	}
	if((direction==="down") && (fontIndex > 0)){
		fontIndex--;
	}
	setFontSize(fontSizes[fontIndex]);
	jQuery("#website-preferences input:radio[value='"+fontIndex+"']").attr('checked', true);
	
} // End changeFontSize.


/**
 * USER PREFERENCE
 * Clean up anchor URLs.
 */
function removeAnchors(varURL){
    
    varURL = removeTokenFromString(varURL,'#top-page');
    varURL = removeTokenFromString(varURL,'#change-website-preferences');
	return varURL;
    
} // End removeAnchors.


/**
 * USER PREFERENCE
 * Display selected radio theme.
 */
function displayRadioCheckedTheme(checkedValue){
    
    var docLocation = document.location.href;
    switch(checkedValue){
        case 'normal':
            jQuery("body").fadeOut(1000, function () {
                setTheme(themeNormal);
                docLocation = removeAnchors(docLocation);
                document.location.href = docLocation + '#top-page';
            });
            jQuery("body").fadeIn(1000);
            break;
        case 'contrast':
            jQuery("body").fadeOut(1000, function () {
                setTheme(themeContrast);
                docLocation = removeAnchors(docLocation);
                document.location.href = docLocation + '#top-page';
            });
            jQuery("body").fadeIn(1000);
            break;
        case 'none':
            jQuery("body").fadeOut(1000, function () {
                setTheme(themeNone);
                docLocation = removeAnchors(docLocation);			
                document.location.href = docLocation + '#change-website-preferences';
                jQuery("#save-preferences span").css('visibility','hidden');
            });
            jQuery("body").fadeIn(1000);
            break;
    }
    
} // End displayRadioCheckedTheme.


/**
 * USER PREFERENCE
 * Preference actions requiring DOM ready call.
 */
function domReadyDoPreferences(checkedValue){

    setSearch(savedSearch);

	// remove tagged header images when in theme none
	if(savedTheme === "none"){
		jQuery("#custom-header-image").css("display","none");
	}

	// pre check the preference page form radio buttons using saved values
	jQuery("#website-preferences input:radio[value='"+savedFontIndex+"']").attr('checked', true);
	jQuery("#website-preferences input:radio[value='"+savedTheme+"']").attr('checked', true);
	jQuery("#website-preferences input:radio[value='"+savedSearch+"']").attr('checked', true);

	jQuery(".decrease-font-size").click(function(event){
		changeFontSize("down");
		event.preventDefault();
	}); // End click.
	
	jQuery(".increase-font-size").click(function(event){
		changeFontSize("up");
		event.preventDefault();
	}); // End click.
				   
	jQuery("input[name='pref-text-size']").click(function(){
		var checkedValue = String(jQuery("input[name='pref-text-size']:checked").val());
		if (checkedValue){
			setFontSize(fontSizes[checkedValue]);
		}
	});// End click.
	
	jQuery("input[name='pref-style']").click(function(){
		var checkedValue = String(jQuery("input[name='pref-style']:checked").val());
		if (checkedValue){
			displayRadioCheckedTheme(checkedValue);
		}
	}); // End click.
	
	jQuery("input[name='pref-search']").click(function(){
		var checkedValue = String(jQuery("input[name='pref-search']:checked").val());
		if (checkedValue){
			setSearch(checkedValue);
		}
	}); // End click.
	
	jQuery("#website-preferences input:radio").click(function(){
		jQuery("#saved-success").removeClass("show");
	}); // End click.
	
	// Save selected preferences
	jQuery("#website-preferences #save-button").click(function(event){
																			
		if(jQuery("input[name='pref-style']:checked").val()===themeNone){
			jQuery("#save-preferences span").css('visibility','hidden');
		}else{
			jQuery("#save-preferences span").css('visibility','visible');
		}
		
		var curRadioTheme = String(jQuery("input[name='pref-style']:checked").val());
		jQuery.cookie('curTheme', curRadioTheme, { expires: 30, path: '/', domain: 'ecu.edu.au' });
		savedTheme = jQuery.cookie('curTheme');
		
		var curRadioSearch = String(jQuery("input[name='pref-search']:checked").val());
		jQuery.cookie('curSearch', curRadioSearch, { expires: 30, path: '/', domain: 'ecu.edu.au'});
		savedSearch = jQuery.cookie('curSearch');
		
		jQuery.cookie('curFontSize', savedFontSize, { expires: 30, path: '/', domain: 'ecu.edu.au' });
		
		jQuery("#website-preferences input:radio").attr('disabled', true);
		jQuery("#website-preferences #save-button").attr('disabled', true);	
		jQuery("#saved-success").removeClass("show");
		jQuery("#saved-feedback").addClass("show");
		
		jQuery("#saved-feedback img").fadeOut(0).fadeIn(4000, function () {																			  
			jQuery("#saved-feedback").removeClass("show");
			jQuery("#saved-success").addClass("show").fadeOut(0).fadeIn(1000);
			jQuery("#website-preferences input:radio").attr('disabled', false);
			jQuery("#website-preferences #save-button").attr('disabled', false);		
		});
		
	}); // End click.
    
} // End domReadyDoPreferences.

// Set all preferences before full DOM load.
if(savedFontSize===null){
	setFontSize(fontSizes[2]);
	savedFontIndex = 2;
}else{
	setFontSize(savedFontSize);
	savedFontIndex = getIndex(fontSizes, savedFontSize);
}

if(savedTheme===null){
	savedTheme = themeNormal;
	setTheme(themeNormal);
}else{
	setTheme(savedTheme);
}

if(savedSearch===null){
	savedSearch = searchWebsite;
}


/* --------------------------------------------------------------------------------------------- 
END: GLOBAL SCOPE FUNCTIONS
--------------------------------------------------------------------------------------------- */


/* --------------------------------------------------------------------------------------------- 
START: DO WHEN DOM IS READY
--------------------------------------------------------------------------------------------- */

jQuery(document).ready(function () {

    // Global DOM ready dependant.
    indicateLeftNavSubs();
    addSocialCircleButton();
    addHostNotice();
    adjustSectionHeading();
    showPortalLogin();
    contentFixes();
    pageInfoPopUp();
    // Get rid of toolbar added by global script versions of below functions.
    jQuery('#ees_toolBar').remove();   
    addQAReviewSystem();
    qaReviewPopUp();
    attachFormEvents();

    // Text resize and user preferences DOM ready dependant.
    domReadyDoPreferences();

    // Perth Time
    showPerthTime();
    setInterval("showPerthTime()", 60000);

}); // End DOM is ready.

/* --------------------------------------------------------------------------------------------- 
END: DO WHEN DOM IS READY
--------------------------------------------------------------------------------------------- */

