(function($){
	
	$(document).ready(function(){
	


		
	//Bookmark
	
	try {
		$('#top_user_nav .bookmark').css('display', 'block').click(function(){
			var url = window.location.href
			var title = $('head title').html();
			if (window.sidebar) { // Mozilla Firefox Bookmark
				window.sidebar.addPanel(title, url, '');
			} else if( window.external ) { // IE Favorite
				window.external.AddFavorite( url, title);
			} else if(window.opera) { // Opera 7+
				return false; // do nothing - the rel="sidebar" should do the trick
			} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
				 alert('Unfortunately, this browser does not support the requested action,'
				 + ' please bookmark this page manually.');
			}
			return false;
		});
	}
	catch(e) { }
	
	
	//Input default text
	window.check_inputs = function(){
		$('.input_default_text').each(function(){
			if(!this._default_text){
				this._default_text = this.value;
				if(this.type == 'password'){
					this._text_input = document.createElement('input');
					
					this._text_input.type = 'text';
					this._text_input.className = this.className;
					this._text_input._text_password = this;
					this._text_input.value = this.value;
					this.value = '';
					
					$(this).removeClass('default_text');
					
					$(this._text_input).css({
						'position': 'absolute',
						'top': $(this).position().top + 'px',
						'left': $(this).position().left + 'px',
						'margin-top': '0',
						'display': 'block'
						});
					
					this.parentNode.appendChild(this._text_input);
					
					$(this.parentNode).css({'height': $(this.parentNode).outerHeight() + 'px'});
					
					$(this._text_input).focus(function(){
						$(this).css({'display': 'none'});
						$(this._text_password).focus();
					});
					
					$(this).focus(function(){
						if( $(this._text_input).css('display') == 'block' )
							$(this._text_input).focus();
					});
					$(this).change(function(){
						if( $(this._text_input).css('display') == 'block' )
							$(this._text_input).focus();
					});
					
					
					$(this).blur(function(){
						if(this.value == '')
							$(this._text_input).css({'display': 'block'});
					});
					
					}
				else {
					$(this).focus(function(){
						if(this.value == this._default_text){
							this.value = '';
							$(this).removeClass('default_text');
							}
						return true;
					});
					$(this).blur(function(){
						if(this.value == ''){
							$(this).addClass('default_text');
							this.value = this._default_text;
							}
						return true;
					});
					}
				}
		});
	};
	window.check_inputs();

	var simple_inputs = function(){
		$('.text.simple').each(function(){
			if(!this._default_text){
				this._default_text = this.value;

				$(this).focus(function(){
					if(this.value == this._default_text){
						this.value = '';
						$(this).removeClass('default_text');
						}
					return true;
				});
				$(this).blur(function(){
					if(this.value == ''){
						$(this).addClass('default_text');
						this.value = this._default_text;
						}
					return true;
				});
				}
		});
	};
	simple_inputs();
	
	
	
	//!Spinner
	$('.input_spinner').each(function(){
		
		$('.plus', this).click(function(){
			var input = $('input', $(this).parent());
			if(parseInt(input.val()) < parseInt(input.attr('alt'))) {
				input.val(parseInt(input.val()) + 1);
				input.change();
			}
		}).disableTextSelect();
		
		$('.minus', this).click(function(){
			var input = $('input', $(this).parent());
			
			if(parseInt(input.val()) > 0) {
				input.val(parseInt(input.val()) - 1);
				input.change();
			}

		}).disableTextSelect();
		
		
	});
	
	//Lightbox controller
	window.cover = {
		'wrapper': false,
		'cover': false,
		'visible': false,
		'render': function(){
			var clientHeight = document.body.clientHeight;
			var clientWidth = document.body.clientWidth;
			if(this.cover)
				$(this.cover).css({
					'width': (window.innerWidth || document.documentElement.clientWidth) + $(document).scrollLeft() + 'px',
					'height': $(document).height() + 'px'
				});
			
			if(this.wrapper) {
				var top  = Math.max(10, (window.innerHeight || document.documentElement.clientHeight)/2 - this.height/2) + $(document).scrollTop(),
					left = Math.max(10, (window.innerWidth || document.documentElement.clientWidth)/2  - this.width/2) + $(document).scrollLeft();
				$(this.wrapper).css({
					'top':  top   + 'px',
					'left': left + 'px'
				});
			}
		},
		'resize': function(){
			
		},
		'show': function(width, height, html){
			
			if( typeof width == 'function' ){
				html = width;
				width = 100;
				height = 100;
				}
			
			height -= 70;
			
			this.width = width;
			this.height = height;
			this.html = html;
			
			
			if(!this.cover){
				this.cover = document.createElement('div');
				$(this.cover).css({
					'width': '100%',
					'height': $(document).height() + 'px',
					'background': '#000',
					'position': 'absolute',
					'top': '0px',
					'left': '0',
					'right': '0',
					'opacity': 0.4,
					'z-index': 99,
					'display': 'none'
				}).addClass('lightbox_cover_wrapper').click(function(){
					cover.hide();
					});
				$(document.body).append(this.cover);
				
				this.render();
				$(window).resize(function(){
					window.cover.render();
				});
				
				}
			else
				this.render();
			
			if(!this.wrapper){
				this.wrapper = document.createElement('div');
				$(this.wrapper).css({
					'background': '#FFF',
					'border': '1px solid #000',
					'padding': '35px 25px',
					'position': 'absolute',
					'display': 'none',
					'z-index': 998
				}).addClass('lightbox_content_wrapper').html('<a class="close">X</a><div class="lightbox_content"></div>');
				$(document.body).append(this.wrapper);
				$('.close', this.wrapper).click(function(){
					cover.hide();
					return false;
				});
				}
			
			// using innerWidth/innerHeight, since those return actual window width/height in CSS pixels,
			// at least on iPhone and perhaps on other smartphones
			var top  = Math.max(10, (window.innerHeight || document.documentElement.clientHeight)/2 - this.height/2) + $(document).scrollTop(),
				left = Math.max(10, (window.innerWidth || document.documentElement.clientWidth)/2  - this.width/2) + $(document).scrollLeft();
			
			$(this.wrapper).css({
				'width':   width + 'px',
				'height':  height + 'px',
				'top':     top + 'px',
				'left':    left + 'px',
				'opacity': 0,
				'display': 'block'
			});

			if (typeof html == 'function') {
				$('.lightbox_content', this.wrapper).html('<div class="loading">loading</div>');
				html.call($('.lightbox_content', this.wrapper).get(0));
				}
			else
				$('.lightbox_content', this.wrapper).html(html);
			
			
			check_inputs();
			$(this.cover).css({'opacity': 0, 'display': 'block'}).animate({'opacity': 0.4}, 'fast', null, function(){
				$(cover.wrapper).animate({'opacity': 1}, 'fast');
			});
			this.visible = true;
		},
		'hide': function(){
			$(this.wrapper).animate({'opacity': 0}, 'fast', null, function(){
				$(this).css({'display': 'none'});
			});
			$(this.cover).animate({'opacity': 0}, 'fast', null, function(){
				$(this).css({'display': 'none'});
			});
			this.visible = false;
			}
		};
	$(document).keypress(function(ev){
		if(cover.visible && ev.keyCode == 27)
			cover.hide();
	});
	
	
	
	//Sub Menu
	(function(){
		//Init
		var mm = $('#main_menu').innerWidth();
		$('#submenu_wrapper ul').each(function(){
			$(this).css({
				'opacity': 0,
				'display': 'block'
			});
			
			
			var li_controller = $('#main_menu .pages .' + this.className);
			
			var width = 0;
			$('li', this).each(function(){
				width += $(this).width();
			});
				
			this._left = parseInt( ((li_controller.width() / 2) + li_controller.position().left) - (width / 2) );
			
			if($('#main_menu').innerWidth() < this._left + width)
				this._left = mm - width
			if(this._left < 0)
				this._left = 0;
			
			$(this).css({
				'width': (mm - this._left) + 'px',
				'padding-left': this._left + 'px'
			});
			
			$(this).get(0)._opacity = 0;
		});
		
		var current = $('#submenu_wrapper').attr('class');
		var current_submenu = false;
		var current_menu = false;
		
		if(current){
			current_menu = $('#main_menu .' + current).addClass('selected');
			current_submenu = $('#submenu_wrapper .' + current).css({
				'opacity': 1,
				'z-index': 2
			});
			}
		
		
		var fade_in = function(){
			
			if(typeof this._opacity == 'undefined')
				this._opacity = 0;
			
			if(this._opacity < 100){
				this._opacity += 15;
				$(this).css('opacity', this._opacity / 100);
				return true;
				}
			else{
				this._opacity = 100;
				$(this).css('opacity', this._opacity / 100); 
				return false;
				}
			}

		var fade_out = function(){
			
			if(typeof this._opacity == 'undefined')
				this._opacity = 0;
			
			if(this._opacity > 0){
				this._opacity -= 4;
				$(this).css('opacity', this._opacity / 100); 
				return true;
				}
			else{
				this._opacity = 0;
				$(this).css('opacity', this._opacity / 100); 
				return false;
				}
			}
		
		
		
		$('.pages').mouseout(function(ev){
			var is_mainmenu = $(ev.relatedTarget).parents('.pages').length ? true : false;
			var is_submenu = $(ev.relatedTarget).parents('#submenu_wrapper').length ? true : false;
			if(!is_mainmenu && !is_submenu && current_submenu && current_submenu.get(0).className != current){
				current_submenu.css('z-index', 1);
				ijs.worker.add('img_' + current_submenu.get(0).className, fade_out, current_submenu);
				current_menu.removeClass('selected');
				current_submenu = current_menu = false;
				if(current){
					current_menu = $('#main_menu .' + current);
					current_submenu = $('#submenu_wrapper .' + current);
					current_submenu.css('z-index', 2);
					current_menu.addClass('selected');
					ijs.worker.add('img_' + current, fade_in, current_submenu);
					}
				}
		});
		
		
		$('#submenu_wrapper').mouseout(function(ev){
			var is_mainmenu = $(ev.relatedTarget).parents('.pages').length ? true : false;
			var is_submenu = $(ev.relatedTarget).parents('#submenu_wrapper').length ? true : false;
			
			if(!is_mainmenu && !is_submenu && current_submenu && current_submenu.get(0).className != current){
				current_submenu.css('z-index', 1);
				ijs.worker.add('img_' + current_submenu.get(0).className, fade_out, current_submenu);
				current_menu.removeClass('selected');
				current_submenu = current_menu = false;
				if(current){
					current_menu = $('#main_menu .' + current);
					current_submenu = $('#submenu_wrapper .' + current);
					current_submenu.css('z-index', 2);
					current_menu.addClass('selected');
					ijs.worker.add('img_' + current, fade_in, current_submenu);
					}
				}
		});
	
		
		$('#main_menu .pages a').mouseover(function(ev){
			
			var className = this.parentNode.className.replace(/first /, '').replace(/ selected/, '');
			
			if(!current_submenu || current_submenu.get(0).className != className){
				if(current_submenu){
					ijs.worker.add('img_' + current_submenu.get(0).className, fade_out, current_submenu);
					current_menu.removeClass('selected');
					current_submenu.css('z-index', 1);
					}
				
				current_menu = $(this.parentNode);
				current_submenu = $('#submenu_wrapper .'+ className);;
				current_submenu.css('z-index', 2);
				current_menu.addClass('selected');
				ijs.worker.add('img_' + className, fade_in, current_submenu);
				}
			
		});
	})();
	
	
	$('.products .meta h2 em').each(function(){
		
		$('.brands img[alt="'+ this.innerHTML +'"]').each(function(){
			if( !this._swapped ) {
				var url = this.src.split('.');
				url[url.length - 2] += '_hover';
				this.src = url.join('.');
				this._swapped = true;
				this._url = this.src;
			}
		});
		
	});
	
	
	
	//Swap color image 
	$('.add-color img').hover(
		function(){
			if( !this._swapped ) {
				this._url = this.src;
				var url = this.src.split('.');
				url[url.length - 2] += '_hover';
				this.src = url.join('.');
				this._swapped = true;
			}
		},
		function(){
			if( this.src != this._url ) 
				this._swapped = false;
			this.src = this._url;
			}
		);
	
	
	$('.fade-images').each(function(){
		var images = [];
		var current = 0;
		var delay = $('.images', this).attr('alt') ? parseInt($('.images', this).attr('alt')) : 3000;
		var main_img = $('img', this).css({'z-index': 2});
		var link = $('a:first', this);
		main_img.get(0)._link = link.attr('href');
		main_img.get(0)._title = link.attr('title');
		images.push(main_img);

		$('.images a', this).each(function(){
			var img = document.createElement('img');
			img.src = $(this).attr('alt');
			$(img).css({
				'z-index': 1,
				'opacity': 0
				});
			img._link = $(this).attr('href');
			img._title = $(this).html();
			main_img.parent().append(img);
			images.push($(img));
			
			$(img).css('left', - $(img).position().left + 'px');
		});
		
		var clear_interval = false
		var fade = function(){
			current++;
			if(current > images.length - 1)
				current = 0;
			
			images[current].css({'opacity': 0, 'z-index': !current ? 3 : 2}).animate({'opacity': 1}, 1200, null, function(){
				images[current].css({'z-index': 2});
				images[current - 1 < 0 ? images.length - 1 : current - 1 ].css({'z-index': 1});
				link.attr('href', images[current].get(0)._link);
				link.attr('title', images[current].get(0)._title);
				
				});
			};
		if($('.images a', this).length) {
			var cicle_interval = setInterval(fade, delay);
			$('img', this).hover(
				function(){
					clearInterval(cicle_interval);
				}, function(){
					 cicle_interval = setInterval(fade, delay);
				});
		}
		
	});
	
	$('.accordion-menu li').not('.selected').not($('.accordion-menu li.selected li')).each(function(){
		var $thisLI = $(this);
		this._ul = $thisLI.children('ul');
		if(this._ul.length){
			this._ul_height = this._ul[0].scrollHeight;
			$thisLI
				.mouseenter(function(){
					this._hasmouse = true;
					var $parentLi, targetHeight = this._ul_height;
					$(this._ul).children('li').each(function() {
						targetHeight += (this._targetHeight ? this._targetHeight : 0);
					});
					this._targetHeight = targetHeight;
					this._ul.clearQueue()
							.queue( function() {
								$(this).animate({'height' : $thisLI[0]._targetHeight + 'px' }, {'duration': 'medium', 'queue': 1});
								$(this).dequeue();
							});
					$(this).parents('li').first().mouseenter();
				})
				.mouseleave(function(){
					this._hasmouse = false;
					this._targetHeight = 0;
					this._ul.delay(1000)
						.queue( function () {
							$(this).animate({'height': '0px'}, {'duration': 'slow', 'queue': 1});
							var $parentLi = $(this).parent().parents('li').first();
							if ($parentLi.length && $parentLi[0]._hasmouse)
								$parentLi.mouseenter();
							else 
								if($parentLi.length)
									$parentLi[0]._ul.animate({'height': '0px'}, {'duration': 'slow', 'queue': 1});
							$(this).dequeue();
						});
				});
			}
	});
	
	$('.image-zoomer').each(function(){
		var full_wrapper = $('.image_full img', this).css('cursor', 'pointer').click(function(){
			zoom.click();
			return false;
		});
		
		
		full_wrapper.parent().mousemove(function(ev){
			if(full_wrapper._zoom){
				this.scrollLeft =  (ev.pageX - $(this).offset().left) / $(this).outerWidth() * (this.scrollWidth - $(this).outerWidth());
				this.scrollTop =  (ev.pageY - $(this).offset().top) / $(this).outerHeight() * (this.scrollHeight - $(this).outerHeight());
				}
		});
		
		var loading = document.createElement('div');
		loading = $(loading);
		loading.css({
			'position': 'absolute',
			'top': '0px',
			'left': '0px',
			'padding': '10px',
			'background': '#FFF',
			'display': 'none'
		}).html('loading...');
		full_wrapper.parent().append(loading);
		
		
		full_wrapper.load(function(){
			if(full_wrapper._loading){
				loading.css('display', 'none');
				full_wrapper._zoom = true;
				full_wrapper._loading = false;
				full_wrapper.parent().addClass('zoom');
				full_wrapper.css('cursor', 'crosshair');
			}
		});
		
		
		
		var zoom = $('.zoom_bloc .zoom', this).click(function(){
			//window.cover.show(full_wrapper.width(), full_wrapper.height() + 50, '<img src="'+ full_wrapper.attr('src') +'" />');
			if(!full_wrapper._zoom){
				full_wrapper._loading = true;
				full_wrapper.attr('rel', full_wrapper.attr('src'));
				full_wrapper.attr('src', $(this).attr('rel'));
				full_wrapper.parent().get(0).scrollLeft = 0;
				full_wrapper.parent().get(0).scrollTop = 0;
				if( !$.browser.msie && parseInt($.browser.version) != 6 )
					loading.css('display', 'block');
				$(this).addClass('minus');
			} else {
				full_wrapper.parent().removeClass('zoom');
				full_wrapper._zoom = false;
				full_wrapper.css('cursor', 'pointer');
				full_wrapper.attr('src', full_wrapper.attr('rel'));
				full_wrapper.parent().get(0).scrollLeft = 0;
				full_wrapper.parent().get(0).scrollTop = 0;
				$(this).removeClass('minus');
				}
			return false;
		});
		// !Zoom
		$('.thumbs a', this).not('.zoom').click(function(){
			var img = $(this).attr('href');
			var full = $(this).attr('rel');
			full_wrapper.animate({'opacity': 0}, 'fast', null, function(){
				full_wrapper._zoom = false;
				full_wrapper.parent().get(0).scrollLeft = 0;
				full_wrapper.parent().get(0).scrollTop = 0;
				full_wrapper.css('cursor', 'pointer');
				full_wrapper.parent().removeClass('zoom');
				zoom.attr('href', img);
				zoom.attr('rel', full);
				if(!full_wrapper.get(0)._onload){
					full_wrapper.get(0)._onload = true;
					full_wrapper.load(function(){
						full_wrapper.animate({'opacity': 1}, 'fast');
						});
					}
				full_wrapper.attr('src', img);
			});
			return false;
		});
	});
	
	});
	
	$(window).load(function(){
		$('.marque-scroller').each(function(){
		
			var scrollWidth = this.scrollWidth;
			var delay = 50;
			var wrapper = $(this).css({'height': $(this).height() + 'px'});
			var scroll_offset = scrollWidth;
			var step = 2;
			
			
			var scroll_wrapper = document.createElement('div');
			scroll_wrapper = $(scroll_wrapper).html(this.innerHTML).css({
				'position': 'absolute',
				'top': parseInt($(this).css('padding-top')) + 'px',
				'left': '0px',
				'width': scrollWidth + 'px'
				});
			
			var clone_wrapper = document.createElement('div');
			clone_wrapper = $(clone_wrapper).html(this.innerHTML).css({
				'position': 'absolute',
				'top': parseInt($(this).css('padding-top')) + 'px',
				'left': scrollWidth + 'px',
				'width': scrollWidth + 'px'
				});
				
			this.innerHTML = '';
			this.appendChild(scroll_wrapper.get(0));
			this.appendChild(clone_wrapper.get(0));
			
			function UrlExists(url) {
				var http = new XMLHttpRequest();
				http.open('HEAD', url, false);
				http.send();
				return http.status!=404;
			}

			$('.add-color img').hover(
				function(){
					var $img = $(this);
					this._url = this.src;
					var hover_url = this.src.split('.');
					hover_url[hover_url.length - 2] += '_hover';
					hover_url = hover_url.join('.');
					if ($img.data('hover_img') == null) {
						if (UrlExists(hover_url)) { 
							$img.data('hover_img', hover_url); 
							$img.attr('src',hover_url);
						} else
							$img.data('hover_img', $img[0]._url);
					}
					this.src = $img.data('hover_img');
				},
				function(){
					this.src = this._url;
					}
				);
			
			wrapper.scrollLeft(scrollWidth);
			
			var scroll = function(){
				wrapper.scrollLeft(scroll_offset);
				scroll_offset -= step;
				if(scroll_offset < 0){
					scroll_offset = scrollWidth;
					wrapper.scrollLeft(scrollWidth);
					}
				}
			
			var interval_id = setInterval(scroll ,delay);
			$(this).hover(
				function(){
					clearInterval(interval_id);
				},
				function(){
					interval_id = setInterval(scroll ,delay);
				});
			//*/
		});
	
	
	$('.refer_a_friend').not('.registered').click(function(){
		window.cover.show(350, 235, function(){
			var wrapper = $(this);
			$.get(config_dir+'index.php?fuseaction=ajax.refer_friend', {} , function(data, status){
				$(wrapper).html(data);
				window.check_inputs();
			});
		});
		return false;
	});
	
	
	$('.product_request_form').click(function(){
		window.cover.show(300, 255, function(){
			var wrapper = $(this);
			$.get(config_dir+'index.php?fuseaction=ajax.product_request', {} , function(data, status){
				$(wrapper).html(data);
				window.check_inputs();
			});
		});
		return false;
	});
	
	
	$('a.frogot_password').click(function(){
		window.cover.show(300, 150, function(){
			var wrapper = $(this);
			$.get(config_dir+'index.php?fuseaction=ajax.forgotten_password', {} , function(data, status){
				$(wrapper).html(data);
				window.check_inputs();
			});
		});
		return false;
	});
	
	if( window.showRegisterLightBox ) {
		
		window.cover.show(600, 450, function(){
			var wrapper = $(this);
			$.get(config_dir+'index.php?fuseaction=ajax.register', {} , function(data, status){
				$(wrapper).html(data);
				window.check_inputs();
			});
		});
		
	}	
	
	
	$('.add-to-cart').click(function(){
		var id = $(this).attr('rel');
		if (id == '#') {
			window.location.href = $('.moreinfo', $(this).parent()).attr('href');
		} else {
			window.cover.show(350, 235, function(){
				var wrapper = this;
				$.get(config_dir+'index.php?fuseaction=ajax.add_to_cart', {'option_id': id} , function(data, status){
					$(wrapper).html(data);
					$('.continue-shopping', wrapper).click(function(){
						window.cover.hide();
						return false;
					});
				});
				
				});
		}
		return false;
	});
	
	$('.ps_login').click(function(){
		window.cover.show(350, 150, function(){
			var wrapper = $(this);
			$.get(config_dir+'index.php?fuseaction=ajax.ps_login', {} , function(data, status){
				$(wrapper).html(data);
				window.check_inputs();
			});
		});
		return false;
	});


	// !Gestion des options

	function updateOptions(data, status) {
		// maj combos
		for (var opt_group_id in data.opt) {
			var options = data.opt[opt_group_id];
			var select = $('#option_'+opt_group_id);
			select.html('');
			for (opt_id in options) {
				var opt = options[opt_id],
					opt_line = $('<option>');
				opt_id = (''+opt_id).replace("'",'');
				var opt_name = opt_id > 0 ? data.status_template[opt[1]-1].replace('{val}',opt[0]) : opt[0];
				opt_line.val(opt_id) // opt_val_id
						.html(opt_name) // opt name
						.attr('alt',opt[1])  // status
						.attr("selected", opt[2] ? 'selected' : null); // opt_val_id
				opt_line.appendTo(select);
			}
		}
		
		// mise à jour stock
		var status = data.status;
		if (status){
			$('#current_price').html(status.price);
			$('#q').attr('alt', status.stock);
			$('#option_id').val(status.id);
		}
		
		// Changement de l'image
		if (data.image) {
			var img = 
			changeImageOption(
				'/images/product/main/image'+data.image.id+'.'+data.image.imagetype, 
				'/images/product/zoom/image'+data.image.id+'.'+data.image.imagetype
				);
		} else {
			first_thumb = $($('.thumbs a')[0]);
			changeImageOption(
				first_thumb.attr('href'),
				first_thumb.attr('rel'));
		}
		
		$('#loader').hide();
	}

	//$('#select_options select').live('change', function(){
	var $optionSelects = $('#select_options select');
	$optionSelects.live("change", function() {

		var valeur = $(this).val(); // Récup de la valeur
		var status = $('option:selected',this).attr('alt');
		if (valeur == "0" || status == 3)
			return;

		var current_cb = $(this),
			selected = $.map( $optionSelects, function(s) { return $(s).val(); } ).join('_'),
			empty = [],
			id = $(this).attr('alt');
		
		// Loading
		$('#loader').show();
		
		if (starting_product_options) {
			// on first load, option data already here
			updateOptions(starting_product_options);
			starting_product_options=false;
		} else {
			// otherwise get options via Ajax
			$.get(
				config_dir+'index.php?fuseaction=ajax.update_option', { 
					group_id: id,
					//value_id: valeur,
					product_id: $('#product_id').val(),
					selected: selected
				}, 
				updateOptions,
				'json');
		}
	});
	$($optionSelects[0]).change();
	
	function changeImageOption(img, full){
		var full_wrapper = $('.image_full img');
		var zoom = $('.zoom_bloc .zoom');
		if ( zoom.attr('href') == img && zoom.attr('rel') == full)
			return;
		full_wrapper.animate({'opacity': 0}, 'fast', null, function(){
			full_wrapper._zoom = false;
			full_wrapper.parent().get(0).scrollLeft = 0;
			full_wrapper.parent().get(0).scrollTop = 0;
			full_wrapper.css('cursor', 'pointer');
			full_wrapper.parent().removeClass('zoom');
			zoom.attr('href', img);
			zoom.attr('rel', full);
			if(!full_wrapper.get(0)._onload){
				full_wrapper.get(0)._onload = true;
				full_wrapper.load(function(){
					full_wrapper.animate({'opacity': 1}, 'fast');
					});
				}
			full_wrapper.attr('src', img);
		});
		return false;
	}
	
	$('.submit-to-cart').click(function(){
		$(this).parent().submit();
		return false;
	});
	
	$('.frmAddToCart').submit(function(){
		var errorOptions = false;
		var qty = parseInt($('.input_spinner input', $(this)).val());
		var max = parseInt($('.input_spinner input', $(this)).attr('alt'));
		var this_frm = this;

		$('#select_options select').each(function(index) {
			if ($(this).val() == 0) {
				errorOptions = true;
			}
		});
		
		if (errorOptions) {
			alert(option_error);
			return false;
		}

		if(qty == 0){
			alert(zero_error);
			return false;
		}
		
		if(qty > max){
			alert(too_many_error+' '+max);
			return false;
		}
		
		window.cover.show(350, 235, function(){
			var wrapper = this;
			$.get(config_dir+'index.php?fuseaction=ajax.add_to_cart', $(this_frm).serialize() , function(data, status){
				$(wrapper).html(data);
				$('.continue-shopping', wrapper).click(function(){
					window.cover.hide();
					return false;
				});
			});
			
			});
		
		return false;
	});
	
	$('.newsletter form').submit(function(){
		if($('#newsletter_email').val() == newsletter_email)
			$('#newsletter_email').val('');
			
		var validation = new Validator(function(errors){
			var error = [];
			for(i=0;i<errors.length;i++)
			{
				var error_msg = '';
				switch(errors[i].errorCode)
				{
					case "E1":
						error_msg = errors[i].field_name+" "+newsletter_empty;
						break;
					case "E4":
						error_msg = errors[i].field_name+" "+newsletter_invalid;
						break;
				}
				error[error.length] = error_msg;
			}
			
			if($('#newsletter_email').val() == '')
				$('#newsletter_email').val(newsletter_email);
			
			if(error.length)
				alert(error.join("\n"))
		});

		validation.addField('newsletter_email', newsletter_email, 'email|required');
		if(validation.validate())
		{
			var email = $('input.text', this).val();
			window.cover.show(350, 150, function(){
				var wrapper = this;
				$.get(config_dir+'index.php?fuseaction=ajax.newsletter_subscription', {'email': email} , function(data, status){
					$(wrapper).html(data);
					$('#newsletter_email').val(newsletter_email);
					$('.continue-shopping', wrapper).click(function(){
						window.cover.hide();
						return false;
					});
				});
				
				});
		}
		return false;
	});
	
	if( $.browser.safari && navigator.platform.indexOf('Win') != -1 ){
		var s = navigator.userAgent.indexOf('Version/') + String('Version/').length;
		if( parseInt(navigator.userAgent.substr(s, navigator.userAgent.indexOf('Safari') - s)) <= 3 )
			$('body').addClass('safari3');
		}
	
	});
	
	if( $.browser.msie) {
		$('html').addClass('ie').addClass('ie'+ parseInt($.browser.version));
	}
	
	
	 if ($.browser.mozilla) {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).css({
					'MozUserSelect' : 'none'
				});
			});
		};
	} else if ($.browser.msie) {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).bind('selectstart', function() {
					return false;
				});
			});
		};
	} else {
		$.fn.disableTextSelect = function() {
			return this.each(function() {
				$(this).mousedown(function() {
					return false;
				});
			});
		};
	}
	
})(jQuery);

