$(document).ready(function(){
	// Remove class no-js for non-intrusive js
    $("a,div,ul,button,label").removeClass("no-js");
	// Add class no-js for a11y
	$(".js").removeClass("js").addClass("no-js");

	// Put a label into a search input
	if (typeof addPlaceHolder == 'function') { addPlaceHolder(); }
	// End label search

	// Print
	if (typeof printJS == 'function') { printJS(); }
	// End Print

	// Go to the top
	if (typeof goOnTheTop == 'function') { goOnTheTop(); }
	// End go to the top

	/* Slideshow */
	if ($('#photo').length && (typeof ($.fn.carousel) == 'function')) {
		
		$("#photo").carousel({
			direction: "vertical",
			dispItems: 1,
			pagination: true,
                        autoSlide: true,
			paginationPosition: "outside",
			tabLabel: function (tabNum) {
				if (!(
					typeof(paginationLabel) == 'object' 
					&& paginationLabel.length
					)) 
					paginationLabel = new Array("", "", "", "", "");
				return paginationLabel[tabNum-1]; 
			},
			nextBtn: '',
			prevBtn: '',
                        autoSlide: true,
                        autoSlideInterval: 5000
		});
	}
	
	/* Diaporama */
	if ($('#diaporama').length && (typeof ($.fn.jcarousel) == 'function')) {
		$('#diaporama').css('overflow', 'hidden');
		$('#diaporama').jcarousel({
			scroll: 1,
                        auto: 3,
	        visible: 1
	    });
	}

	/* Colorbox on Product item detail */
	if ($("a[rel='colorbox']").length && (typeof ($.fn.colorbox) == 'function')) {
		$("a[rel='colorbox']").colorbox({transition:"fade", width:"75%", height:"600px"});
	}
	
	/* Tabs */
	if ($('#tabs').length && (typeof ($.fn.tabs) == 'function')) {
		$("#tabs").tabs();
	}
        $('#search_query_top').click(function(){
            if($(this).val()=='Recherche') $('#search_query_top').val('');
        })
        
/*        $('#cart_block').hover(
            function()
            {
                var h=parseInt($('#cart_block_list').height())+'px';
                $("#cart_block_contenu").stop().animate({height:h},{queue:false,duration:500,easing:'easeOutBounce'});
            },
            function()
            {
                $("#cart_block_contenu").stop().animate({height:0},{queue:false,duration:500});
            }
        );
*/       
});

// Print
function printJS() {
	if ($('a.print').length) {
		$('a.print').click(function(){
			print();
			return false;
		});
	}
}
// End Print

// Go on the Top
function goOnTheTop() {
	$('.top').click(function() {
		$('html, body').animate({scrollTop: 0}, 'slow');
		return false;
	});
}
// End Go on the Top

/* PLACEHOLDER */
function addPlaceHolder() {
	var inputPlaceholder = $('input.placeholder');
	if(inputPlaceholder.length) {
		var oldInputPlaceholderValue = "";
		var nameInput = "";
		inputPlaceholder.each(function() {
			if ($(this).val() == "") {
				nameInput = $(this).attr('name');
				$('label').each(function() {
					if ($(this).attr("for") == nameInput ) {
						oldInputPlaceholderValue = $(this).html();
					}
				});
				$(this).val(oldInputPlaceholderValue).addClass('placeholder-disabled');
			}
			else {
				oldInputPlaceholderValue = $(this).val();
			}
		});
		inputPlaceholder.focus(function() {
			nameInput = $(this).attr('name');
				$('label').each(function() {
					if ($(this).attr("for") == nameInput ) {
						oldInputPlaceholderValue = $(this).html();
					}
				});
			if ($(this).val() == oldInputPlaceholderValue) {
				$(this).removeClass('placeholder-disabled').val('');
			}
		}).blur(function() {
			if ($(this).val() == '') {
				$(this).addClass('placeholder-disabled').val(oldInputPlaceholderValue);
			}
		});
	}
}
/* END PLACEHOLDER */

function isArray(obj) {
	return obj.constructor == Array;
}

