jQuery(document).ready(function($) {
	/**
	 * We have some fancy animations which we only want in good browsers
	 * So anything that's better then IE8/7
	 */
	var is_good_browser = (!$.browser.msie);
	
	//change .portfolio-item rotation point
	// This seems causes a MS filter issue making the wire look like sh*t
	// So if we're not rotating, no need to make things look worse
	if(is_good_browser) {
		$('.portfolio-item').transform({origin: [98, 0]});
	}
	
	//rotate people polaroid
	//$('#profile-image.people-item').transform({rotate: -6});
	
	//set bg to be invisible initially
	$('#supersize').css("opacity",0);
	
	//supersize settings
	$.fn.supersized.options = {  
		startwidth: 1680,  
		startheight: 1050,
		vertical_center: 1,
		slideshow: 0,
		navigation: 0,
		transition: 0, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
		pause_hover: 0,
		slide_counter: 0,
		slide_captions: 0,
		slide_interval: 3000  
	};
	
	// supersize image based on window size
	$('#supersize').supersized(); 
	
	//fade bg image when loaded
	$(window).load(function () {
  		$('#supersize').fadeTo(400, 1);
	});
	
	
	//fade in & out bg image on nav rollover
	$("ul#nav-links li a ").hover(
   function() {
      $(this).animate({backgroundPosition: '0px 0px'}, 200);
         
      },
   function(){
	   if($(this).parent().hasClass("selected") == false)
	   {
 			$(this).animate({backgroundPosition: '-240px 0px'}, 0);
	   }
      }
   );
	
	
	
	//controls item scrolling on homepage	
	var news_items = $('#news-items');
	if(news_items.length > 0) {
		news_items.cycle({ 
			fx:     'scrollHorz', 
			speed: 400, 
			timeout: 10000, 
			next:   '#next-news-item', 
			prev:   '#previous-news-item' 
		});
	}
	
	var portfolio_items = $('#portfolio-items');
	if(portfolio_items.length > 0) {
		portfolio_items.cycle({ 
			fx:     'scrollHorz', 
			speed: 400, 
			timeout: 10000, 
			next:   '#next-portfolio-item', 
			prev:   '#previous-portfolio-item' 
		});
	}

	var multiplier = 100;
	
	//controls scrolling portfolio pages
	$('.scroll-left-portfolio').click(function() {
		// Make sure that when the disabled arrow button is clicked, we don't do anything
		if($(this).hasClass('disabled')) return false;
		
		if(is_good_browser && $('.portfolio-item').queue().length < 1) {
			$('.portfolio-item').animate({rotate: 6}, 3 * multiplier);
		}
		
	  	$('.portfolio-items-container').animate({left: '+=224'}, 3 * multiplier,  
			function() {
			//after first animation
	  		if(is_good_browser && $('.portfolio-item').queue().length == 0 && $('.portfolio-items-container').queue().length == 0) {
				$('.portfolio-item').animate({rotate:-6}, 2 * multiplier);
				$('.portfolio-item').animate({rotate: 3}, 4 * multiplier);
				$('.portfolio-item').animate({rotate: 0}, 2 * multiplier);
			} else if(is_good_browser && $('.portfolio-item').queue().length == 1 && $('.portfolio-items-container').queue().length == 0) {
				$('.portfolio-item').animate({rotate:-3}, 1 * multiplier);
				$('.portfolio-item').animate({rotate: 2}, 3 * multiplier);
				$('.portfolio-item').animate({rotate: 0}, 2 * multiplier);
			}
	  	});
	});
	
	$('.scroll-right-portfolio').click(function() {
		// Make sure that when the disabled arrow button is clicked, we don't do anything
		if($(this).hasClass('disabled')) return false;
		
		// Start off by doing a rotation
		if(is_good_browser && $('.portfolio-item').queue().length < 1) {
			$('.portfolio-item').animate({rotate: -6}, 3 * multiplier);
		}
		
	  	$('.portfolio-items-container').animate({left: '-=224'}, 3 * multiplier, function() {
	  		if(is_good_browser && $('.portfolio-item').queue().length == 0 && $('.portfolio-items-container').queue().length == 0) {
				$('.portfolio-item').animate({rotate: 6}, 2 * multiplier);
				$('.portfolio-item').animate({rotate:-3}, 4 * multiplier);
				$('.portfolio-item').animate({rotate: 0}, 2 * multiplier);
			} else if(is_good_browser && $('.portfolio-item').queue().length == 1 && $('.portfolio-items-container').queue().length == 0) {
				$('.portfolio-item').animate({rotate: 3}, 1 * multiplier);
				$('.portfolio-item').animate({rotate:-2}, 3 * multiplier);
				$('.portfolio-item').animate({rotate: 0}, 2 * multiplier);
			}
	  	});
	});
	
	//controls item scrolling on homepage	
	var project_images = $('.project-images');
	if(project_images.length > 0) {
		project_images.cycle({ 
			fx:     'scrollHorz', 
			speed: 400, 
			timeout: 0, 
			next:   '.next-image', 
			prev:   '.previous-image' 
		});
	}
	
	
	//controls scrolling people page
	$('.scroll-left-people').click(function() {
		// Make sure that when the disabled arrow button is clicked, we don't do anything
		if($(this).hasClass('disabled')) return false;
		
		$('.background-people').animate({left: '+=178'}, 300)									
	  	$('.people-items-container').animate({left: '+=178'}, 300,  
			function() {
			//after first animation
	  	});
	});
	
	$('.scroll-right-people').click(function() {
		// Make sure that when the disabled arrow button is clicked, we don't do anything
		if($(this).hasClass('disabled')) return false;
		
		$('.background-people').animate({left: '-=178'}, 300)									
	  	$('.people-items-container').animate({left: '-=178'}, 300,  
			function() {
			//after first animation
	  	});
	});
});
