$(document).ready(function(){
	//$("#browser").Treeview();
	
	//$("#main, #navigation").equalizeCols();
	$("#main .callout").setCalloutWidth();	
	$("#nav").Treeview({
		speed: ".5",
		unique: true,
		collapsed: true,
		store: true,
		toggle: function() {
			//window.console && console.log && console.log("%o was toggled", $(this).parent());
			//$("#nav, #navigation").equalizeCols();
			
		}
	});

	var nav_links = document.getElementById('nav').getElementsByTagName('a');
	var selected = location.pathname;
	if (selected != "/") {
	
	   for (var i = 0; i < nav_links.length; i++) {
	     var link = nav_links[i].pathname;
	
	
	     // fiddle IE's view of the link
	     if (link.substring(0, 1) != '/')
		 
	       link = '/' + link;
	
		   
	
	     if (link == selected)
		   nav_links[i].parentNode.className = "active"
	       //nav_links[i].style.color = "#f0f"			//setAttribute(cattr, 'selected');
	   }
	}
	
	$('.styleswitch').click(function()
	{
		switchStylestyle(this.getAttribute("rel"));
		return false;
	});
	var c = readCookie('style');
	if (c) switchStylestyle(c);

});


/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
 
(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	 
	$.fn.equalizeCols = function(){
		var height = 0;
  
		return this
			.css("height", "auto")
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);


(function($) {

	$.fn.setCalloutWidth = function(){
			var img = $(this).find('img').width()
			$(this).width(img)
	}
	
})(jQuery);


function switchStylestyle(styleName)
{	
	var main = $("#main").height()
	var bd = $("#navigation").height()
	$('link[@rel*=style][@title]').each(function(i) 
	{	
		this.disabled = true;
		if (this.getAttribute('title') == styleName || this.getAttribute('title') == 'screen'  || this.getAttribute('title') == 'reset' || this.getAttribute('title') == 'print') this.disabled = false;
	});
	createCookie('style', styleName, 365);
	//$("#main, #navigation").equalizeCols();
}

// 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);
}
// /cookie functions

