var iBodyOriginalSize = 0;
var sLowVisionCookieValue = 'lowvision';
var sStandardVisionCookieValue = 'standardvision';

function prepGoogleMaps(sDivID){
	var iLat = 0;
	var iLong = 0;
	var iZoom = 14;
	if (document.getElementById(sDivID) != null){
		// Load the map
		loadGoogleMaps(sDivID, iLat, iLong, iZoom);

		// Register the unload function
		$(window).unload( function () { GUnload(); } );
	}
}

function loadGoogleMaps(sDivID, iLat, iLong, iZoom){
	if (GBrowserIsCompatible()) {
		var gMap = new GMap2(document.getElementById(sDivID));
		var icon = new GIcon();
		var sPointHTML = '<p>Cork College Of Commerce</p>';
		var marker;

		point = new GLatLng(iLat,iLong);
		marker = createMarker(point,sPointHTML);

		gMap.addControl(new GSmallMapControl());
		gMap.addControl(new GMapTypeControl());
		gMap.setCenter(new GLatLng(iLat, iLong), iZoom);
		gMap.addOverlay(marker);
	}
}

function createMarker(point,html){
	var oMarker = new GMarker(point);
	GEvent.addListener(oMarker, "click", function() {
	oMarker.openInfoWindowHtml(html);});
	return oMarker;
}

function hideElement(sElementID){
	var oElement = document.getElementById(sElementID);
	if (oElement != null){
		oElement.style.display = 'none';
	}
}
function showElement(sElementID){
	var oElement = document.getElementById(sElementID);
	if (oElement != null){
		oElement.style.display = '';
	}
}

function enterHeaderNav(oElement){
	$(oElement).attr('src', '/template/images/HeaderNavOn.png');
}
function exitHeaderNav(oElement){
	$(oElement).attr('src', '/template/images/HeaderNavOff.png');
}
function PageOnLoad(){
	//TODO: Check the vision set
	if (getVisionTemplateCookie() == sLowVisionCookieValue){
		setLowVision();
	}else{
		setStandardVision();
	}
	prepareScreen();
	fixIEPNG();
}
function prepareScreen(){
	var iDocHeight = $(document).height();
	var iNewBodyHeight = 0;
	iNewBodyHeight = iDocHeight - ($('#dvPageHeader').height() + $('#dvFooter').height()) - 8;
	if (iNewBodyHeight > $('#dvPageBody').height()){
		$('#dvPageBody').height(iNewBodyHeight);
	}
}

function setLowVision(){
	//alert('Load low vision template');
	hideElement('lnkLowVision');
	showElement('lnkStandardVision')
	setLowVisTemplateStatus(true);
	setVisionTemplateCookie(sLowVisionCookieValue);
}
function setStandardVision(){
	//alert('Load standard vision template');
	hideElement('lnkStandardVision');
	showElement('lnkLowVision');
	setLowVisTemplateStatus(false);
	setVisionTemplateCookie(sStandardVisionCookieValue);
}


function setLowVisTemplateStatus(bEnabled){
	var oLinkElements = $('link');
	var bElementFound = false;
	for (i=0;i<oLinkElements.length;i=i+1){
		if (oLinkElements[i].title == 'LowVisTemplate'){
			oLinkElements[i].disabled = !bEnabled;
			bElementFound = true;
		}
	}
	if (!bElementFound && bEnabled){
		$('head').append('<link rel="stylesheet" type="text/css" title="LowVisTemplate" media="screen" href="/template/css/lowvision.css" />');
	}
}


function setVisionTemplateCookie(sValue){
	$.cookie('VISION_TEMPLATE', sValue, {expires:365});
}
function getVisionTemplateCookie(){
	return $.cookie('VISION_TEMPLATE');
}
function fixCourseResourceIcons(){
    $('.CourseResourceIcon').each( function() {
    	var oElement = this;
		var sImgSrc = $(oElement).attr('src');
		var sImgFilter = $(oElement).css('filter');
		$(oElement).css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sImgSrc + "', sizingMethod='scale')");
    });
}

function doPrint(){
	window.print();
	return false;	
}

function popupEmailCourse(sC){
	popupWin('/cf/emailtofriend.cfm?c='+sC,650,290);
}
function popupWin(sURL, iWidth, iHeight) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(sURL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + iWidth + ",height=" + iHeight + "');");
}
function fixIEPNG(){
	//$(document).pngFix();
	//$('div.clsHeaderFeaturedItem').pngFix();
}