/* Author: Oscar Chinellato

*/

$(document).ready(function() {
	
	if(launchCarousel) {
		var original = $('.slides').clone();
		var carouselCurrent = 0;
		
		$('.carousel').carousel({
			hAlign:'center', 
			vAlign:'bottom', 
			hMargin:1.0, 
			vMargin:0.2, 
	        frontWidth:250, 
			frontHeight:400, 
			carouselWidth:940, 
			carouselHeight:450, 
			left:0, 
			right:0, 
			top:0, 
			bottom:0, 
			backZoom:0.6, 
			slidesPerScroll:5, 
			speed:500, 
			buttonNav:'none', 
			directionNav:false,
			autoplay:true, 
			autoplayInterval:5000, 
			pauseOnHover:true, 
			mouse:true, 
			shadow:true,
			reflection:true, 
			reflectionHeight:0.2, 
			reflectionOpacity:0.5, 
			reflectionColor:'0,0,0', 
			description:false, 
			descriptionContainer:'.description', 
		   	before: function(carousel){}, 
			after: function(carousel){
				carouselCurrent = carousel.current;
			}
		});
		
		if(!homeCollection) {
			$('.slides div a').click(function(evt) {
				var link = $(original).find('div').eq(carouselCurrent).find('a');
				if($(evt.target).attr('src') == link.find('img').attr('src')) {
					evt.preventDefault();
					Chainsport.loadShoe(link.attr('rel'));
					$('.carousel').slideUp(1000);
				}	
			});
		}
		
		
	}	

	
	if(slideUpShoe) {
		$('.carousel').slideUp(1000);
		$('.top-link').click(function(evt) {
			evt.preventDefault();
			$('.carousel').slideDown(1000);
		})
		$('a[rel=shoe-thumbs-lightbox]').lightBox({
			imageLoading: '/static/img/lightbox/lightbox-ico-loading.gif',
			imageBtnClose: '/static/img/lightbox/lightbox-btn-close.gif',
			imageBtnPrev: '/static/img/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/static/img/lightbox/lightbox-btn-next.gif',
		})
	}
	
	if(launchSlider) {
		$( '#slider' ).lateralSlider({
			displayDuration: 4000
		});
	}
	
	if(tecnicaMap) {
		$(function() {
			var coords = $('#tecnica-top-panel').offset();
			$('#tecnica-top-panel a').each(function() {
				$(this).css( {
					left : parseInt($(this).css('left')) + coords.left + 180,
					top : parseInt($(this).css('top')) + coords.top - 25
				})
			})
		});
		
		$(function() {
			$('a[rel=popover]').popover({
				html: true
			})
			.click(function(e) {
				e.preventDefault();
			});
		});
	}
	if(merchGallery) {
		$('a[rel=merch]').lightBox({
			imageLoading: '/static/img/lightbox/lightbox-ico-loading.gif',
			imageBtnClose: '/static/img/lightbox/lightbox-btn-close.gif',
			imageBtnPrev: '/static/img/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/static/img/lightbox/lightbox-btn-next.gif',
		});
	}
	if(home) {
		$('#email').focus(function() {
			$('.captcha-container').slideDown();
		});
	}
	
});



var Chainsport = {
	loadShoe : function(id) {
		$.post('/' + lang + '/collezioni/shoe/'+ (parseInt(id)) , '', function(data) {
			$('#collection-showcase')[0].innerHTML = data.view;
			$('a[rel=shoe-thumbs-lightbox]').lightBox({
				imageLoading: '/static/img/lightbox/lightbox-ico-loading.gif',
				imageBtnClose: '/static/img/lightbox/lightbox-btn-close.gif',
				imageBtnPrev: '/static/img/lightbox/lightbox-btn-prev.gif',
				imageBtnNext: '/static/img/lightbox/lightbox-btn-next.gif',
			})
			$('.top-link').click(function(evt) {
				evt.preventDefault();
				$('.carousel').slideDown(1000);
			})
		}, 'json');
	}
}

function removeFlash() {
	$('#flash-container').detach();	
	$.post('/it/main/homeslider', '', function(data) {
		$('#slider')[0].innerHTML = data.view + " " +  $('#slider')[0].innerHTML;
		$('#slider h4').css({
			top: -250
		})
		$('#home-slider').fadeIn(400, function() {
			$('#slider h4').fadeIn();
		});
	}, 'json');
}























