// Hide toolbar on Iphone browser

addEventListener("load", function() { 
			setTimeout(hideURLbar, 0); }, false);
			function hideURLbar(){
			window.scrollTo(0,1);
		}


// Replace text in form

function textInInput (inp,Focus) {
	if (Focus) {
		if (inp.value==inp.defaultValue) 
			inp.value="";
			
	} else {
		if (inp.value=="") {
			inp.value=inp.defaultValue;
			
		}
	}
}

// Detect Iphone orientation

window.onload = function initialLoad() {
    updateOrientation();
}

function updateOrientation(){
    var contentType = "";
    switch(window.orientation){
        case 0:
	contentType += "portrait";
	break;

	case -90:
	contentType += "landscape";
	break;

	case 90:
	contentType += "landscape";
	break;

	case 180:
	contentType += "portrait";
	break;
    }
    document.getElementById("page_wrapper").setAttribute("class", contentType);
}

window.addEventListener("load", function() { setTimeout(loaded, 100) }, false);
	
		function loaded() {
			document.getElementById("page_wrapper").style.visibility = "visible";
			window.scrollTo(0, 1); // pan to the bottom, hides the location bar
		}

// jQuery stuff

jQuery(document).ready(function() {
    jQuery("#main-nav").hide();
	jQuery("#search-form").hide();
	jQuery("#loginform-container").hide();
	jQuery("#menu a").toggle( function () { jQuery(this).addClass("up");},function () {jQuery(this).removeClass("up");
  }
);
    jQuery("#menu a").click(function() {jQuery("#main-nav").slideToggle(400);return false;});
  	jQuery("#search a").click(function() {jQuery("#search-form").slideToggle(400);return false;});
	jQuery("#login a").click(function() {jQuery("#loginform-container").slideToggle(400);return false;});
	
		//bookmark-it
	jQuery('.bookmark-it a').click(function(){
		var pageName=window.location.href;
		var nameArr =pageName.split("?");
		pageName=nameArr[0] + "?" + nameArr[1];

		if (window.sidebar){
			window.sidebar.addPanel(document.title,pageName,"");
		} else if(document.all){ 
			window.external.AddFavorite(pageName,document.title);
		} else if(navigator.userAgent.toLowerCase().indexOf('iphone')!=-1) {
			alert('please press the \'+\' button on your browser to bookmark this site.');
		} else if(navigator.userAgent.toLowerCase().indexOf('webkit')!=-1) {
			alert('please press ctrl + D to bookmark');
		} else {
			return true;
		}
	});
});
/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

(function($)
{
	$(document).ready(function() {
		$('.styleswitch').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});
		var c = readCookie('style');
		if (c) switchStylestyle(c);
	});

	function switchStylestyle(styleName)
	{
		$('link[@rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		createCookie('style', styleName, 365);
	}
})(jQuery);
// 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
