$(function(){ 
	
	setupScroll();
	SliderChiSiamo();
	SliderProdotti();
	SliderTeam();
	SliderPartners();
	SliderCaseHistory();
	SliderAwards();
//	AwardsLayer();
	//SliderContacts();
	CaseHistoryLayer();
	AwardsLayer();
	
	FasceOpen();
});


$(window).load(function(){
//splash();						
});



function splash(){
	//$("#splash").show(); 
	//$("#sidebar").css("margin-left", "-250px"); 
	$("#splash").delay(3000).fadeOut(2000); 
	//$("#splash").delay(3000).animate({marginTop:"-1500px"}, 2000); 
	$("#sidebar").delay(3000).animate({marginLeft:"0px"}, 2000); 
}


function setupScroll(){
	$("#menu a").live("click", function(){
		$.scrollTo("li"+$(this).attr("href"), 1200,{easing:'swing', axis:'y'});
		$("#menu a").removeClass("active");
		$(this).addClass("active");
		return false;
	});
}



function SliderChiSiamo(){
	var sliderChiSiamo = $("#chisiamoSlide").bxSlider({
		wrapperClass: 'chisiamo_slider',
		auto_controls: false,
		pager:false,
		infiniteLoop:false,
		controls:false
	});

	$('#chisiamo .controls a').live("click", function(){
		var thumbIndex = $('#chisiamo .controls a').index(this);
		sliderChiSiamo.goToSlide(thumbIndex);
		$('#chisiamo .controls a').show();
		$(this).hide();
		return false;
	});
}



function SliderProdotti(){
	var sliderProdotti = $("#prodottiSlide").bxSlider({
		wrapperClass: 'prodotti_slider',
		auto_controls: false,
		pager:false,
		infiniteLoop:false,
		controls:false
	});

$('#prodotti .controls a').live("click", function(){
		var thumbIndex = $('#prodotti .controls a').index(this);
		sliderProdotti.goToSlide(thumbIndex);
		$('#prodotti .controls a').show();
		$(this).hide();
		return false;
	});
}



function SliderCaseHistory(){
	$("#casehistorySlide").bxSlider({
		wrapperClass: 'casehistory_slider',
		auto_controls: false,
		pager:false,
		infiniteLoop:false,
		nextText:' NEXT >',
		prevText:'< PREV '
	});
}


function SliderAwards(){
	$("#awardsSlide").bxSlider({
		wrapperClass: 'awards_slider',
		auto_controls: false,
		pager:false,
		infiniteLoop:false,
		nextText:' NEXT >',
		prevText:'< PREV '
	});
}



function SliderTeam(){
	var sliderTeam = $("#teamSlide").bxSlider({
		wrapperClass: 'team_slider',
		auto_controls: false,
		pager:false,
		infiniteLoop:false,
		controls:false
	});

	$('#team #teamThumbs a').live("click", function(){
		var thumbIndex = $('#team #teamThumbs a').index(this);
		sliderTeam.goToSlide(thumbIndex);
		$('#team #teamThumbs a').removeClass("active");
		$(this).addClass("active");
		return false;
	});


	$('#team .controls a').live("click", function(){
		
		var thumbTot = $('#team #teamThumbs a').length-1;
		var thumbIndex = $('#team #teamThumbs a.active').index();
		var controlAct = $('#team .controls a').index(this);
		if(controlAct==0){
			if(thumbIndex !=0){
				sliderTeam.goToSlide(thumbIndex-1);
				$('#team #teamThumbs a').removeClass("active");
				$('#team #teamThumbs a').eq(thumbIndex-1).addClass("active");
			}
		}
		if(controlAct==1){
			if(thumbIndex != thumbTot){
				sliderTeam.goToSlide(thumbIndex+1);
				$('#team #teamThumbs a').removeClass("active");
				$('#team #teamThumbs a').eq(thumbIndex+1).addClass("active");
			}
		}
		return false;
	});
}


