﻿var kDefaultColor	=	'#666';
var kInputColor		=	'#000';
var kHoverColor		=	'#FFF';
var kNormalColor	=	'#FFC';


var baseFontSize = 16;
if ($.browser.msie) { baseFontSize = 14 }

// STUFF TO DO WHEN DOCUMENT LOADS
jQuery(document).ready(function() {
	// turn on Javascript-dependent blocks
	$('div.JS_dependent').css({ display:'block'});

	// set fontSize to session cookie or base size
	// indicate larger or smaller size
	var savFontSize = $.cookie('fontSize');
	if (Boolean(savFontSize)) {
		$('html').css({ fontSize: savFontSize+"px" });
		if(savFontSize>baseFontSize) {
			$('#increaseFont').addClass('switchSelect');
		}
		else if( savFontSize < baseFontSize ) {
			$('#decreaseFont').addClass('switchSelect');
		}
	}
	else {
		$('html').css({ fontSize: baseFontSize });
	}

/* 	PopulateElement('input#searchbox', 'Search term'); */
	
	
	// BINDINGS
	
	$('.fontSwitcher').hover(
		function () {
			$(this).css({ color:kHoverColor});
		}, 
		function () {
			$(this).css({ color:kNormalColor});
		}
	);


	$('.fontSwitcher').click(function() {
		$('.fontSwitcher').removeClass('switchSelect');
		if( this.id == 'increaseFont') {
			IncreaseFontSize(); 
			$(this).addClass('switchSelect');
		}
		else if( this.id == 'decreaseFont') { 
			DecreaseFontSize();
			$(this).addClass('switchSelect');
		}
		else ResetFontSize();
		//event.stopPropagation();
	});
});


/*  */
/* function PopulateElement(selector, defvalue) { */
/* 	var t = $.trim($(selector).val()); */
/*     if($.trim($(selector).val()) == "") { */
/*         $(selector).val(defvalue); */
/*         $(selector).css({ color:kDefaultColor}); */
/*     } */
/*    */
/*     $(selector).focus(function() { */
/*         if($(selector).val() == defvalue) { */
/*            $(selector).val(""); */
/*            $(selector).css({ color: kInputColor}); */
/*         } */
/*     }); */
/*      */
/*     $(selector).blur(function() { */
/*         if($.trim($(selector).val()) == "") { */
/*             $(selector).val(defvalue); */
/*             $(selector).css({ color:kDefaultColor}); */
/*         } */
/*     }); */
/*  } */
/*  */


// PAGE MODIFIER FUNCTIONS

function PrinterFriendly(){
	$("link[media='screen']").each(
		function() { 
			var tCss = $(this).attr("href");
			var tNewCss = tCss.replace(/_screen/i, "_print");
			$(this).attr("href", tNewCss);
			$(this).attr("switched", 'true');
		});
	$("div#extra").html("<input type='button' value='Return to regular page' onclick='RegularDisplay()' style='float:right; color:#FFF; background-color:#000;'>");
/* 	$('img#ae_logo').attr("src","/media/IMG/base/ACCESS-ed_logo.png"); */
	
	return false;
};


function RegularDisplay()
{
   $("link[switched='true']").each(
	function() { 
		var tCss = $(this).attr("href");
		var tNewCss = tCss.replace(/_print/i, "_screen");
		$(this).attr("href", tNewCss);
		$(this).attr("switched", 'false');
	});
	$("div#extra").html("");
/* 	$('img#ae_logo').attr("src","/media/IMG/base/ACCESS-ed_logo_full.png"); */
	return false;
};


function IncreaseFontSize()
{
	var currentFontSize = $('html').css('font-size');
	var currentFontSizeNum = parseFloat(currentFontSize, 10);
	var newFontSize = currentFontSizeNum*1.2;
	if(newFontSize < 40 ) {
		$('html').css({ fontSize: newFontSize });
		$.cookie('fontSize', newFontSize, { path: '/' });
	}
	return false;
};

function ResetFontSize() {
	$('html').css({ fontSize: baseFontSize });
	$.cookie('fontSize', baseFontSize, { path: '/' });
	return false;
};

function DecreaseFontSize(){
	var currentFontSize = $('html').css('font-size');
	var currentFontSizeNum = parseFloat(currentFontSize, 10);
	var newFontSize = currentFontSizeNum*0.8;
	if(newFontSize > 8 ) {
		$('html').css({ fontSize: newFontSize });
		$.cookie('fontSize', newFontSize, { path: '/' });
	}
	return false;
};
