//
// common.js -- common javascipt functions used throughout the website
// Written by Jon Burney (e4education)
// Copyright 2007 Bluestone New Media Ltd (e4education)
//


//  function:  addLoadEvent
//  arguments:  func - the name of the function to attach
//  return: none
//  desc: Attaches a function to the onload event while preserving existing onload functions
//  Credit to Simon Willison (see http://simonwillison.net/2004/May/26/addLoadEvent/ for more details)
function addLoadEvent(func) {

	var oldonload = window.onload;
	
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		
		window.onload = function() {
		
			if (oldonload) {
				oldonload();
			}
			func();
		};
	}
}

//	Function:	setUpExternalLinks()
//	Scope:		Public
//	Arguments:	N/A
//	Returns:	N/A
//	Description:	Finds all of the links on a page and checks if the rel attribute is set to 'external' if it is then it sets the DOM target to be '_blank' so 
//			the link opens in a new window
function setUpExternalLinks() {

	var elmLinks = document.getElementsByTagName("a");
	
	for (var i=0; i < elmLinks.length; i++) {
		if (elmLinks[i].rel == "external") {
			elmLinks[i].target = "_blank";
		}
	}
}


function getElementStyle(elemID, IEStyleProp, CSSStyleProp) {
    var elem = document.getElementById(elemID);
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
    return "";
}


function htmldecode( strTextData ) {
  var tmpDiv = document.createElement("DIV");
  tmpDiv.innerHTML=strTextData;
  return ((tmpDiv.innerText) ? tmpDiv.innerText : tmpDiv.textContent);
}


$(document).ready(function() {

  setUpExternalLinks();
  var elm_secureBar = $("#secureBar");
  
  if ($(elm_secureBar).size() > 0) {
    intWindowHeight = window.innerHeight;
    intBarHeight = $(elm_secureBar).height();
    intBarHeight = intBarHeight + 9;
    $("body").css("background-position", "0px " + intBarHeight+"px");
  }
});




/*
##########################################################
					START COLUMNS
##########################################################
*/
  $.fn.e4eColumnsFE = function() {
	var options = arguments[0] || {};
	options = $.extend($.e4eColumnsFE.defaults, options);
	var elem = $(this);
	$.e4eColumnsFE.construct(elem, options);
  };
  $.e4eColumnsFE = {
	  defaults:{
		  height: true,
		  width: false,
		  animate: false,
		  animateSpeed: 250
	  },
	  construct: function(elem, options){
		  if(options.animate===false){options.animateSpeed=0;}
		  if(options.height===true){
			  $.data($('body').get(0), 'topHeight', 0);
			  $(elem).each(function(){
          $(this).css({height:'auto'});
  				if($.data($('body').get(0), 'topHeight')<$(this).height()){
            $.data($('body').get(0), 'topHeight', $(this).height());
          }
			  });
			  if(options.width===false){
				  $(elem).animate({height:$.data($('body').get(0), 'topHeight')},options.animateSpeed);
			  }
		  }
		  if(options.width===true){
			  $.data($('body').get(0), 'topWidth', 0);
			  $(elem).each(function(){
  				if($.data($('body').get(0), 'topWidth')<$(this).width()){
  				  $.data($('body').get(0), 'topWidth', $(this).width());
  				}
			  });
			  if(options.height===false){
				  $(elem).animate({width:($.data($('body').get(0), 'topWidth'))},options.animateSpeed);
			  }
		  }
		  if(options.height===true && options.width===true){
			  $(elem).animate({height:($.data($('body').get(0), 'topHeight')),width:($.data($('body').get(0), 'topWidth'))},options.animateSpeed);
		  }
	  }
  };
/*
##########################################################
					 END COLUMNS
##########################################################
*/