function CaseHistoryLayer()
{
	
	$("a.openLayer").colorbox({
		inline:true, 
		href:"#CaseHistoryLayer",
		onOpen:function(){ 
		
			CaseHistory = $(this).attr("id");
		
			$("#CaseHistoryLayer").empty();
			$("#CaseHistoryLayer").append('<div class="title">'+$("#Item"+CaseHistory).children('.category').text()+'</div>');
			$("#CaseHistoryLayer").append('<div class="video"><object width="640" height="360"><param name="movie" value="http://www.youtube.com/v/'+$("#Item"+CaseHistory).children('.video').text()+'?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+$("#Item"+CaseHistory).children('.video').text()+'?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="360"></embed></object></div>');
			$("#CaseHistoryLayer").append('<div class="text"><h1>'+$("#Item"+CaseHistory).children('.title').text()+'</h1><div class="shareCaseHistory"><a href="'+$("#Item"+CaseHistory).children('.flickr').text()+'" target="_blank"><img src="/res/img/flickr_16.png" border="0" alt="Vai a Flickr" title="Vai a Flickr" /></a><a href="http://www.facebook.com/sharer.php?u=http://www.show-reel.it" target="_blank"><img src="/res/img/facebook_16.png" border="0" alt="Condividi su Facebook" title="Condividi su Facebook" /></a><a href="http://twitter.com/share?url=http://www.show-reel.it" target="_blank"><img src="/res/img/twitter_16.png" border="0" alt="Condividi su Twitter" title="Condividi su Twitter" /></a></div><h2>'+$("#Item"+CaseHistory).children('.client').text()+'</h2><p>'+$("#Item"+CaseHistory).children('.text').html()+'</p></div>');
			
			$("#CaseHistoryLayer").show();
		
		},
		onCleanup:function(){ 
			$("#CaseHistoryLayer").hide();
		}
	})


}


function AwardsLayer()
{
	
	$("a.openLayerAwards").colorbox({
		inline:true, 
		href:"#AwardsLayer",
		onOpen:function(){ 
		
			AwardsLayer = $(this).attr("id");
		
			$("#AwardsLayer").empty();
			$("#AwardsLayer").append('<div class="title">'+$("#Item"+AwardsLayer).children('.category').text()+'</div>');
			$("#AwardsLayer").append('<div class="image"><img src="/image.php?src=/media/images/awards/'+$("#Item"+AwardsLayer).find('.image').text()+'&w=500&h=360" /></div>');
			$("#AwardsLayer").append('<div class="text"><h1>'+$("#Item"+AwardsLayer).children('.title').text()+'<br />'+$("#Item"+AwardsLayer).children('.year').text()+'</h1><h2>Progetto: '+$("#Item"+AwardsLayer).children('.client').text()+'</h2><p>'+$("#Item"+AwardsLayer).children('.text').html()+'</p>'+$("#Item"+AwardsLayer).children('.links').html()+'</div>');
			
			$("#AwardsLayer").show();
		
		},
		onCleanup:function(){ 
			$("#AwardsLayer").hide();
		}
	})


}



function SliderPartners(){
	$("#partnersSlide").bxSlider({
		wrapperClass: 'partners_slider',
		auto_controls: false,
		pager:false,
		infiniteLoop:false,
		nextText:' NEXT >',
		prevText:'< PREV '
	});
}



function SliderContacts(){
	$("#contactsSlide").bxSlider({
		wrapperClass: 'contacts_slider',
		auto_controls: false,
		pager:false,
		infiniteLoop:false,
		nextText:' NEXT >',
		prevText:'< PREV'
	});
}


function FasceOpen(){
	$("#openFindUs").live("click", function(){
		$("#fasciaFindUs").animate({right:0}, 350);									  
		$("#openFindUs").hide();									  
		$("#closeFindUs").show();									  
		return false;										  
	});

	$("#closeFindUs").live("click", function(){
		$("#fasciaFindUs").animate({right:-240}, 350);									  
		$("#openFindUs").show();									  
		$("#closeFindUs").hide();									  
		return false;										  
	});


	$("#openShare").live("click", function(){
		$("#fasciaShare").animate({right:0}, 350);									  
		$("#openShare").hide();									  
		$("#closeShare").show();									  
		return false;										  
	});

	$("#closeShare").live("click", function(){
		$("#fasciaShare").animate({right:-240}, 350);									  
		$("#openShare").show();									  
		$("#closeShare").hide();									  
		return false;										  
	});

}
