$(function() {
	
	var ua = navigator.userAgent.toLowerCase();
	var myBrowsers = {
		mozilla: $.browser.mozilla,
		safari:  $.browser.safari,
		opera:   $.browser.opera,
		ie:      $.browser.msie,
		ie6:     $.browser.msie && ($.browser.version < 7),
		ie7:     $.browser.msie && ($.browser.version == 7),
		ie8:     $.browser.msie && ($.browser.version > 7),
		iphone:  /iphone/.test(ua),
		chrome:  /chrome/.test(ua),
		firefox: /firefox/.test(ua),
		webkit:  /webkit/.test(ua),
		osx:     /mac os x/.test(ua),
		win:     /win/.test(ua),
		linux:   /linux/.test(ua)
	};
	
	$.each(myBrowsers, function(a, b) {
		
		if (b) {
			$('html').addClass(a);
		}
		
	});
	
	$('.menu-arrow_current').css({
		left: getPositionArrowMenu()
	});
	
	$('#menu > ul > li').not('.menu-search2').mouseenter(function() {
		
		$('.menu-arrow_current').stop().animate({
			left: getPositionArrowMenu($(this))
		}, 'slow');
		
	}).mouseleave(function() {
		
		$('.menu-arrow_current').stop().animate({
			left: getPositionArrowMenu()
		}, 'slow');
		
	});
	
	if ($('#bloc-404').length) {
		
		$('body').addClass('page_404');
		
	}
	
	if ($('p.checkbox').length != 0) {
		
		$('p.checkbox').each(function() {
			
			var $this = $(this);
			var hidden = $('input', $this);
			
			if (hidden.val() == '1') {
				$this.addClass('checkbox-on');
			} else {
				$this.addClass('checkbox-off');
			}
			
		});
		
		$('p.checkbox').click(function(e) {
			
			e.preventDefault();
			
			var $this = $(this);
			var hidden = $('input', $this);
			
			if ($this.hasClass('disabled')) {
				return false;
			}
			
			if ($this.hasClass('checkbox-on')) {
				$this.removeClass('checkbox-on');
				
				hidden.val('0');
			} else {
				$this.addClass('checkbox-on');
				
				hidden.val('1');
			}
			
		});
		
	}
	
	if ($('#newsletter_messages').length != 0) {
		
		$('#newsletter_messages_footer').html($('#newsletter_messages'));
		
	}
	
	if ($('#list_products').length != 0) {
		
		$('.list_products-menu-list_marques').scrollBrands();
		
		$('.list_products-menu-categories').each(function() {
			
			var $this = $(this);
			
			$('.list_products-menu-categories-child li.current', $this).parent().parent().addClass('current');
			
			$('.list_products-menu-categories-child2 li.current', $this).parent().parent().addClass('current').parent().parent().addClass('current');
			
			$('> li > a', $this).click(function(e) {
				
				e.preventDefault();
				
				if (!$(this).parent().hasClass('current')) {
					$(this).next().slideToggle();
				}
				
			});
			
			$('.list_products-menu-categories-child > li').mouseenter(function(e) {
				
				e.preventDefault();
				
				var list = $('ul', this);
				
				if (list.length != 0) {
					if (list.hasClass('animated')) return;
					
					$('.list_products-menu-categories-child > li > ul').not(list).slideUp();
					
					list.addClass('animated').slideDown(function() {
						list.removeClass('animated');
					});
				}
				
			});
			
		});
		
		if ($('.list_products-menu-filter').length != 0) {
			
			$('.list_products-menu h1').after($('.list_products-menu-filter'));
			
		}
		
		if ($('.menu-homme').hasClass('menu-current')) {
			$('#list_products').addClass('list_products-homme');
		}
		
		if ($('.menu-femme').hasClass('menu-current')) {
			$('#list_products').addClass('list_products-femme');
		}
		
		if ($('.menu-marques').hasClass('menu-current')) {
			$('#list_products').addClass('list_products-marques');
		}
		
		if ($('.menu-junior').hasClass('menu-current')) {
			$('#list_products').addClass('list_products-junior');
		}
		
		$('.list_products-content-list-item-image').mouseenter(function() {
			
			var $this = $(this);
			var item = $this.parent();
			var apercu = $('.list_products-content-list-item-apercu', item);
			
			if (apercu.is(':hidden')) {
				
				if ($.browser.msie) {
					apercu.show();
				} else {
					apercu.stop().css('opacity', 0).show().animate({
						opacity: 1
					}, 'slow');
				}
				
			}
			
			item.mouseleave(function(e) {
				
				if ($.browser.msie) {
					apercu.hide();
				} else {
					apercu.stop().animate({
						opacity: 0
					}, 'slow', function() {
						apercu.hide();
					});
				}
				
			});
			
		});
		
		if ($('.list_products-menu').height() < $('.list_products-center').height()) {
			
			var height = $('#list_products').height() - 29;
			
			$('.list_products-menu').height(height);
			
		}
		
	}
	
	if ($('.home-scrollable-marques-content-scrollable-item').length != 0) {
		
		var marques_items = $('.home-scrollable-marques-content-scrollable-items');
		
		$('.home-scrollable-marques-content-scrollable').infiniteCarousel({
			inView: 6,
			transitionSpeed: 600,
			displayProgressBar: false,
			displayThumbnails: false,
			displayThumbnailNumbers: false,
			displayThumbnailBackground: false,
			enableKeyboardNav: false,
			easeLeft: 'swing',
			easeRight: 'swing'
		});
		
		$('.home-scrollable-marques-content-nav_left').click(function(e) {
			
			e.preventDefault();
			
			$('.home-scrollable-marques-content-scrollable > div:last').trigger('click');
			
		});
		
		$('.home-scrollable-marques-content-nav_right').click(function(e) {
			
			e.preventDefault();
			
			$('.home-scrollable-marques-content-scrollable > div:last').prev().trigger('click');
			
		});
		
		$('.home-scrollable-marques-content-scrollable-item').delegate('a', 'mouseenter', function() {
			
			var $this = $(this);
			var img = $('img', $this);
			var img_src = img.attr('src');
			var img_rel = img.attr('rel');
			
			img.attr('src', img_rel).attr('rel', img_src);
			
		});
		$('.home-scrollable-marques-content-scrollable-item').delegate('a', 'mouseleave', function() {
			
			var $this = $(this);
			var img = $('img', $this);
			var img_src = img.attr('src');
			var img_rel = img.attr('rel');
			
			img.attr('src', img_rel).attr('rel', img_src);
			
		});
		
	}
	
	if ($('#product_details').length != 0) {
		
		eventsProductDetails();
		
	}
	
	if ($('#cart').length != 0) {
		
		$('.cart-middle-content-items tr:last td').css('border-bottom', '10px solid #eaeaea');
		
		$('.col-qty-content-inc').click(function(e) {
			
			e.preventDefault();
			
			var $this = $(this);
			var span = $this.parent().find('span');
			var input = $this.parent().parent().find('input');
			var new_val = parseInt(input.val()) + 1;
			
			input.val(new_val);
			span.text(new_val);
			
			var form = $this.closest('form');
			
			form.submit();
			
		});
		
		$('.col-qty-content-dec').click(function(e) {
			
			e.preventDefault();
			
			var $this = $(this);
			var span = $this.parent().find('span');
			var input = $this.parent().parent().find('input');
			
			if (input.val() <= 0) {
				return false;
			}
			
			var new_val = parseInt(input.val()) - 1;
			
			input.val(new_val);
			span.text(new_val);
			
			var form = $this.closest('form');
			
			form.submit();
			
		});
		
		$('.cart-middle-content-foot-coupon a.discount-coupon-form-remove').click(function(e) {
			
			e.preventDefault();
			
			var $this = $(this);
			var form = $this.closest('form');
			
			form.find('input[type=hidden]').val('1');
			form.submit();
			
		});
		
	}
	
	if ($('#cart_onepage').length != 0) {
		
		function loadProgress(callback) {
			var callback = callback || $.noop;
			
			$('.cart_onepage-menu-content div').load(PROGRESS_URL, function() {
				
				Cufon.refresh();
				
				callback();
				
			});
		}
		
		loadProgress();
		
		$('#billing-form, #shipping-form, #shipping-method-form, #co-payment-form, #review-form').submit(function(e) {
			
			e.preventDefault();
			
			var $this = $(this);
			var step_current = $('.step-current');
			var step_current_content = $('.cart_onepage-step', step_current);
			var overlay = $('<div />').addClass('overlay').css({
				height: step_current_content.height(),
				width: step_current_content.width(),
				position: 'absolute',
				background: '#eaeaea',
				opacity: .8,
				top: step_current_content.position().top,
				left: step_current_content.position().left + 28
			});
			
			if (this.id == "review-form")
			{
				overlay.html("<div style='padding:20px 0 0 200px'><img src='/skin/frontend/urbansurfers/default/img/ajax-loader.gif' /><br /><span style='font-weight:bold'>Merci de patienter durant la validation de votre commande.<br />Cette étape peut durer jusqu'à 1 minute.</span><div>");
			}
			
			$this.append(overlay);
			
			var inputs = [];
			
			$this.find('input[type=text], input[type=hidden], select').each(function() {
				
				if ($(this).val() != '') {
					inputs.push($(this).attr('name') + '=' + encodeURIComponent($(this).val()));
				}
				
			});
			
			$this.find('input[type=radio]').each(function() {
				
				if ($(this).val() != '' && $(this).is(':checked')) {
					inputs.push($(this).attr('name') + '=' + encodeURIComponent($(this).val()));
				}
				
			});
			
			var last_step = false;
			
			if ($(e.target).attr('id') == 'review-form') {
				$('#co-payment-form :input').each(function() {
					
					if ($(this).val() != '' && $(this).is(':checked')) {
						inputs.push($(this).attr('name') + '=' + encodeURIComponent($(this).val()));
					}
					
				});
				
				last_step = true;
			}
			
			$.ajax({
				type: $this.attr('method'),
				dataType: 'json',
				url: $this.attr('action'),
				data: inputs.join('&'),
				success: function(response) {
					
					if (response.goto_section != undefined && !last_step) {
						Cufon.refresh();
						
						loadProgress();
						
						if (response.update_section != undefined) {
							$('#' + response.update_section.name + '-form .cart_onepage-step-content').html(response.update_section.html);
						}
						
						if (step_current.next().length != 0) {
							step_current.removeClass('step-current');
							step_current.next().addClass('step-current');
						}
						
						if (response.update_section.name == 'payment-method') {
							$('#p_method_atos_standard').trigger('click');
							$('#atos_standard_atos_cc_CB').attr('checked', 'checked');
						}
					} else {
						if (response.redirect) {
							window.location = response.redirect;
							
							return false;
						}
						
						if (response.success) {
							window.location = SUCCESS_URL;
							
							return false;
						}
					}
					
					overlay.remove();
					
				}
			})
			
		});
		
		$('#shipping-form .checkbox').click(function() {
			
			var $this = $(this);
			var form = $this.parent();
			var hidden = $('input[type=hidden]', $this).val();
			
			if (hidden == '1') {
				form.find(':input').each(function() {
					
					var id = $(this).attr('id').split(':')[1];
					
					if ($(':input[id=billing:' + id + ']', '#billing-form').length != 0) {
						$(this).val($(':input[id=billing:' + id + ']', '#billing-form').val());
					}
					
				});
				
				if ($('p.select_adress select', '#billing-form').length != 0) {
					
					if ($('p.select_adress select', '#billing-form').val() != '') {
						form.find('select').val($('select', '#billing-form').val());
						
						$('.cart_onepage-step-content', form).hide();
					} else {
						form.find('select').val('');
						
						$('.cart_onepage-step-content', form).show();
					}
					
				}
			}
			
		});
		
		$('.cart_onepage-step-bottom-left a').click(function(e) {
			
			e.preventDefault();
			
			var step_current = $('.step-current');
			
			step_current.removeClass('step-current');
			step_current.prev().addClass('step-current');
			
		});
		
		if ($('#billing-address-select').length != 0) {
			
			var form_billing = $('#billing-address-select').parent().parent();
			
			$('.cart_onepage-step-content', form_billing).hide();
			
			$('#billing-address-select').prev().find('a').removeAttr('onclick').click(function(e) {
				
				e.preventDefault();
				
				$('.cart_onepage-step-content', form_billing).show();
				
				$('#billing-address-select option:last').attr('selected', 'selected');
				
			});
			
			$('#billing-address-select').removeAttr('onchange').change(function(e) {
				
				e.preventDefault();
				
				if ($(this).val() == '') {
					$('.cart_onepage-step-content', form_billing).show();
				} else {
					$('.cart_onepage-step-content', form_billing).hide();
				}
				
			});
		
		}
		
		if ($('#shipping-address-select').length != 0) {
			
			var form_shipping = $('#shipping-address-select').parent().parent();
			
			$('.cart_onepage-step-content', form_shipping).hide();
			
			$('#shipping-address-select').prev().find('a').removeAttr('onclick').click(function(e) {
				
				e.preventDefault();
				
				$('.cart_onepage-step-content', form_shipping).show();
				
				$('#shipping-address-select option:last').attr('selected', 'selected');
				
				$('#shipping-form .checkbox-on').trigger('click');
				
			});
			
			$('#shipping-address-select').removeAttr('onchange').change(function(e) {
				
				e.preventDefault();
				
				if ($(this).val() == '') {
					$('.cart_onepage-step-content', form_shipping).show();
					
					$('#shipping-form .checkbox-on').trigger('click');
				} else {
					$('.cart_onepage-step-content', form_shipping).hide();
				}
				
			});
			
		}
		
		$('#checkout-payment-method-load dt input').each(function() {
			
			var $this = $(this);
			
			$this.removeAttr('onclick');
			
			$this.click(function(e) {
				
				var dt = $this.parent();
				
				$('#checkout-payment-method-load dd').hide();
				
				dt.next('dd').show().find('fieldset, ul').show();
				
			});
			
		});
	
	}
	
	$('.submit_button').click(function(e) {
		
		e.preventDefault();
		
		var $this = $(this);
		var href = $this.attr('href').split('#')[1];
		var form = $this.closest('form');
		
		if (href != '1' && href != '') {
			form = $('#' + href);
		}
		
		form.submit();
		
	});
	
	$('.bloc_disabled').each(function() {
		
		var $this = $(this);
		
		$this.css('opacity', .1).find(':input').attr('disabled', 'disabled');
		
	});
	
	if ($('.change_password').length != 0) {
		
		$('.change_password').click(function(e) {
			
			var $this = $(this);
			var hidden = $this.find('input');
			
			if (hidden.val() == '1') {
				
				$('.bloc_disabled').each(function() {
					
					var $this = $(this);
					
					$this.removeAttr('style').find(':input').removeAttr('disabled');
					
				});
				
			} else {
				
				$('.bloc_disabled').each(function() {
					
					var $this = $(this);
					
					$this.css('opacity', .1).find(':input').attr('disabled', 'disabled');
					
				});
				
			}
			
		});
	
	}
	
	if ($('ul.messages').length != 0) {
		
		$('div.messages').show();
		
		if ($('.error-msg').length != 0) {
			
			$('div.messages').prepend($('<div />').addClass('messages-errors'));
			
		}
		
		if ($('.success-msg').length != 0) {
			
			$('div.messages').prepend($('<div />').addClass('messages-success'));
			
		}
		
		if ($('.notice-msg').length != 0) {
			
			$('div.messages').prepend($('<div />').addClass('messages-notices'));
			
		}
		
		if ($.trim($('div.messages').text()) == '') {
			$('div.messages').hide();
		}
		
	}
	
	$('.header-append-top-picto3').mouseenter(function() {
		
		$(this).css('background', '#616161').find('a').addClass('current');
		
		Cufon.refresh();
		
		$('.header-append-top-login_box').show();
		
	});
	
	$('.header-append-top-picto1, .header-append-top-picto2').mouseenter(function(e) {
		
		if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'P') {
			
			$('.header-append').trigger('mouseleave');
			
			$('.header-append-top-login_box').hide();
		}
		
	});
	
	$('.header-append-top-login_box').mouseleave(function(e) {
		
		if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'P') {
			
			$('.header-append').trigger('mouseleave');
			
			$('.header-append-top-login_box').hide();
		}
		
	});
	
	$('.header-append').mouseleave(function() {
		
		$('.header-append-top-picto3').removeAttr('style').find('a').removeClass('current');
		
		Cufon.refresh();
		
	});
	
	$('.product_details-left-images ul li:not(.current), .product_details-right-middle-colors ul li.disabled, .product_details-right-middle-sizes ul li.disabled, #menu > ul > li:not(.menu-current) > a').setOpacity(.5);
	$('.list_products-content-list-item-epuise div').setOpacity(.8);
	
	$('.home-bon_plan-item').changeColor('.home-bon_plan-item-img', '.home-bon_plan-colors', '.home-bon_plan-colors-nav_left', '.home-bon_plan-colors-nav_right');
	$('.list_products-content-list-item').changeColor('.list_products-content-list-item-image', '.list_products-content-list-item-colors-list', '.list_products-content-list-item-colors-list-nav_left', '.list_products-content-list-item-colors-list-nav_right');
	
	$('#menu ul li.menu-item').mouseenter(function() {
		
		$('div.menu-content', this).css('z-index', 9999);
		
	});
	
	$('.menu-content .menu-content-left').each(function() {
		
		var $this = $(this);
		var parent = $this.parent();
		
		var max_height = 0;
		
		parent.show();
		
		if ($this.height() < parent.height()) {
			$this.height(parent.height() - 40);
		}
		
		$('.menu-content-left-item', $this).show().each(function() {
			
			if ($(this).height() > max_height) {
				max_height = $(this).height();
			}
			
		});
		
		$('.menu-content-left-item', $this).height(max_height);
		
		parent.removeAttr('style');
		
	});
	
	$.scrollablePubs.init();
	
	if ($('#list_products-brand').length != 0) {
		
		$('#breadcrumb').remove();
		
		$('#list_products-brand .list_products-brand-col').height($('#list_products-brand .list_products-brand-cols').height());
		
		$('.mostimportant-item a').mouseenter(function() {
			
			var $this = $(this);
			var img = $('img', $this);
			var img_src = img.attr('src');
			var img_rel = img.attr('rel');
			
			img.attr('src', img_rel).attr('rel', img_src);
			
		}).mouseleave(function() {
			
			var $this = $(this);
			var img = $('img', $this);
			var img_src = img.attr('src');
			var img_rel = img.attr('rel');
			
			img.attr('src', img_rel).attr('rel', img_src);
			
		});
		
	}
	
	if ($('.list_products-content-list-item-apercu-bottom').length != 0) {
		
		$('.list_products-content-list-item-apercu-bottom span a').click(function(e) {
			
			e.preventDefault();
			
			var $this = $(this);
			
			var div = $('<div />').addClass('apercu').hide();
			var div_close = $('<div />').addClass('apercu_close');
			var load = $('<div />').addClass('load');
			
			div.append(load);
			
			$('body').append(div);
			
			div.overlay({
				oneInstance: false,
				mask: {
					color: '#000',
					loadSpeed: 200,
					opacity: .5
				},
				top: 'center',
				load: true,
				onClose: function() {
					
					div.remove();
					
				}
			});
			
			div_close.click(function() {
				
				div.data('overlay').close();
				
			});
			
			div.load('/ajax_get_product.php?product_id=' + $this.attr('rel') + '&url=' + $this.attr('href'), function() {
				
				Cufon.refresh();
				
				div.append(div_close);
				
				eventsProductDetails();
				
				$('.product_details-right-middle-button-right a').click(function(e) {
					
					load.css('opacity', .5);
					
					div.prepend(load);
					
					var color = $('.product_details-right-middle-colors input').val() || '';
					var size = $('.product_details-right-middle-sizes input').val() || '';
					
					if ($('#message-apercu').length != 0) {
						$('#message-apercu').animate({
							opacity: 0
						}, function() {
							$('#message-apercu').remove();
						});
					}
					
					$.ajax({
						url: '/ajax_add_product_to_cart.php',
						dataType: 'json',
						data: {
							product_id: $this.attr('rel'),
							color: color,
							size: size
						},
						success: function(response) {
							
							if (response.cart != undefined) {
								var text = 'article';
								
								if (response.cart > 1) {
									text += 's';
								}
								
								$('.header-append-cart a').html(response.cart + ' ' + text);
							}
							
							if (response.message != undefined) {
								
								var message = $(response.message).hide().css('z-index', 9999999).width(974).attr('id', 'message-apercu');
								
								$('body').append(message);
								
								message.overlay({
									oneInstance: false,
									load: true,
									top: 'center'
								});
								
							}
							
							if (response.error != undefined) {
								
								var error = $(response.error).hide().css('z-index', 9999999).width(974).attr('id', 'message-apercu');
								
								$('body').append(error);
								
								error.overlay({
									oneInstance: false,
									load: true,
									top: 'center'
								});
								
							}
							
							Cufon.refresh();
							
						},
						complete: function() {
							
							load.remove();
							
							setTimeout(function() {
								
								$('#message-apercu').animate({
									opacity: 0
								}, function() {
									$('#message-apercu').remove();
								});
								
							}, 5000);
							
							$('#message-apercu').add(div).click(function() {
								
								$('#message-apercu').animate({
									opacity: 0
								}, function() {
									$('#message-apercu').remove();
								});
								
							});
							
						}
					});
					
				});
				
			});
			
		})
		
	}
	
	Cufon.replace('.cufon-bebas_neue, #menu > ul > li > a, .home-bon_plan-item-content p, .footer-append-newsletter h4, .header-append-top ul li, .list_products-menu h1, .cart_onepage-menu-content h1, .list_products-menu h2, .list_products-content-list-item-colors-title h6, .list_products-content-list-item h5 span, .list_products-content-list-item-apercu-middle > span, .list_products-content-list-item-apercu-middle-content, div.messages ul.messages li ul li', {
		fontFamily: 'Bebas Neue'
	});
	
});

