$(document).ready(function() 
{
	initModel();
	loadXml();
});/* End Document ready */

$(window).load(function() 
{
	initLocation();
	initView();
	
	$('.portfolio-preview').hover(function()
	{
		var $id = '#' + $(this).attr('id');
		var $parent = '#' + $(this).parent().attr('id');
		$($id + ' .portfolio-preview-border').stop(true,true).fadeIn(600);
		$($id + ' .portfolio-preview-image').stop(true,true).fadeTo(600, 1);
		$($parent + ' .color-animate').stop(true,true).animate( { color: 'beige' }, 1000);
	},
	function()
	{
		var $id = '#' + $(this).attr('id');
		var $parent = '#' + $(this).parent().attr('id');
		$($id + ' .portfolio-preview-border').stop(true,true).fadeOut(600);
		$($id + ' .portfolio-preview-image').stop(true,true).fadeTo(600, 0.8);
		$($parent + ' .color-animate').stop(true,true).animate( { color: '#909090' }, 1000);
	});
	
	$('.portfolio-preview').click(function()
	{	
		var $index = $('.portfolio-preview').index(this);
		var $id = '#' + $(this).attr('id');
		var $parent = '#' + $(this).parent().attr('id');
		var $holder = $($parent + ' .portfolio-details-holder');
		var $details = $($parent + ' .portfolio-details');
	
		initContent($index, $id, $parent, $holder, $details);
	});
	
	$('.portfolio-controls').hover(function()
	{
		var $alt = $(this).attr('alt');
		$(this).parent().find('.portfolio-control-hint').text($alt);
		$(this).stop(true,true).animate( { backgroundColor: 'beige' }, 800);
	},
	function()
	{
		$(this).parent().find('.portfolio-control-hint').text('');
		$(this).stop(true,true).animate( { backgroundColor: '#ADADAD' }, 800);
	});
	
	$('.portfolio-details').hover(function()
	{
		$(this).find('.portfolio-details-info').stop(true,true).fadeIn(300);
	},
	function()
	{
		$(this).find('.portfolio-details-info').stop(true,true).fadeOut(300);
	});
	
	$('.portfolio-facebook, .masthead-icons').hover(function()
	{
		$(this).stop(true,true).animate( { backgroundColor: 'beige' }, 800);
	},
	function()
	{
		$(this).stop(true,true).animate( { backgroundColor: '#ADADAD' }, 800);
	});
	
	$('.portfolio-down').click(function()
	{
		var $index = $('.portfolio-down').index(this);
		var $num = $('.portfolio-entry').length;
		
		if($index < $num - 1)
		{
			$index = $index + 1;
			var $parent = '#' + $($('.portfolio-entry').get($index)).attr('id');
			document.title = 'Philleep Florence - ' + titleArray[$index];
			urlHash = '/' + portfolioArray[$index] + '/';
			window.location.hash = urlHash;
			scrollContent($parent);	
		}
	});
	
	$('.portfolio-up').click(function()
	{
		var $index = $('.portfolio-up').index(this);
		var $num = $('.portfolio-entry').length;
		
		if($index > 0)
		{
			$index = $index - 1;
			var $parent = '#' + $($('.portfolio-entry').get($index)).attr('id');
			document.title = 'Philleep Florence - ' + titleArray[$index];
			urlHash = '/' + portfolioArray[$index] + '/';
			window.location.hash = urlHash;
			scrollContent($parent);	
		}
	});
	
	$('.portfolio-home, #go-to-top, #masthead-logo').click(function()
	{
		var $parent = '#container';
		urlHash = '/home/';
		window.location.hash = urlHash;
		document.title = 'Philleep Florence - Interactive Digital Studio';
		resetPortfolio();
		$('#profile').slideUp(600);
		scrollContent($parent);	
	});
	
	$('#portfolio-search-p').hover(function()
	{
		$(this).stop(true,true).animate( { color: 'beige' }, 600);
		$('.search-close').stop(true,true).show(200);
	},
	function()
	{
		$(this).stop(true,true).animate( { color: '#909090' }, 600);
		$('.search-close').stop(true,true).fadeOut(300);
	});
	
	$('#portfolio-search').click(function()
	{
		clearSearch();
	});
	
	$('#masthead-input').focus(function()
	{
		if($(this).val() == 'search works')
		{
			$(this).val('');
		}
		$('#masthead-form').stop(true,true).animate( { backgroundColor: 'beige' }, 1000);
	});
	
	$('#masthead-input').blur(function()
	{
		if($(this).val() == '')
		{
			$(this).val('search works');
		}
		$('#masthead-form').stop(true,true).animate( { backgroundColor: '#ADADAD' }, 1000);
	});
	
	$('#masthead-input').keydown(function(e)
	{
		if(e.keyCode == 13 || e.which == 13)
		{
			var $val = $('#masthead-input').val();
			searchWorks($val);
		}
	});
	
	$('#masthead-form').click(function()
	{
		if($('#masthead-input').val() != 'search works' && $('#masthead-input').val() != '')
		{
			var $val = $('#masthead-input').val();
			searchWorks($val);
		}
	});
	
	$('#show-profile').click(function()
	{
		$('#profile').slideToggle(700);
	});
	
	window.onhashchange = hashChanged;
});/* End Window load */



