	function switchStylestyle(styleName)
	{
		$('link[@rel*=style]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName || this.getAttribute('title') == 'grid' || this.getAttribute('title') == 'ie' ||this.getAttribute('title') == 'reset' || this.getAttribute('title') == 'fonts')  {
				this.disabled = false;
				
			} 
			
		});
		//adjustLayout()
		createCookie('style', styleName, 365);
		//
	}
	
	var adjustLayout = function () {
		//alert("adjust")
		//ph = getPageHeight()
		dh = $("#bd").height()
		//alert (dh)
		nh = $("#localnav").height()
		//if (ph > dh) {x = ph - 151 -$("#ft").height()} else {x = $("#yui-main").height()}
		//	$("#yui-main").height(dh)
		if (nh<dh) {
			$("#localnav").height(dh)	
		}
		
		
	}
	
	
	function getPageHeight(){
	  var de = document.documentElement;
	  var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
	  
	  return h;
	}
	
	
	// cookie functions http://www.quirksmode.org/js/cookies.html
	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);
	}

	

	$.fn.hoverClass = function(c) {
		return this.each(function(){
			$(this).hover( 
				function() { $(this).addClass(c);  },
				function() { $(this).removeClass(c); }
			);
		});
	};
	

	$(document).ready(function(){
		$('.styleswitch').click(function() {
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});
		var c = readCookie('style');		
		if (c) switchStylestyle(c);
		else switchStylestyle('default');
		//adjustLayout()
		
		//need to tweek this function for more conditions
		var co = $(".callout")
		var _co = $(".a_callout")
		var maps =$('.maps .withlocal')
		for (i=0; i<co.length; i++) {
			var maxWidth = 0
			iw = co[i].getElementsByTagName('img')
			for (j=0; j<iw.length; j++) {				
				if (iw[j].width > maxWidth) {
					maxWidth = iw[j].width
				}
			}
			co[i].style.width = maxWidth + "px"
		}
		for (i=0; i<_co.length; i++) {
			var maxWidth = 0
			iw = _co[i].getElementsByTagName('img')[0].width
			for (j=0; j<iw.length; j++) {				
				if (iw[j].width > maxWidth) {
					maxWidth = iw[j].width
				}
			}
			_co[i].style.width = maxWidth + "px"
		}
		for (i=0; i<maps.length; i++) {
			// iw = maps[i].getElementsByTagName('img');
			// var maxWidth = 0
			// for (j=0; j<iw.length; j++) {
			// 	if (iw[j] > maxWidth) {
			// 		alert(maxWidth)
			// 	}
			// }
			// 
			// 
			// _co[i].style.width = iw + "px"
		}
		
	});