(function($) {
	
	$.fn.scrollBrands = function() {
		
		var $this = this;
		
		if ($this.length == 0) {
			return false;
		}
		
		var list_marques_ul = $('ul', $this);
		var list_marques_item_height = $('li:first', list_marques_ul).height() * 5;
		var list_marques_count = $('li', list_marques_ul).length / 5;
		
		if (list_marques_count <= 1) {
			$('.list_products-menu-list_marques-nav', $this).hide();
			
			return false;
		}
		
		var list_marques_nav_middle = $('.list_products-menu-list_marques-nav_middle', $this);
		var list_marques_nav_middle_bloc = $('span', list_marques_nav_middle).attr('alt', 1);
		var list_marques_nav_middle_bloc_height_old = list_marques_nav_middle_bloc.height();
		
		var list_marques_nav_top = $('.list_products-menu-list_marques-nav_top', $this);
		var list_marques_nav_bottom = $('.list_products-menu-list_marques-nav_bottom', $this);
		
		var list_marques_nav_middle_bloc_height = (list_marques_nav_middle_bloc_height_old / list_marques_count);
		
		list_marques_nav_middle_bloc.height(list_marques_nav_middle_bloc_height);
		
		list_marques_nav_bottom.click(function(e) {
			
			if (list_marques_nav_middle_bloc.attr('alt') >= Math.ceil(list_marques_count)) {
				return false;
			}
			
			list_marques_nav_bottom.addClass('animate');
			
			list_marques_nav_middle_bloc.attr('alt', parseInt(list_marques_nav_middle_bloc.attr('alt')) + 1);
			
			if ((list_marques_nav_middle_bloc.position().top + list_marques_nav_middle_bloc_height) >= (list_marques_nav_middle_bloc_height_old - (list_marques_nav_middle_bloc_height))) {
				list_marques_nav_middle_bloc.animate({
					top: '+=' + ((list_marques_nav_middle_bloc_height_old - list_marques_nav_middle_bloc.position().top) - list_marques_nav_middle_bloc_height)
				}, 'slow', 'linear');
			} else {
				list_marques_nav_middle_bloc.animate({
					top: '+=' + list_marques_nav_middle_bloc_height
				}, 'slow', 'linear');
			}
			
			moveNav('up', list_marques_item_height, function() {
				list_marques_nav_bottom.removeClass('animate');
			});
			
		});
		
		list_marques_nav_top.click(function(e) {
			
			if (list_marques_nav_middle_bloc.attr('alt') == 1) {
				return false;
			}
			
			list_marques_nav_top.addClass('animate');
			
			list_marques_nav_middle_bloc.attr('alt', parseInt(list_marques_nav_middle_bloc.attr('alt')) - 1);
			
			if ((list_marques_nav_middle_bloc.position().top - list_marques_nav_middle_bloc_height) <= 0) {
				list_marques_nav_middle_bloc.animate({
					top: 0
				}, 'slow', 'linear');
			} else {
				list_marques_nav_middle_bloc.animate({
					top: '-=' + list_marques_nav_middle_bloc_height
				}, 'slow', 'linear');
			}
			
			moveNav('down', list_marques_item_height, function() {
				list_marques_nav_top.removeClass('animate');
			});
			
		});
		
		function moveNav(type, value, callback) {
			
			var callback = callback || $.noop;
			
			switch (type) {
				
				case 'up' :
				
					list_marques_ul.animate({
						top: '-=' + value
					}, 'slow', callback);
				
				break;
				
				case 'down' :
				
					list_marques_ul.animate({
						top: '+=' + value
					}, 'slow', callback);
				
				break;
				
			}
			
		}
		
	}
	
})(jQuery);

