//JavaScript Dynamic Content using jQuery
//www.mclelun.com
//original by yendesign

$(document).ready(function(){
var jqc_vHash = window.location.hash;

//Check if there is hash data on first load
if (jqc_vHash)
{
	jqc_fnLoad(jqc_vHash.substr(1,jqc_vHash.length));
	
	if((window.location.pathname == "/portfolio/")||
	(window.location.pathname == "/portfolio")||
	(window.location.pathname == "/portfolio.php"))
	{
		//TABS
		$("#frmfolio_web").hide();
		$("#frmfolio_game").hide();
		$("#frmfolio_comic").hide();
		$("#frmfolio_art").hide();
		$("#frmfolio_cgi").hide();
		
		var jqc_vTab = jqc_vHash.split("_");
		$("#frmfolio_"+jqc_vTab[0].slice(1)).show();
		
		$("#jqc_tab li").each(function() {
			$(this).css("background","#211a16");
			if($(this).attr('id') == jqc_vTab[0].slice(1))
			{
				$(this).css("background","#2e251e");
			}
		});

	}
}
else
{
	$("#frmfolio_web").hide();
	//$("#frmfolio_game").hide();
	$("#frmfolio_comic").hide();
	$("#frmfolio_art").hide();
	$("#frmfolio_cgi").hide();
	
	
	$("#jqc_tab li").each(function() {
		if($(this).attr('id') == "game")
		{
			$(this).css("background","#2e251e");
		}
	});

}


function jqc_fnLoad(p_ID){
	
	$('html, body').animate({scrollTop:150}, 'fast');
	document.location.hash=p_ID;
	jqc_fnShowLoading();
	
	if((window.location.pathname == "/labs/") ||
	(window.location.pathname == "/labs") ||
	(window.location.pathname == "/labs.php"))
	{	
		$("#jqc_content").empty();
		$("#jqc_content").animate({ opacity: 'hide' }, 500);
		$("#jqc_content").load("http://www.mclelun.com/conlabs/"+p_ID+"/index.html", jqc_fnHideLoading);
	}
	else if((window.location.pathname == "/portfolio/")||
	(window.location.pathname == "/portfolio")||
	(window.location.pathname == "/portfolio.php"))
	{
		$("#jqc_content").empty();
		$("#jqc_content").animate({ opacity: 'hide' }, 500);
		$("#jqc_content").load("http://www.mclelun.com/confolio/"+p_ID+"/index.html", jqc_fnHideLoading);
		
	}
	else
	{
		alert('error loading');
	}
}

$(".jqc_menu li").click(function(){
	jqc_fnLoad(this.id);
	document.title = "Mclelun : " + $(this).text();
});


$("#jqc_tab li").click(function(){
	
	$("#jqc_tab li").each(function() {
		$(this).css("background","#211a16");
	});

	$(this).css("background","#2e251e");
	$("#frmfolio_web").hide();
	$("#frmfolio_game").hide();
	$("#frmfolio_cgi").hide();
	$("#frmfolio_comic").hide();
	$("#frmfolio_art").hide();
	$("#frmfolio_"+this.id).show();
});


function jqc_fnShowLoading()
{
	$("#jqc_loading")
		.css({visibility:"visible"})
		.css({opacity:"1"})
		.css({display:"block"})
	;
}

function jqc_fnHideLoading()
{
	$("#jqc_content").animate({ opacity: 'show' }, 500);
	$("#jqc_loading").fadeTo(1000, 0);
	//document.title = "Mclelun : " + $("#jqc_content").find("h2").html();
};

});
