function look() {
	
	if ( $(window).width() < 1200 ) {
		$('.mozaic_look').addClass('w1024');
	}
	
	var voir_look = $('<img />').attr('src','/themes/prestashop_new/img/look/btn_voir_look.png').addClass('voir_look');	
	
	$('.mozaic_look a').mouseenter(function(){
		$('.mozaic_look a').not($(this)).stop(true).fadeTo(500, 0.5);
		
		voir_look.insertBefore($(this).find('img')).css({
			top: ($(this).height()/2)
		}).fadeTo(1000, 1);
		
		$(this).stop(true).fadeTo(500, 1).addClass('active');
	});
	
	$('.mozaic_look a').mouseleave(function(){
		$('.voir_look').remove();
		$('.mozaic_look a').fadeTo(500, 1);
	});
	
	$('.voir_look').live('click',function(){
		$(this).parent().trigger('click');
	});
}

function navigation(){
	
	$('#categories_block_left li:not(#categories_block_left ul li)').mouseenter(function(){		
		if( $(this).is('.menu_main') ) {
			$(this).css('backgroundColor','#808080');
			$(this).find('a').css('color','#fff');
			$(this).find('ul').show();
		}
	});
	$('#categories_block_left li:not(#categories_block_left ul li)').mouseleave(function(){
		if( $(this).is('.menu_main') ) {
			$(this).removeAttr('style');
			$(this).find('a').removeAttr('style');
			$(this).find('ul').hide();
		}
	});
	
	if($.browser.msie){
		$('#categories_block_left .menu_main ul').css('padding','10px').width(616);
		$('#categories_block_left .menu_main ul').each(function(){
			$(this).find('li:odd:not(.offre_du_moment)').css('margin','0 220px 0 0')
		});
	}
	
}



function slideThumb(){
	if( $('.autres_vues ul').height() > $('.autres_vues').height() ) {	
			
		$('.autres_vues .gotostart').mouseenter(function(){
			if( parseInt($('.autres_vues ul').css('top')) < 0 ) {										
				$('.autres_vues ul').animate({top:0}, countSpeed(0) )
			}
		});
		$('.autres_vues .gotoend').mouseenter(function(){
			if( parseInt($('.autres_vues ul').css('top')) <= 0 ) {										
				$('.autres_vues ul').animate({top: -($('.autres_vues ul').height()-$('.autres_vues').height()) }, countSpeed(-($('.autres_vues ul').height()-$('.autres_vues').height())) )
			}
		});
		$('.autres_vues .gotostart,.autres_vues .gotoend').mouseleave(function(){
			$('.autres_vues ul').stop(true,false);
			if( parseInt($('.autres_vues ul').css('top')) == 0 ) {
				$('.autres_vues .gotostart').css({color:'#ddd',cursor:'default'});
			} else {
				$('.autres_vues .gotostart').css({color:'#4e4e4e',cursor:'pointer'});
			}
			if( parseInt($('.autres_vues ul').css('top')) == -($('.autres_vues ul').height()-$('.autres_vues').height()) ) {
				$('.autres_vues .gotoend').css({color:'#ddd',cursor:'default'});
			} else {
				$('.autres_vues .gotoend').css({color:'#4e4e4e',cursor:'pointer'});
			}
		});
	} else {
		$('#product .autres_vues').css({padding:0,height:657});
		$('.autres_vues .gotostart,.autres_vues .gotoend').remove();
	}
}
function countSpeed(destination) {
	var posUl = parseInt($('.autres_vues ul').css('top'));
	
	var speed = Math.abs(Math.abs(destination)-Math.abs(posUl));
	return (speed*2);
}


function ZoomFiche() {
	// Update visuel
	$('#product .autres_vues img').live('mouseenter', function (){
		var visuel_principal = $(this).closest('a').attr('href');
		$('#product .visuel a').attr('href',visuel_principal);
		visuel_principal = visuel_principal.replace('thickbox','very_large');
		$('#product .visuel a img').attr('src',visuel_principal);
		return false;
	});
	
	// SuperZoom
	$('#product .visuel img, #product .autres_vues img').live('click', function (){
    	$('body').data('scrolltop', $(window).scrollTop());
    	if( $(this).is('#product .autres_vues img')) {
			urlZoom = $(this).closest('a').attr('href');
		} else {
			urlZoom = $(this).attr('src');
		}
		if ($(window).width() >= 1200) {
			var widthImg = 1200;
		} else {
			var widthImg = $(window).width();
		}

		htmlZoom = $('<img>').attr('src', urlZoom).width(widthImg).height('auto').css('marginLeft',-(widthImg/2));
		
		if($.browser.msie){
			$('html').css('overflow', 'hidden');
		} else {
			$('body').css('overflow', 'hidden');
		}

		$('<div>').addClass('ZoomBox').css({
			width: $(window).width(),
			height: $(window).height(),
			background: '#fff',
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex: 15
		}).html(htmlZoom).append('<a href="#" class="close">FERMER <img src="/themes/prestashop_new/img/icon/btn_deco2.png" alt="" /></a>').appendTo('body');

		$('.ZoomBox').sliding(widthImg);
	
		$('.ZoomBox').click(function () {
			$(this).fadeOut(500, function () {
				$(this).remove()
			});
		
			if($.browser.msie){
				$('html').css('overflow', '');
			} else {
				$('body').css('overflow', '');
			}
			
			$(window).scrollTop($('body').data('scrolltop'));
		});
		return false;
	});
	
}
// Zoom
(function($) {
  //Définition du plugin
  $.fn.sliding = function(widthImg) {

    container = $(this);
    content = $(this).find("img:first");

    var defaults =
    {
      containerHeight : $(window).height(),
      contentWidth : $(window).width(),
      contentHeight : $('.ZoomBox img:first').height()
    }
    var options =
    {
      contentWidth : widthImg
    }
    var opt = $.extend(defaults, options);



	function superZoom(){
		$(document).scrollTop(0);
		$('.ZoomBox img').load(function(){
		
			opt.contentHeight = $('.ZoomBox img:first').height();
			var overflowed = opt.contentHeight - opt.containerHeight;
			
			container.bind("mousemove",function(e){
				newPosition = (e.pageY/opt.containerHeight);
				newPosition = newPosition*overflowed*(-1);
				$('.ZoomBox img:first').css('top',newPosition);
			
			});
			
			container.bind("click",function(){
				container.fadeOut(500,function(){ $(this).remove() });
			});
		});
	}

    $(this).each(superZoom);
    // interface fluide
     return $(this);
  };
})(jQuery);

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
