$(document).ready(function()
{
	function doCycle()
	{

			if($("#cycle").length >= 1)
			{
			$("#cycle-container").after('<div id="controls"><a id="prev" href="#">p</a><span id="numbers"></span><a id="next" href="#">n</a>');
			$("#controls").hide().slideDown("slow");
			
			$('#cycle').cycle({ 
				fx: 'scrollHorz',
				speed: 500,
			    timeout: 0, 
			    pager:  '#numbers',
			 	next:   '#next', 
			    prev:   '#prev',
				slideResize: 1
			});
			}
	

		
		
	};

	$(window).load(function() {
		doCycle();
	});
	

	// Fix current_page_item
	
	if ($("body").hasClass("single-portfolio")){
		$(".menu").find("a:contains('Portfolio')").parent("li").addClass("current_page_item");
	}
	
	if ($("body").hasClass("single-post")){
		$(".menu").find("a:contains('Blog')").parent("li").addClass("current_page_item");
	}
	
	
	// Filter buttons
	$(".filter-all").addClass("active");
	
	$(".filter-all").click(function()
	{
		$(".case-icons").removeClass("active");
		$(this).toggleClass("active");
		
		$(".thumbnail-wrapper").animate({ opacity: 1 }, 500);
	});
	
	
	$(".filter-art-direction").click(function()
	{
		$(".case-icons").removeClass("active");
		$(this).toggleClass("active");
		
		$(".thumbnail-wrapper").each(function()
		{
			if( $(this).hasClass("art-direction") )
			{
				$(".art-direction").animate({ opacity: 1 }, 200);
			}
			else {
				
				$(this).animate({ opacity: 0.3 }, 200);
				}
		});		
		
	});
	
	$(".filter-design").click(function()
	{
		$(".case-icons").removeClass("active");
		$(this).toggleClass("active");
		
		$(".thumbnail-wrapper").each(function()
		{
			if( $(this).hasClass("design") )
			{
				$(".design").animate({ opacity: 1 }, 200);
			}
			else {
				
				$(this).animate({ opacity: 0.3 }, 200);
				}
		});
		
	});
	
	$(".filter-development").click(function()
	{
		$(".case-icons").removeClass("active");
		$(this).toggleClass("active");
		
		$(".thumbnail-wrapper").each(function()
		{
			if( $(this).hasClass("development") )
			{
				$(".development").animate({ opacity: 1 }, 200);
			}
			else {
				
				$(this).animate({ opacity: 0.3 }, 200);
				}
		});
	});

	
	// Thumbnail hover animation
	
	$(".thumbnail-wrapper").mouseenter(function() {
		var $this = $(this);

		$this.find(".thumbnail-info").css({"text-indent" : "-260px"})

		$this.animate({
			top: "-10px",
		}, 200, function() {
		});
		
		$(this).find(".thumbnail-info").animate({
			opacity: 1,
			"text-indent": 0
		}, 200, function() {
		});
		
		$(this).find(".case-thumbnail").animate({
			opacity: 0
		}, 200, function() {
		});

	});

	$(".thumbnail-wrapper").mouseout(function() {
		$(this).animate({
			top: 0,
		}, 100, function() {
		});

		$(this).find(".thumbnail-info").animate({
			opacity: 0,
			"text-indent": "-260px"
		}, 200, function() {
		});
		
		$(this).find(".case-thumbnail").animate({
			opacity: 1
		}, 300, function() {
		});
		
	});
	

	/* GOT TO TOP */
	$(function()
	{
		$.fn.scrollToTop=function(){
			$("#toTop").hide().removeAttr("href");
			if($(window).scrollTop()!="0"){
				$(this).fadeIn("slow")
			}
			var scrollDiv=$(this);
			$(window).scroll(function(){
				if($(window).scrollTop()=="0"){
					$(scrollDiv).fadeOut("slow")
				}else{
					$(scrollDiv).fadeIn("slow")
				}
			});
			$(this).click(function(){
				$("html, body").animate({scrollTop:0},"slow");
			});
		}
	});
	$(function() {
		$("#toTop, #toFavourites").scrollToTop();
	});
	
	/* Twitter! */
	
	getTwitters('twitter', { 
	  id: 'adriantomic', 
	  count: 1, 
	  enableLinks: true, 
	  ignoreReplies: true, 
	  clearContents: true,
	  template: '<p>%text%</p> <a href="http://twitter.com/%user_screen_name%/statuses/%id%/"></a><p>Follow me on Twitter: <a href="http://www.twitter.com/adriantomic">adriantomic</a></p>'
	});
	


});


