// JavaScript Document
var current_promo = 0;
var interval;
var lst_promo_pdf = [];
$(document).ready(function () {
	
	$(window).scroll(function () { 
		var position = $(window).scrollTop();
		
		if (position > 129){
			$('#box_cart').css('top', position+'px');
			/*$('#box_cart').animate({
				top: position
			}, 1, function() {
				// Animation complete.
			  });*/
		}else if (position < 129){
			
			$('#box_cart').css('top', '129px');			
		}
		/*
		if (position > 129){
			$('#box_cart').addClass('box_cart_fix');
		}else if (position < 129){
			
			$('#box_cart').removeClass('box_cart_fix');		
		}
		*/
    });

	$('#navigation-categories li.first:last').addClass('last');

	$('#navigation-categories li.first').mouseenter(function(){
		var top = 0;		
		var position = $(this).position();
		var nb_li = $('#navigation-categories li.first').length;
		var nb_place = nb_li - $(this).attr('rel');

		if (position.top - 30 > 0) top = position.top;

		//alert($(this).children('ul').children('li').length + ' -- ' + nb_place);
		if ($(this).children('ul').hasClass('small_menu')){
			if ($(this).children('ul').children('li').length > nb_place){
				over = $(this).children('ul').children('li').length - nb_place;
				over_place = over*143;
				$(this).children('ul').css({'top': 'inherit'});
				$(this).children('ul').css({'bottom': '0px'});
				
			}else{
				$(this).children('ul').css('top', top+'px');

			}
			
		}else if($(this).children('ul').children('li').length > 0){
			$('#backmenu').show();
			if ($(this).children('ul').children('li').length > 4){
				$(this).children('ul').css({'top': '0px'});
			}else if($(this).attr('rel') > 4){
				$(this).children('ul').css({'top': '145px'});
	
			}else{
				$(this).children('ul').css('top', top+'px');
			}
			
			
		}
		$(this).children('a').addClass('actif');
		$(this).children('ul').show();
		
	}).mouseleave(function(){
		$('#backmenu').hide();
		$(this).children('ul').hide();
		$(this).children('a').removeClass('actif');
	});
	
	$('#navigation-categories li.first').mouseleave();

	$(".zoom").fancybox({
		'titleShow'     : true,
		'titlePosition'  : 'over'

	});
	
	$("a[rel=group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
	});


	$('a.item').each(function() {
		 $(this).qtip(
		  {
			  content: {
				text: (($(this).attr('body')) ? $(this).attr('body') : $(this).attr('title')), 
				title: {
					text: (($(this).attr('body')) ? $(this).attr('title') : '')
				}
			},
	
			 position: {
				at: 'top center', // Position the tooltip above the link
				my: 'bottom center',
				viewport: $('#box_slider')
	
			 },
			 show: {
			   // event: 'click mouseenter',
				solo: true // Only show one tooltip at a time,
			 },
			 hide: {
				//event: 	'unfocus'
			 },
			 style: {
				  classes: 'ui-tooltip-'+box_color+' ui-tooltip-'+box_style+''
				},
				events: {
				  show: function(e, api)
				  {
					 $('#promotions').cycle('pause');
				  },
				  hide: function(e, api)
				  {
					 $('#promotions').cycle('resume');
				  }
			   }     
		  });
	 });
	
	$("input.focus").focus(function () {
        if (this.value == this.defaultValue) {
            this.value = "";
        }
        else {
            this.select();
        }
    });

    $("input.focus").blur(function () {
        if ($.trim(this.value) == "") {
            this.value = (this.defaultValue ? this.defaultValue : "");
        }
    });

	$('#promotions').cycle({
	    fx:     			'scrollHorz',
	    next:   			'#fleche-droite',
	    prev:   			'#fleche-gauche',
	    pager:				'div#nav-promotions ul',
	    activePagerClass:	'actif',
	    pagerAnchorBuilder: function(idx, slide) { 
	        // return selector string for existing anchor 
			//alert($('div#nav-promotions li:eq(' + idx + ') a').length);
			return 'div#nav-promotions li:eq(' + idx + ') a';
	    },
	    timeout:  	5000
	});

	/*$('div#nav-promotions ul li').click(function() { 
	    $('#promotions').cycle($(this).index());
	    return false; 
	});*/
/*
	$('#fleche-gauche').click(function(){
					  
	});
	
	$('#fleche-droite').click(function(){
					  
	});*/
	
});

function checksubmit(){
	if($('#fldsearch').val() != '') return true;
	else return false;
}