(function($) {
	
	$.fn.changeColor = function(item_img, item_color, nav_left, nav_right) {
		
		if (this.length == 0) {
			return;
		}
		
		this.each(function() {
			
			var $this = $(this);
			var link = $this.find('h3 a');
			var prices = $this.find('h5');
			var apercu = false;
			
			if ($this.find('.list_products-content-list-item-apercu').length != 0) {
				apercu = true;
			}
			
			if (link.length != 0) {
				var old_link = link.attr('href').split('#')[0];
			}
			
			$(item_img, $this).find('img:first').addClass('current');
			$(item_color, $this).find('span:first').addClass('current');
			
			if (link.length != 0) {
				link.attr('href', old_link + '#' + $(item_img, $this).find('img:first').attr('alt'));
			}
			
			$(nav_right, $this).click(function(e) {
				
				e.preventDefault();
				
				var img_current = $(item_img, $this).find('img.current');
				var img_next = img_current.next();
				var span_current = $(item_color, $this).find('span.current');
				var span_next = span_current.next();
				var apercu_current, apercu_next;
				
				if (apercu) {
					apercu_current = $('.list_products-content-list-item-apercu-middle-content-current', $this);
					apercu_next = apercu_current.next();
				}
				
				if (img_next.length != 0 && span_next.length != 0) {
					img_current.removeClass('current');
					span_current.removeClass('current');
					
					img_next.addClass('current');
					span_next.addClass('current');
					
					if (link.length != 0) {
						link.attr('href', old_link + '#' + img_next.attr('alt'));
					}
					
					if (apercu) {
						apercu_current.removeClass('list_products-content-list-item-apercu-middle-content-current');
						apercu_next.addClass('list_products-content-list-item-apercu-middle-content-current');
					}
				} else {
					img_current.removeClass('current');
					span_current.removeClass('current');
					
					$(item_img, $this).find('img:first').addClass('current');
					$(item_color, $this).find('span:first').addClass('current');
					
					if (link.length != 0) {
						link.attr('href', old_link + '#' + $(item_img, $this).find('img:first').attr('alt'));
					}
					
					if (apercu) {
						apercu_current.removeClass('list_products-content-list-item-apercu-middle-content-current');
						
						$('.list_products-content-list-item-apercu-middle-content:first', $this).addClass('list_products-content-list-item-apercu-middle-content-current');
					}
				}
				
				prices.removeClass('current');
				prices.eq($(item_color, $this).find('span.current').index() - 2).addClass('current');
				
			});
			
			$(nav_left, $this).click(function(e) {
				
				e.preventDefault();
				
				var img_current =  $(item_img, $this).find('img.current');
				var img_prev = img_current.prev();
				var span_current = $(item_color, $this).find('span.current');
				var span_prev = span_current.prev();
				
				var apercu_current, apercu_prev;
				
				if (apercu) {
					apercu_current = $('.list_products-content-list-item-apercu-middle-content-current', $this);
					apercu_prev = apercu_current.prev();
				}
				
				if (img_prev.length != 0 && span_prev.length != 0) {
					img_current.removeClass('current');
					span_current.removeClass('current');
					
					img_prev.addClass('current');
					span_prev.addClass('current');
					
					if (link.length != 0) {
						link.attr('href', old_link + '#' + img_prev.attr('alt'));
					}
					
					if (apercu) {
						apercu_current.removeClass('list_products-content-list-item-apercu-middle-content-current');
						apercu_prev.addClass('list_products-content-list-item-apercu-middle-content-current');
					}
				} else {
					img_current.removeClass('current');
					span_current.removeClass('current');
					
					$(item_img, $this).find('img:last').addClass('current');
					$(item_color, $this).find('span:last').addClass('current');
					
					if (link.length != 0) {
						link.attr('href', old_link + '#' + $(item_img, $this).find('img:last').attr('alt'));
					}
					
					if (apercu) {
						apercu_current.removeClass('list_products-content-list-item-apercu-middle-content-current');
						
						$('.list_products-content-list-item-apercu-middle-content:last', $this).addClass('list_products-content-list-item-apercu-middle-content-current');
					}
				}
				
				prices.removeClass('current');
				prices.eq($(item_color, $this).find('span.current').index() - 2).addClass('current');
				
			});
			
		});
		
	}
	
})(jQuery);

