function Init(){
	if (typeof load == 'function'){
		load();
	}
	
	FixImages();
}

function CleanUp(){
	if (typeof GUnload == 'function'){
		GUnload();
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Fix Images
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function FixImages(){
	return;
	var classArray = Array('imageRight','imageLeft','imageTop');

	for (var i = 0; i < classArray.length; i++){
		var divNodes = getElementsByClass(classArray[i],null,'div')
		for (var j = 0; j < divNodes.length; j++){
			var divNode = divNodes[j];
			var divWidth = '100px';

			var imageNodes = divNode.getElementsByTagName('img');

			for ( k = 0; k < imageNodes.length; k++){
				if (parseInt(imageNodes[k].width) > parseInt(divWidth)){
					divWidth = imageNodes[k].width;
				}
			}

			divNode.style.width = parseInt(divWidth) + 'px';
		}
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null ){
		node = document;
	}

	if ( tag == null ){
		tag = '*';
	}

	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Banner slideshow in General content page
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




var containerHeight = '113px';
var speed = 5000;
var type = 'sequence';

$(document).ready(function(){
  if($('#slideshowBanner').length > 0){
    
    $('ul#bannerImageSlide').innerfade({
      speed: speed,
      timeout: 8000,
      type: type,
      containerheight: containerHeight
    });
  }
});

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// media Index: iamge gallery and movie lightbox
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//
// Entry point for starting up a photo gallery from the media index template.
// 
function StartGallery(galleryGroupId){
  var element = document.getElementById("gallery_" + galleryGroupId);
    
  if(element){
   // $('#'+ element.id + ' a').lightBox({fixedNavigation:true});
    $(element).find('a:first').click();
   }
}

var player;

function playerReady(obj) {
	var id = obj['id'];
	var version = obj['version'];
	var client = obj['client'];
	player = document.getElementById(id);
}

 function OpenMovie(){
  var pageSizeArray = GetPageSize();
    				  
    $('#video-overlay').css({
		  backgroundColor:	'#96c081',
		  opacity:			0.8,
		  width:				pageSizeArray[0],
		  height:				pageSizeArray[1]
	  }).fadeIn();
  	
	  $('#video-lightbox').show();  
 }
	    
 function CloseMovie(){
	 $('#video-lightbox').hide();
	$('#video-overlay').fadeOut();
 
 }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Page Events
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

window.onload = Init;
window.onunload = CleanUp;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Utils
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function GetPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

