	
	/*
	JS
	--------------------------------------------------------------------------------------------  
	@site				sho.com (v5)
	@file				Utils.js
	@author			dpaul
	@modified		01.07.09
	@desc				Warehouse for misc utility functions: canvas area, browser type, cookies etc.
	@note				Cookie handling  courtesy http://www.quirksmode.org/js/cookies.html
	@depend		Prototype
	
	/* =:Utils
	-------------------------------------------------------------------------------------------- */  
	if( SHO == undefined ) var SHO = {};
	SHO.Utils = function()
	{	
		var _ISIE7;
		var _ISIE6;
		var _ISIE;
		
		/* =:Document
		  -----------------------------------------------------------------------------------------*/  
		function getPageSize()
		{
			// lifted from Lokesh Dhakar's lightbox
			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;
			}
	
			return [pageWidth,pageHeight];
		}
		
		function fixHeights ( selec )
		{
			var tallest = 0;
			$$(selec).each(function(e){
				var h = e.getHeight(); 
				tallest = h > tallest ? h : tallest;
			});
			
			$$(selec).each(function(e){
				e.setStyle({ height: tallest+'px'});
			});
		}
		

		/* =:Browser
		  -----------------------------------------------------------------------------------------*/  
		function isIE7()
		{
			if( _ISIE7 == undefined ){
				_ISIE7 = navigator.userAgent.indexOf( 'MSIE 7.0' ) !== -1 ? true : false; }
			return _ISIE7;
		}
		
		function isIE6()
		{
			if( _ISIE6 == undefined ){
				_ISIE6 = navigator.userAgent.indexOf( 'MSIE 6.0' ) !== -1 ? true : false; }
			return _ISIE6;
		}
		
		function isIE()
		{
			if( _ISIE == undefined ){
				_ISIE = navigator.userAgent.indexOf( 'MSIE' ) !== -1 ? true : false; }
			return _ISIE;
		}


		/* =:Cookies
		  -----------------------------------------------------------------------------------------*/  
		function createCookie(name,value,days)
		{
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		}
		
		function readCookie(name)
		{
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		}
		
		function eraseCookie(name)
		{
			createCookie(name,"",-1);
		}

		/* =:Reveal Public Methods
		  -----------------------------------------------------------------------------------------*/  
		return {
			getPageSize:getPageSize,
			fixHeights:fixHeights,
			
			isIE7:isIE7,
			isIE6:isIE6,
			isIE:isIE,
			
			readCookie:readCookie,
			createCookie:createCookie,
			writeCookie:createCookie,
			eraseCookie:eraseCookie
		}
	
	}();
	