(function($) {
	
	$.fn.setOpacity = function(opacity) {
		
		var $this = $(this);
		
		if ($this.length != 0) {
			$this.css('opacity', opacity);
		}
		
		return $this;
		
	}
	
})(jQuery);

(function($) {
	
	var timeout;
	
	$.scrollablePubs = {
		
		init: function() {
			
			if ($('.home-scrollable-pubs').length == 0) {
				return;
			}
			
			var $this = this;
			
			if ($('.home-scrollable-pubs-content-scrollable ul li').length < 4)  {
				
				var new_elements = [];
				
				$('.home-scrollable-pubs-content-scrollable ul li').each(function() {
					
					var clone_element = $(this).clone();
					
					new_elements.push(clone_element);
					
				});
				
				$(new_elements).each(function() {
					
					$('.home-scrollable-pubs-content-scrollable ul').append(this);
					
				});
				
			}
			
			$this.autoscroll();
			
			$('.home-scrollable-pubs-slide-nav_top').click(function(e) {
				
				e.preventDefault();
				
				clearTimeout(timeout);
				
				timeout = setTimeout(function() {
					$this.autoscroll();
				}, 12000);
				
				$this.navigation('top');
				
			});
			
			$('.home-scrollable-pubs-slide-nav_bottom').click(function(e) {
				
				e.preventDefault();
				
				clearTimeout(timeout);
				
				timeout = setTimeout(function() {
					$this.autoscroll();
				}, 12000);
				
				$this.navigation('bottom');
				
			});
			
			$('.home-scrollable-pubs-content-scrollable ul li').css('opacity', .3);
			
			$('.home-scrollable-pubs-content-scrollable').delegate('ul li a', 'click mouseenter mouseleave', function(e, a) {
				
				e.preventDefault();
				
				if (a == undefined) {
					clearTimeout(timeout);
					
					timeout = setTimeout(function() {
						$this.autoscroll();
					}, 12000);
				}
				
				var $a = $(this);
				var $li = $a.parent();
				
				if (e.type == 'mouseenter') {
					$li.not('.current').css('opacity', 1);
				}
				
				if (e.type == 'mouseleave') {
					$li.parent().find('li:not(.current)').css('opacity', .3);
				}
				
				if (e.type == 'click') {
					$('.home-scrollable-pubs-content-scrollable ul li').css('opacity', .3);
					
					var big = $('.home-scrollable-pubs-big');
					var big_link = big.find('a');
					var big_img = big_link.find('img');
					
					var current_link = $a.attr('href').substring(1);
					var current_big = $a.find('img').attr('alt');
					
					var old_current = $li.parent().find('li.current').removeClass('current');
					
					$li.addClass('current').animate({
						opacity: 1
					});
					
					big_link.attr('href', current_link);
					big_img.attr('src', current_big);
				}
				
			});
			
			$('.home-scrollable-pubs-content-scrollable ul li:first a').trigger('click', ['trigger']);
			
			return $this;
			
		},
		
		navigation: function(direction, callback, prepend) {
			
			var callback = callback || $.noop;
			var prepend = prepend || $.noop;
			
			if ($('.home-scrollable-pubs-slide ul').hasClass('animated')) {
				return false;
			}
			
			prepend();
			
			var items = $('.home-scrollable-pubs-slide ul');
			
			items.addClass('animated');
			
			switch (direction) {
				
				case 'top' :
					
					var item_last = items.find('li:last').clone();
					
					item_last.setOpacity(.3);
					
					items.prepend(item_last).css('top', '-188px').animate({
						top: '+=94px'
					}, 'slow', function() {
						callback();
						
						items.removeClass('animated').find('li:last').remove();
						
						$('.home-scrollable-pubs-content-scrollable ul li:first a').trigger('click', ['trigger']);
					});
					
				break;
				
				case 'bottom' :
					
					var item_first = items.find('li:first').clone();
					
					item_first.setOpacity(.3);
					
					items.append(item_first).animate({
						top: '-=94px'
					}, 'slow', function() {
						callback();
						
						items.removeClass('animated').css('top', '-94px').find('li:first').remove();
						
						$('.home-scrollable-pubs-content-scrollable ul li:first a').trigger('click', ['trigger']);
					});
					
				break;
				
			}
			
		},
		
		autoscroll: function() {
			
			var $this = this;
			
			timeout = setTimeout(function() {
				
				$('.home-scrollable-pubs-slide-nav_bottom').trigger('click');
				
				$this.autoscroll();
				
			}, 6000);
			
		}
		
	}
	
})(jQuery);

