	$(function () {
		
		if(window.location.hash.length > 1){	
			var alink = window.location.hash.substring(1,2);
			if(window.location.hash.length > 2){
				var alinkrel = window.location.hash.substring(2);
				$("#worksTitle").html(alinkrel);
			}
			$('ul.ourWorkList a').removeClass("selected");
			$(('ul.ourWorkList a.category'+alink)).addClass("selected");						
			$('ul.ourWorkControls a').removeClass("selected");
			$(('ul.ourWorkControls a.category'+alink)).addClass("selected");	
		}	
		
		$('.anythingSlider').anythingSlider({
			autoPlay: true,
			pauseOnHover: false,
			easing: "easeInOutExpo",
			hashTags: true,
			buildNavigation: false,
			animationTime: 1000,
			delay: 5000
		});
		$('.anythingSliderNav').anythingSlider({
			autoPlay: false,
			pauseOnHover: true,
			easing: "easeInOutExpo",
			hashTags: false,
			buildNavigation: true,
			animationTime: 1350
		});		
		
		$('ul.ourWork img').hide();	

		$('ul.ourWork img').fadeIn(1500);

		$("a.lightbox").fancybox({
			'overlayOpacity'	:	'0.85',
			'overlayColor'		:	'#000',
			'titlePosition'		:	'inside'
		});	
		$("a.lightboxIframe").fancybox({
			'type'				: 'iframe',
			'width'				: '70%',
			'height'			: '70%',
			'overlayOpacity'	:	'0.85',
			'overlayColor'		:	'#000'
		});	
	
		window.setInterval(function() {
			var minVal = 1;
			var maxVal = 25;
			var randVal1 = Math.round( minVal+(Math.random()*(maxVal-minVal)) );
			var randVal2 = Math.round( minVal+(Math.random()*(maxVal-minVal)) );
			var randVal3 = Math.round( minVal+(Math.random()*(maxVal-minVal)) );
			var randVal4 = Math.round( minVal+(Math.random()*(maxVal-minVal)) );		
			while(randVal2 == randVal1) { randVal2 = Math.round( minVal+(Math.random()*(maxVal-minVal)) ); }
			while(randVal3 == randVal2 || randVal3 == randVal1) { randVal3 = Math.round( minVal+(Math.random()*(maxVal-minVal)) ); }			
			while(randVal4 == randVal3 || randVal4 == randVal2 || randVal4 == randVal1) { randVal4 = Math.round( minVal+(Math.random()*(maxVal-minVal)) ); }			
			swapAction(randVal1,randVal2,randVal3,randVal4);
		}, 7000);		
		
		swapAction = function(id1,id2,id3,id4){
			// Fade out
			$('#item'+id1+' a').fadeOut(1000);
			$('#item'+id2+' a').fadeOut(1000);
			$('#item'+id3+' a').fadeOut(1000);
			$('#item'+id4+' a').fadeOut(1000, function() {
				// Callback on final fade... get contents
				var tempHtml1 = $('#item'+id1).html();
				var tempHtml2 = $('#item'+id2).html();	
				var tempHtml3 = $('#item'+id3).html();	
				var tempHtml4 = $('#item'+id4).html();	
				// Swap contents
				$('#item'+id1).html(tempHtml4);				
				$('#item'+id2).html(tempHtml3);
				$('#item'+id3).html(tempHtml2);
				$('#item'+id4).html(tempHtml1);
				// Fade in
				$('#item'+id1+' a').fadeIn(1000);
				$('#item'+id2+' a').fadeIn(1000);
				$('#item'+id3+' a').fadeIn(1000);
				$('#item'+id4+' a').fadeIn(1000);
			});
		}
				
	});
