// Ajax load functions
$(document).ready(function() {	
	var strPage = window.location.hash.substr(1);
	var toLoad = strPage + '.html #content-inner';
	$('#content-inner').load(toLoad)							
	
	if (toLoad.indexOf('twitter') != -1) {
		document.title = "Twitter Feed | The Hag Portfolio"; 
		$('.tweet').livequery(function(){
			$(".tweet").tweet({
				username: "hgascoigne92",
				join_text: "auto",
				avatar_size: 32,
				count: 6,
				auto_join_text_default: "I said,",
				auto_join_text_ed: "I",
				auto_join_text_ing: "I was",
				auto_join_text_reply: "I replied to",
				auto_join_text_url: "I was checking out",
				loading_text: "loading tweets..."
			});
		});
	}
	else if (toLoad.indexOf('index') != -1) {
		document.title = "The Hag Portfolio | Home of Hag Designs"; 
	}
	else if (toLoad.indexOf('web') != -1) {
		document.title = "Web Design | The Hag Portfolio"; 
	}
	else if (toLoad.indexOf('envato') != -1) {
		document.title = "Envato Mobile | The Hag Portfolio"; 
	}
	else if (toLoad.indexOf('3d-film') != -1) {
		document.title = "3D and Film | The Hag Portfolio"; 
	}
	else if (toLoad.indexOf('2d') != -1) {
		document.title = "2D Graphic Design | The Hag Portfolio"; 
	}
	else if (toLoad.indexOf('about') != -1) {
		document.title = "About | The Hag Portfolio"; 
	}
	$('a').livequery(function(){ 
		/* This is basic - uses default settings */ 
		$("a.single_image").fancybox({
			'overlayOpacity': 0.8,
			'padding': 0
		}); 
		$("a.inline").fancybox({
			'padding'       : 0,
			'frameWidth'    : 650,
			'frameHeight'   : 366,
			'overlayOpacity': 0.8,
			'zoomOpacity'	: true
		}); 
	});
	$('a').livequery(function(){ 
		/* This is basic - uses default settings */ 
		$('.ajax').click(function(){						  
		var toLoad = $(this).attr('href')+' #content-inner';
		$('#content-inner').slideUp('fast',loadContent);
		$('#content-inner').hide();
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		function loadContent() {
			if(toLoad.indexOf('twitter') != -1)
			{
				document.title = "Twitter Feed | The Hag Portfolio";
				
				//TODO: PREVENT DUPLICATES!!!
				/*$('.tweet').livequery(function(){
					$(".tweet").tweet({
						username: "hgascoigne92",
						join_text: "auto",
						avatar_size: 32,
						count: 6,
						auto_join_text_default: "I said,",
						auto_join_text_ed: "I",
						auto_join_text_ing: "I was",
						auto_join_text_reply: "I replied to",
						auto_join_text_url: "I was checking out",
						loading_text: "loading tweets..."
					});
				});*/
			}
			else if(toLoad.indexOf('index') != -1)
			{
				document.title = "The Hag Portfolio | Home of Hag Designs"; 
			}
			else if(toLoad.indexOf('web') != -1)
			{
				document.title = "Web Design | The Hag Portfolio"; 
			}
			else if (toLoad.indexOf('envato') != -1) 
			{
				document.title = "Envato Mobile | The Hag Portfolio"; 
			}
			else if(toLoad.indexOf('3d-film') != -1)
			{
				document.title = "3D and Film | The Hag Portfolio"; 
			}
			else if(toLoad.indexOf('2d') != -1)
			{
				document.title = "2D Graphic Design | The Hag Portfolio"; 
			}
			else if(toLoad.indexOf('about') != -1)
			{
				document.title = "About | The Hag Portfolio"; 
			}
			$('#content-inner').load(toLoad,'',showNewContent())
		}
		function showNewContent() {
			$('#content-inner').slideDown('normal',hideLoader());
		}
		function hideLoader() {
		}
		return false;
	});
	});
});