Cufon.replace('h1')('h2')('h3')('ul.mainNavigation li a');

/* *****************************
 * LoadGallery 
 * @param {Object} type
 * @param {Object} gallery
 * @param {Object} wrapperElement
 * ******************************/
function LoadGallery(type)
{
	//$(wrapperElement).load('php/functions.php?page=' + type + '&type=' + gallery, function(){
		$("ul#gallery li a").fancybox({
			'titlePosition'	: 'inside',
			'changeSpeed' : '150',
			'cyclic' : 'true',
			'speedIn' : '150',
			'speedOut' : '150',
			'padding' : '5',
			'titleFormat' : formatTitle
		});
		Cufon.replace("h2");
		/*if(type == "gallery")
		{
			$("ul#gallery").css("display","block");
		}*/
	//});
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/data/closelabel.gif" /></a></span>' + (title && title.length ? '<b style="width:75%;">' + title + '</b>' : '' ) + '<span class="index" style="position:absolute;right:0;bottom:0;">Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</span></div>';
}

/* ****************************
 * Cufonize
 * ****************************/
function Cufonize(context)
{
	if($(".member #membercontent h2").length > 0) {
		Cufon.replace(".member #membercontent h2");
		Cufon.replace("h3.speciality");	
	}
	else {
		setTimeout(function(){
			Cufonize();
		}, 500);
	}
}

/* ******************************
 * LoadPage
 * @param {Object} page
 * @param {Object} active
 * @param {Object} me
 * ******************************/
function LoadPage(page, active, me) {
	//var href = window.location.href;
	//var href = window.location.href.split('?')[0];
	$('#content').load(page, function(response, status) { 
		//document.location.hash = href + "/" + $(me).attr("href");
		document.location.hash = $(me).attr("href");
	});
}

/* ******************************
 * StartSlideSwitch
 * ******************************/
function StartSlideSwitch()
{	
	if($("#slideshow").length > 0){
		$('#slideshow').cycle();
	}
	else {
		setTimeout("StartSlideSwitch()", 500);
	}
}
	
(function( $ ){	
	/* ********************************
	 * Document ready function
	 * ********************************/
	$(document).ready(function(){
		var params = document.location.hash.split('?')[1];
		if (params != undefined && params.split('=')[0] == 'mail') {
			switch (params.split('=')[1]) {
				case "empty":
					$('#content').load('pages/contact.html', function(){
						$('#content div h1').after("<div class='message'><p class='error'>Du måste skriva ett meddelande</p></div>");
					});
					break;				
				case "error":
					$('#content').load('pages/contact.html', function(){
						$('#content div h1').after("<div class='message'><p class='error'>Något gick fel, meddelandet är inte skickat.</p></div>");
					});
					break;	
				case "sent":
					$("#content").after("<div class='message'><p>Tack för ditt meddelande!</p></div>");
					break;			
				default:
					$('#content').load('pages/start.html');	
			}
		}		
		else{
			$('#content').load('pages/start.html');	
		}
		
		//If browser is IE
		if($.browser.msie)
		{
			//Add first/last child classes to li elements
			$("ul li:last-child").each(function(i){ $(this).addClass("last-child"); });
			$("ul li:first-child").each(function(i){ $(this).addClass("first-child"); });
		}
		
	});
})( jQuery );
