$(document).ready(function(){

	/*
	----------------------------------------------------------
	GENERAL
	---------------------------------------------------------- */

	$('#logos').jcarousel({
		auto: 6,
        scroll: 3,
		animation: 600,
        wrap: 'both',
        initCallback: mycarousel_initCallback
    });
	
	$("#features .feature1").hover(
    	function() {
		$(this).stop().animate({"opacity": ".75"}, "slow");
    	},
    	function() {
		$(this).stop().animate({"opacity": "1"}, "fast");
    	}
	);
	
	$("#features .feature2").hover(
    	function() {
		$(this).stop().animate({"opacity": ".75"}, "slow");
    	},
    	function() {
		$(this).stop().animate({"opacity": "1"}, "fast");
    	}
	);
	
	$("#features .feature3").hover(
    	function() {
		$(this).stop().animate({"opacity": ".75"}, "slow");
    	},
    	function() {
		$(this).stop().animate({"opacity": "1"}, "fast");
    	}
	);
	
	$("#CScallout").hover(
    	function() {
		$(this).stop().animate({"opacity": ".75"}, "slow");
    	},
    	function() {
		$(this).stop().animate({"opacity": "1"}, "fast");
    	}
	);
	
	$("#portfolio div").hoverIntent(
    	function() {
		$(this).find("ul.linkblock").toggle("slow");
    	},
    	function() {
		$(this).find("ul.linkblock").toggle("fast");
    	}
	);
	
	
	$("#slider").easySlider({
		auto: false, 
   		continuous: true,
   		vertical:false,
   		allControls: true
	});
	
	var $container = $('#portfolio');
		
	$('#filters a').click(function(){
      var selector = $(this).attr('data-filter');
	  
	  // Set cookie
	  $.cookie("ourwork-sort", selector, { expires : 90, path: '/' });	  
	  
      $container.isotope({ filter: selector });
      return false;
    });
	
	// switches selected class on buttons
      $('#viewby').find('.view-set a').click(function(){
        var $this = $(this);
		
        // don't proceed if already selected
        if ( !$this.hasClass('selected') ) {
          $this.parents('.view-set').find('.selected').removeClass('selected');
		  $this.addClass('selected');
        }
	});

	
	/*
	----------------------------------------------------------
	BIOS
	---------------------------------------------------------- */
	$("body.team div.bio:not(:first)").hide();
	$("#team li a:first").addClass("active");

	$('#team li a').each(function(){
	    var item = this.id;
	    item = item.slice(4,20);
		// alert(item);

	    $(this).click(function() {
			$('div.bio').hide();
			$('#bio-'+item).animate({opacity: "show"}, "slow");
			$('#team li a').removeClass("active");
			$(this).addClass("active");
			return false;

	    });
	});
	
	
	/*
	----------------------------------------------------------
	FORMS
	---------------------------------------------------------- */
	$.validator.addMethod("NumbersOnly", function(value, element) {
		return this.optional(element) || /^[0-9\-\+]+$/i.test(value);
		}, "Phone must contain only numbers, + and -.");

	$("#contact-form").validate();
	
	
	
	/*
	----------------------------------------------------------
	FANCYBOX
	---------------------------------------------------------- */
	$("#tabs li a").fancybox({
		'width'				: 675,
		'height'			: 725,
		'hideOnContentClick': false,
        'autoScale'     	: false,
        'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});


});


// END ON READY
	
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
