	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') == 'print')  {
				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"
		}
		
	});
	
	/**
	 * jQMinMax     http://davecardwell.co.uk/javascript/jquery/plugins/jquery-minmax/
	 *
	 * @author      Dave Cardwell <http://davecardwell.co.uk/>
	 * @version     0.1
	 *
	 * @projectDescription  Add min-/max- height & width support.
	 *
	 * Built on the shoulders of giants:
	 *   * John Resig      - http://jquery.com/
	 *
	 *
	 * Copyright (c) 2006 Dave Cardwell, licensed under the MIT License:
	 *   * http://www.opensource.org/licenses/mit-license.php
	 */


	new function() {
	    $.minmax = {
	        active: false,
	        native: false
	    };


		// 	    $(document).ready(function() {
		// 	        // Create a div to test for native minmax support.
		// 	        var test = document.createElement('div');
		// 	        $(test).css({
		// 	                'width': '1px',
		// 	            'min-width': '2px'
		// 	        });
		// 	        $('body').append(test);
		// 
		// 	        // In compliant browsers, the min-width of 2px should overwrite the
		// 	        // width of 1px.
		// 	        $.minmax.native = ( test.offsetWidth && test.offsetWidth == 2 );
		// 
		// 	        // Tidy up.
		// 	        $(test).remove();
		// 
		// 	        // Go no further if minmax is supported natively.
		// 	        if( $.minmax.native )
		// 	            return;
		// 
		// 	        // Use jQMinMax.
		// 	        $.minmax.active = true;
		// 
		// 	        // Set up the minmax jQuery expressions.
		// 	        $.minmax.expressions();
		// 
		// 
		// 	        // Use the plugin on all elements where a min/max CSS style is set.
		// 	        $(':minmax').minmax();
		// 	    });
		// 
		// 
		// 	    $(window).resize(function() {
		// 	     // Go no further if minmax is supported natively.
		// 	        if( $.minmax.native )
		// 	            return;
		// 
		// 	        // Use the plugin on all elements where a min/max CSS style is set.
		// 	        $(':minmax').minmax();
		// });



	    /**
	     * Set up the minmax jQuery expressions.
	     *
	     * @example $.minmax.expressions();
	     *
	     * @name $.minmax.expressions
	     * @cat  jQMinMax
	     */
	    $.minmax.expressions = function() {
	        // p for 'properties'.
	        var p = new Array( 'min-width', 'min-height',
	                           'max-width', 'max-height' );

	        // This will hold the components of an uber selector for grabbing
	        // anything with a minmax value.
	        var minmax = new Array();

	        for( var i = 0; i < p.length; i++ ) {
	            // Build the expression.
	            var expr = "$.css(a,'" + p[i] + "')!='0px'&&"
	                     + "$.css(a,'" + p[i] + "')!='auto'&&"
	                     + "$.css(a,'" + p[i] + "')!=window.undefined";

	            // max-width / max-height can also have the value 'none'.
	            if( p[i].charAt(2) == 'x' )
	                expr += "&&$.css(a,'" + p[i] + "')!='none'";

	            // Add the expression to jQuery.
	            $.expr[':'][ p[i] ] = expr;

	            // Add the expression to the ':minmax' expression.
	            minmax[i] = '(' + expr + ')';

	        }

	        // Build and add the ':minmax' expression.
	        $.expr[':']['minmax'] = minmax.join('||');
	    };



	    /**
	     * Check the given elements for height/width values that fall outside
	     * their min/max constraints and update them appropriately.
	     *
	     * @example $('#foo').minmax();
	     *
	     * @name $.fn.minmax();
	     * @cat  jQMinMax
	     */
	    $.fn.minmax = function() {
	        return $(this).each(function() {
	            // Get the min/max constraints of the current element.
	            var constraint = {
	                'min-width':  calculate( this, 'min-width'  ),
	                'max-width':  calculate( this, 'max-width'  ),
	                'min-height': calculate( this, 'min-height' ),
	                'max-height': calculate( this, 'max-height' )
	            };


	            // Determine its current width and height.
	            var width  = this.offsetWidth;
	            var height = this.offsetHeight;

	            if (document.documentElement.clientWidth > width) {
	            	width = document.documentElement.clientWidth
	            }

	            var newWidth  = width;
	            var newHeight = height;



	            // If the element is wider than its max-width...
	            if( constraint['max-width'] != window.undefined
	             && newWidth > constraint['max-width'] )
	                newWidth = constraint['max-width'];

	            // If the element is/is now thinner than its min-width...
	            if( constraint['min-width'] != window.undefined
	             && newWidth < constraint['min-width'] )
	                newWidth = constraint['min-width'];

	            if( constraint['min-width'] != window.undefined
	             && constraint['min-width'] < newWidth )
	                $('#doc3').width('100%');

	            // If the element is taller than its max-height...
	            if( constraint['max-height'] != window.undefined
	             && newHeight > constraint['max-height'] )
	                newHeight = constraint['max-height'];

	            // If the element is/is now shorter than its min-height...
	            if( constraint['min-height'] != window.undefined
	             && newHeight < constraint['min-height'] )
	                newHeight = constraint['min-height'];


	            // Update the proportions of the current element as required.
	            if( newWidth  != width )
	                $(this).css( 'width',  newWidth  );
	            if( newHeight != height )
	                $(this).css( 'height', newHeight );
	        });
	    };



	    // Calculate the computed numeric value of a CSS length value.
	    function calculate( obj, p ) {
	        var raw = $(obj).css( p );

	        // Nothing in, nothing out.
	        if( raw == window.undefined || raw == 'auto' )
	            return window.undefined;

	        var result;

	        // Is it a percentage value?
	        result = raw.match(/^\+?(\d*(?:\.\d+)?)%$/);
	        if( result ) {
	            return Math.round(
	                Number(
	                    (
	                        /width$/.test(p) ? $(obj).parent().get(0).offsetWidth
	                                         : $(obj).parent().get(0).offsetHeight
	                    )
	                    * result[1]
	                    / 100
	                )
	            );
	        }


	        // Is it a straight pixel value?
	        result = raw.match(/^\+?(\d*(?:\.\d+)?)(?:px)?$/);
	        if( result ) {
	            return Number( result[1] );
	        }


	        // Garbage in, nothing out.
	        return window.undefined;
	    }
	}();