function eventsProductDetails() {
	
	if ($('.product_details-right-middle-text-description-short-content').text().length >= $('.product_details-right-middle-text-description-long').text().length) {
		$('.product_details-right-middle-text-description-short-next').hide();
	}
	
	$('.product_details-right-middle-text-description-short-next a').click(function(e) {
		
		e.preventDefault();
		
		var $this = $(this);
		var bloc_text = $this.parent().parent().parent();
		var short_text = $('.product_details-right-middle-text-description-short-content', bloc_text);
		var long_text = $('.product_details-right-middle-text-description-long', bloc_text);
		
		$this.parent().fadeOut('slow');
		
		short_text.html(long_text.html());
		
	});
	
	$('.product_details-right-middle-colors ul li:not(.disabled)').mouseenter(function() {
		
		var $this = $(this);
		var img = $('img', $this);
		var img_alt = $.parseJSON(img.attr('alt'));
		
		var product_details_sizes = $('.product_details-right-middle-sizes');
		var sizes = img_alt.sizes.split(' ');
		var color = img_alt.text;
		
		$('.product_details-right-middle-colors-title span').text(color);
		
		$('ul li:not(.disabled)', product_details_sizes).each(function() {
			
			var $this = $(this);
			var a = $('a', $this);
			var a_rel = $.parseJSON(a.attr('rel'));
			var li_size = a_rel.size;
			
			$this.hide();
			
			$(sizes).each(function() {
				
				if (li_size == this) {
					$this.show();
				}
				
			});
			
		});
		
	}).mouseleave(function() {
		
		$('.product_details-right-middle-colors ul li.current').trigger('click');
		
	}).click(function() {
		
		var $this = $(this);
		
		if (!$this.is(':visible')) {
			return false
		}
		
		var img = $('img', $this);
		var img_alt = $.parseJSON(img.attr('alt'));
		
		if ($('#product_color-' + img_alt.color).is(':hidden') || $('#product_color-' + img_alt.color).css('display', 'none')) {
			$('.product_details-left').hide();
			$('#product_color-' + img_alt.color).show();
			
			$('.product_details-right-middle-price').hide();
			$('#product_color_price-' + img_alt.color).show();
		}
		
		$this.parent().next('input').val(img_alt.color);
		
		$('.product_details-right-middle-colors ul li').removeClass('current');
		
		$this.addClass('current').trigger('mouseenter');
		
		$('.product_details-left:visible .product_details-left-images ul li:first').trigger('click');
		
	});
	
	var color = self.document.location.hash.substring(1);
	
	if (color == '') {
		$('.product_details-right-middle-colors ul li:not(.disabled)').first().trigger('click');
	} else {
		var safe = false;
		
		$('.product_details-right-middle-colors ul li:not(.disabled) img').each(function() {
			
			var $this = $(this);
			var img_alt = $.parseJSON($this.attr('alt'));
			
			if (img_alt.color == color) {
				$this.parent().trigger('click');
				
				safe = true;
				
				return false;
			}
			
		});
		
		if (!safe) {
			$('.product_details-right-middle-colors ul li:not(.disabled)').first().trigger('click');
		}
	}
	
	$('.product_details-right-middle-sizes ul li:not(.disabled)').mouseenter(function() {
		
		var $this = $(this);
		var a = $('a', $this);
		var a_rel = $.parseJSON(a.attr('rel'));
		
		var product_details_colors = $('.product_details-right-middle-colors');
		var colors = a_rel.colors.split(' ');
		
		$('ul li:not(.disabled)', product_details_colors).each(function() {
			
			var $this = $(this);
			var img = $('img', $this);
			var img_alt = $.parseJSON(img.attr('alt'));
			var li_color = img_alt.color;
			
			$this.setOpacity(.5);
			
			$(colors).each(function() {
				
				if (li_color == this) {
					$this.setOpacity(1);
				}
				
			});
			
		});
		
	}).mouseleave(function() {
		
		if ($('.product_details-right-middle-sizes ul li.current').length != 0) {
			$('.product_details-right-middle-sizes ul li.current').trigger('click');
		} else {
			$('.product_details-right-middle-colors ul li:not(.disabled)').removeAttr('style');
		}
		
	}).click(function() {
		
		var $this = $(this);
		
		if ($this.css('opacity') != 1) {
			return false
		}
		
		var a = $('a', $this);
		var a_rel = $.parseJSON(a.attr('rel'));
		
		$this.parent().next('input').val(a_rel.size);
		
		$('.product_details-right-middle-sizes ul li').removeClass('current');
		
		$this.addClass('current').trigger('mouseenter');
		
		Cufon.refresh();
		
	});
	
	$('.product_details-left-images').delegate('ul li:not(.current)', 'mouseenter', function() {
		
		$(this).setOpacity(1);
		
	}).delegate('ul li:not(.current)', 'mouseleave', function() {
		
		$(this).setOpacity(.5);
		
	});
	
	$('.product_details-left-images').delegate('ul li:not(.current)', 'click', function() {
		
		var $this = $(this);
		var img = $('img', $this);
		var img_big = $('.product_details-left-big img', $this.parent().parent().parent());
		
		$this.parent().find('.current').removeClass('current').setOpacity(.5);
		$this.addClass('current').removeAttr('style');
		
		var img_alt = $.parseJSON(img.attr('alt'));
		
		img_big.attr('src', img_alt.image).attr('alt', img_alt.image_big);
		
	});
	
	$('.product_details-left-big img').mouseenter(function() {
		
		var img = $(this);
		var img_alt = $('.product_details-left-big-alt', img.parent());
		
		img.hide();
		
		img_alt.css({
			backgroundImage: 'url(' + img.attr('alt') + ')',
			backgroundPosition: 'center center',
			backgroundRepeat: 'no-repeat'
		}).show().mousemove(function(e) {
			
			img_alt.css('background-position', ((e.pageX - img_alt.offset().left) - 400) + 'px ' + ((e.pageY - img_alt.offset().top) - 400) + 'px');
			
		}).mouseleave(function() {
			
			img_alt.hide();
			img.show();
			
		});
		
	});
	
	$('.product_details-left:visible .product_details-left-images ul li:first').trigger('click');
	
}

function getPositionArrowMenu(element) {
	
	var element = element || '.menu-current';
	
	var menu_arrow_current = $('.menu-arrow_current');
	
	var menu_current = $(element);
	var menu_current_position = 0;
	var menu_current_width = menu_current.width();
	
	menu_current.prevAll().each(function() {
		
		menu_current_position += $(this).width();
		
	});
	
	menu_current_position = menu_current_position - (menu_arrow_current.width() / 2) + (menu_current_width / 2);
	
	return menu_current_position;
	
}
