/*
* ECU Applications Main Javascript Library
* Scott Hall [Squiz.net.au]
* February 2010
* 
* Modification history:
* 
* 2010-02-03: Scott Hall
*             - File setup and formatting.
*
* 
*/

/* START jQuery 'document ready' function for generic use *************************************** */

jQuery(document).ready(function(){

	// Left nav section arrow fix.
	jQuery("#nav-local > ul > li").each(function(i){
		if (jQuery(this).children().length > 1) {
			jQuery(this).children().eq(0).addClass("parent-with-subs");
		}
	}); // End each.

	// ie6 fix for content headings
	jQuery("#content-main h2:first").addClass("content-title");

	// fix the width of the floated image area container based on image size */
	var imgWidth = jQuery("#floated-image-area img:first-child").width();
	jQuery("#floated-image-area").width(imgWidth);

	// Dynamically pull wrapped related content column up
	// by the height of the main content h2 if no floated image exists
	if(jQuery("#related-content-wrapped").length > 0 && jQuery("#floated-image-area img").length == 0){
		jQuery("#related-content-wrapped").css("margin-top", "-22px");
	}

	// 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 = 0 + windowHeight / 2 - popupHeight / 2;
		var posLeft = 0 + documentWidth / 2 - popupWidth / 2;
		newWindow = window.open(this.href,"mywindow","location=0,status=0,scrollbars=1,width="+popupWidth+",height="+popupHeight+",left="+posLeft+",top="+posTop);
		return false;
	}); // End click.
	
}); // End doc ready.

/* END jQuery 'document ready' function for generic use ***************************************** */


/* START Declaration of generic javascript functions ******************************************** */

function removeTokenFromString(s,t) {
        s = 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;
}

function getIndex(varArray, varValue){
	for(var i = 0; i < varArray.length; i++){
		if(varArray[i]==varValue){
			return i;
		}
	}
}

/* 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;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

function trim(str){
    str = str + "";
    return str.replace(/^\s+|\s+$/g,"");
}

/* END Declaration of generic javascript functions ******************************************** */
