/* 
The Warehouse Agency
Digital Warehouse Agency
View and Control
*/
$(document).ready(function()
{
	/////////////////////////////////////////////////////////
	///////////////// Clients Functions /////////////////////
	/////////////////////////////////////////////////////////
	$('.clients-li').css({ 'margin-top' : '200px', 'opacity' : '0' });
	$('.clients-li').each(function()
	{
		var i = $('.clients-li').index(this);
		$(this).attr({ 'id' : 'clients-li-' + i});
	});
	initClientsArray();
	
	$('.clients-li').hover(
		function()
		{
			if(isScroll)
			{
				$('.clients-li').stop().fadeTo(800, 0.3);
				$(this).stop().fadeTo(600, 1);
			}
		}, 
		function()
		{
			if(isScroll)
			{
				$('.clients-li').stop().fadeTo(800, 1);
			}
		}
	);
	
	$('#contents').mousemove(function(e)
	{
		clientsScroll(e);
	});
	
	$('.clients-li').click(function()
	{			
		clientName = $(this).text();
		clientName = clientName.toLowerCase();
		clientIndex = '#' + $(this).attr('id');
		initClient();
	});
	
	$('#clients-title, #clients-close').click(function()
	{
		exitClientSlides();	
	});
	
	$('#clients-title, #clients-close').bind(event, function(e) 
	{
		exitClientSlides();
	});
	
	$('#client-info-controller').hover(function()
	{
		if(!isInfo)
		{
			$('#client-info-img').stop(true, true).fadeIn(300);
		}
	},
	function()
	{
		if(!isInfo)
		{
			$('#client-info-img').stop(true, true).fadeOut(300);
		}
	});
	
	$('#client-info-controller').click(function()
	{
		if(!isInfo)
		{
			$('#client-info').stop(true, true).show(300);
			isInfo = true;
		}
		else
		{
			$('#client-info').stop(true, true).hide(300);
			isInfo = false;
		}
	});
	
	$('#clients-slides-controller-mobile').bind(event, function(e) 
	{
		if(!isInfo)
		{
			$('#client-info').stop(true, true).show(300);
			isInfo = true;
		}
		else
		{
			$('#client-info').stop(true, true).hide(300);
			isInfo = false;
		}
	});
});

$(window).load(function () 
{
	
	$('#navigation').fadeIn(1000, function()
	{ 
		init();
		align(); 
	});
	/////////////////////////////////////////////////////////
	///////////// Load Content Functions ////////////////////
	/////////////////////////////////////////////////////////	
	$('.nav-li').click(function()
	{
		URL = $(this).attr('id');
		URL = URL.replace('-nav', '');
		urlHash = location.hash;
		
		if(activeNav != URL)
		{		
			$('#' + activeNav + '-nav').attr({ 'class' : 'nav-li' });
			
			activeNav = URL;
			URL = '/' + URL + '/';
			location.hash = URL;
			urlHash = location.hash;			
			
			$('#no-hit').fadeIn(0);
			clearTimers();
			initContents();	
		}
	});
	
	$('#logo').click(function()
	{
		if(activeNav != 'clients')
		{
			$('#' + activeNav + '-nav').attr({ 'class' : 'nav-li' });
			activeNav = 'clients';
			URL = '/clients/';
			location.hash = URL;
			urlHash = location.hash;	
			
			$('#no-hit').fadeIn(0);
			clearTimers();
			initContents();	
		}
	});	
	
	window.setInterval(function(){
		currHash = window.location.hash;

		if(currHash != urlHash)
		{			
			$('#' + activeNav + '-nav').attr({ 'class' : 'nav-li' });
			
			if(currHash.indexOf('clients') < 0)
			{
				urlHash = window.location.hash;
				URL = window.location.hash;
				initContents();
			}
			else
			{				
				if(isClient)
				{
					urlHash = window.location.hash;
					URL = window.location.hash;
					exitClientSlides();	
					activeContent = 'clients';
					$('#' + activeContent + '-nav').attr({ 'class' : 'active-li' });
				}
				else
				{
					window.location.hash = '/clients/';
					urlHash = window.location.hash;
					URL = window.location.hash;
					$('#' + activeContent + '-nav').attr({ 'class' : 'active-li' });
					$('#clients-portfolio').css({ 'display' : 'none'});
					$('#clients-images').html('');
					$('#no-hit').fadeIn(0);
					clearTimers();
					initContents();
				}
				
			}
		}
	}, 1000);
});

$(window).resize(function()
{
	clearTimeout(resizeDelay);
	resizeDelay = setTimeout(function()
	{
		align();
	}, 20);
});	
