$(document).ready(function()
{
	ScrollUtils.init();
	
	// Apply active state to clicked menu items
	$('.clickmenu a').click(function(){
		parentdiv = $(this).parent().get(0);
		$(parentdiv).children().removeClass('active');
		$(this).addClass('active');
	});
	
	loadTwitter('madeinkatana', 4);
	
	$('.result a').click(function(){
		loadColorBox($(this), '');	
	});
	
	// TODO Need to remove duplicaion for colorbox code call (Nawaz)
	$("a[rel='rel_Showreel_All']").colorbox({
		scrolling: false,
		slideshow: true,
		innerWidth: 500,
		initialHeight: 200,
		rel: 'rel_Showreel_All',
		current: "Project {current} of {total}",
		slideshow: true,
		slideshowAuto: false,
		preloading: false,
		onComplete: function()
		{
			$.fn.colorbox.resize();
			process_banners();
		}
	});
	
	process_banners();
});

function getImage(img, action)
{
	img.src = 'img/buttons/' + action + '/' + img.id + 'Button.png';
}

function showcontent(tagId, tagName)
{
	if(tagId != '') // If 'All' is not selected
	{
		$('.result:not(.tag_' + tagId + ')').hide('slow');	// Hide all contents
		$('.tag_' + tagId).show('slow');	// Display only contents those are matching with tag
	}
	else
	{
		$('.result').show('slow');	// Show all contents
	}
}

function loadColorBox(link, tagName)
{
	$('.result a:visible').colorbox({
		scrolling: false,
		slideshow: true,
		innerWidth: 500,
		initialHeight: 200,
		rel: 'rel_' + tagName,
		current: "Project {current} of {total}",
		slideshow: true,
		slideshowAuto: false,
		preloading: false,
		onComplete: function()
		{
			$.fn.colorbox.resize();
			process_banners();
			ScrollUtils.init();
		}
	});
}

function process_banners()
{
	// Set delay to prevent all banners refreshing at once, we increment per banner container load
	var initial_delay = 0;
	
	$('.banner_wrapper').each(function(i)
	{
		var paging_div = '#' + this.id + ' > .banner_paging';
		var banners_div = '#' + this.id + ' > .banners';
		
		$(banners_div).cycle
		({
			fx: 'fade',
			pause: true,
			speed:500,
			timeout: 6000,
			delay: initial_delay,
			pager: paging_div 
		});
		
		initial_delay += 800;
		
		// Shows and hides navigation based on hovering over the banners
		$(banners_div).hover
		(
			function(){$(this).next().css('display','block');},
			function(){$(this).next().css('display','none');}
		);
		
		$(paging_div).hover
		(
			function(){$(this).css('display','block');}
		);
	});
}

function showContactUs()
{
	$('#contactUs').slideDown('slow');
}

function hideContactUs()
{
	$('#contactUs').slideUp('slow');
}

