function highlight(carousel,obejctli,liindex,listate){
	 liindex = liindex + 1;
     $('#peoplenav a:nth-child('+ liindex +')').attr("class","active");
};
function removehighlight(carousel,obejctli,liindex,listate){
	 liindex = liindex + 1;
     $('#peoplenav a:nth-child('+ liindex +')').removeAttr("class","active");
};

function mycarousel_initCallback(carousel) {
    $('#slideshow-next').bind('click', function() {
        carousel.next(); 
        return false;
    });

    $('#slideshow-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    
    $('#peoplenav a').bind('click', function() {
    	carousel.scroll(jQuery.jcarousel.intval(jQuery(this).index()));
    	return false;
    });
};

$(document).ready(function() {

	$(".box").addClass('loadhide');
	
	$('#follow').click(function() {
  		$('#socialtab').toggle("fast");
  		return false;
	});
	
	$('#socialtab').mouseleave(function() {
  		$('#socialtab').hide("fast");
	});
	
	$(".btncontact, #closebtn").click(function(){
		//$("html,body").animate( { scrollTop: 0 }, "slow" );
		$("#contact").slideToggle("slow");
		$('#socialtab').hide();
		return false;
	});
	
	$('#slideshow ul li').hover(function(){
		$(".slidecaption", this).stop().animate({bottom:'0px'},{queue:false,duration:300});
	}, function() {
		$(".slidecaption", this).stop().animate({bottom:'-90px'},{queue:false,duration:300});
	});	
	
	$(window).bind('scroll', function(){
    	$("#contact").slideUp("slow");
	});
	
    $("#slideshow").jcarousel({
        scroll: 1,
        size: 5,
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback:  highlight,
        itemVisibleOutCallback: removehighlight,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
    
    $(".jcarousel-clip, .jcarousel-clip-horizontal").removeAttr("style");

	$('.slides').each(function() {
	    var $this = $(this); 
	    var $ss = $this.closest('.slideshow');
	    var prev = $ss.find('a.prev'); 
	    var next = $ss.find('a.next');
	    var slidenav = $ss.find('.slide-nav');
	    if ( $this.children().length == 1 )
        	slidenav.hide();
        else
	    $this.cycle({
	    	fx: 'scrollHorz',
	    	speed: 500,
	    	timeout: 0,
	    	prev: prev,
        	next: next
	    });
	});
	
	$('.newsslides').each(function() {
	    var $this = $(this); 
	    var $ss = $this.closest('.newsslideshow');
	    var prev = $ss.find('a.prev'); 
	    var next = $ss.find('a.next');
	    var slidenav = $ss.find('.slide-nav');
	    if ( $this.children().length == 1 )
        	slidenav.hide();
        else
	    $this.cycle({
	    	fx: 'scrollHorz',
	    	speed: 500,
	    	timeout: 0,
	    	prev: prev,
        	next: next
	    });
	});
	
	
	var elements = $(".news-entry");
	var next = 0;
	var max = elements.length;
	$('.news-next').click(function(){
		if(next+1 < max) {
	    	next++;
	    	$.scrollTo(elements[next], 800, { 
	    		axis:'y',
	    		offset: {top:-20, left:0} 
	    	});
		}
		return false;
	});
	
	$('.news-prev').click(function(){
		if(next-1 > -1) {
	    	next--;
	    	$.scrollTo(elements[next], 800, { 
	    		axis:'y',
	    		offset: {top:-20, left:0} 
	    	});
		}
		return false;
	}); 
	
	$('a.news-top').click(function() {
		   $.scrollTo( $('#wrapper'), 800);
		   return false;
	});
	
	$('.news-share').click(function() {
		var a = $(this);
		a.next('.socialb').toggle('fast');
		return false;
 	 });
 	 
 	 $('.slides img').tooltip({ 
		track: true, 
		delay: 400, 
		showURL: false,
		fade: 200 
	});
	
		   
});
$(window).load(function(){
    $('#project-grid').masonry({
    	singleMode: true, 
		itemSelector: '.box',
		animate: true,
		saveOptions: false,
		animationOptions: {
			duration: 400,
		    easing: 'linear',
		    queue: false
		  }
	});
    
    $('#work-grid').masonry({
    	singleMode: true, 
		itemSelector: '.workbox',
		animate: true,
		saveOptions: false,
		animationOptions: {
			duration: 400,
			easing: 'linear',
			queue: false
		}
	});

	$(".box").removeClass('loadhide');
});
