// JavaScript Document

/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */

jQuery(document).ready(function() {

	//Home CYCLE BANNIERE
	$('#slider_intro ul').cycle({
	    fx:     'fade',
	    speed:  500,
	    timeout: 1000,
	    nowrap: true,
	    end: function() {
		$('.jcarousel-control:not(.jcarousel-control2) .btn-default-1').trigger('click');
	      $('#slider_intro').fadeOut(1000);
	      showSecondSlider();
	    }
	});
	
	$('.jcarousel-control2 a').one('click', function() {
	  var self = this;
		showSecondSlider();$('.jcarousel-control:not(.jcarousel-control2) .btn-default-' + self.title).trigger('click');
		$('#slider_intro').fadeOut(1000);	  
	});

	jQuery("#homeConfortCarousel").jcarousel({
		scroll: 3,
		initCallback: function (carousel) {
			carousel.clip.hover(function() {
				carousel.stopAuto();
			}, function() {
				carousel.startAuto();
			});
		
			// home-header-holder hover behaviors
			$('.home-header-holder').hover(function() {
				carousel.stopAuto();
				$(this).children('.home-header-btn').addClass('active');
				$(this).siblings().children('.home-header-btn').removeClass('active');
				$(this).children('.home-header-content').css({ visibility: 'visible' });
				$(this).children('.home-header-content').show();
				$(this).siblings().children('.home-header-content').hide();
			},function() {
				carousel.startAuto();
				$(this).children('.home-header-btn').removeClass('active');
				$(this).children('.home-header-content').hide();
				$(this).siblings('div:first').children('.home-header-content').show();
			});
		}
	});

	// Using hide method at his point makes Chrome returning an error
	// So first just set visibility to hidden so that it has time to load the carousel
	$('.home-header-holder > .home-header-content').css({ visibility: 'hidden' });
});

function showSecondSlider()
{
	$('#homeMainCarousel').fadeIn(1000);
	
  $("#homeMainCarousel ul").cycle({
    fx:     'scrollHorz',
    speed:   1000,
    timeout: 6000,//5000,
    activePagerClass: 'active',
    pager: '.jcarousel-control:not(.jcarousel-control2)',
    pagerAnchorBuilder: function(idx, slide) {
    	return '.jcarousel-control:not(.jcarousel-control2) .btn-default-' + (idx + 1);
    } 
	});
}
