var jde = new Object();
jde = {
	ie_sucks: function() {
		$('.footer .left ul').css('letter-spacing','-0.03em');
		$('.footer .left ul li').css('margin-right','5px');

		$('.content .content-right .main-category a.image img').css('width','auto');
		$('.content .search-results .main-category ul li img').each(function(){
			if ($(this).width()>205) {
				$(this).css('width','205px !important');
			}
		});
		$('.content .the-category .main-category ul li img').each(function(){
			if ($(this).width()>205) {
				$(this).css('width','205px');
			}
		});

		$('.content .search-results .products ul li .image a img').each(function(){
			if ($(this).width()>170) {
				$(this).css('width','170px');
			}
		});

		$('.content .page-content .content-right ul.presse li .image img').each(function(){
			if ($(this).height()>150) {
				$(this).css('height','150px');
			}
		});
		$('.content .search-results .products ul li .image a').each(function(){
			var left = (200-$(this).width())/2;
			$(this).css('left',left+'px');
		});
		$('.content .content-right .products ul li a.image img').each(function(){
			if ($(this).width()>110) {
				$(this).css('width','110px');
			}
		});
		$('.content .content-right .similar-products .middle ul li .image a').each(function(){
			var left = (200-$(this).width())/2;
			$(this).css('left',left+'px');
		});
		$('.content .content-right .similar-products .middle ul li .image a img').each(function(){
			if ($(this).width()>120) {
				$(this).css('width','120px');
			}
		});
		$('.content .content-right .similar-products.institute-products .middle ul li .image a img').each(function(){
			if ($(this).height()>150) {
				$(this).css('height','150px');
			}
		});
	},
	ready: function() {
		Cufon.set('fontFamily', 'Futura').replace('.header .menu ul li a.main,'
					+'.header .menu ul li h3,'
					+'.content .content-right .products h3,'
					+'.content .content-header h2,'
					+'.content .content-right .product h1,'
					+'.content .page-header .text1,'
					+'.content .page-header .text2,'
					+'.content .page-content .content-right .columns.philosophy .column-1 h2,'
					+'.content .page-content .content-right .columns.philosophy .column-2 h2,'
					+'.content .page-content .content-right .columns.philosophy .column-3 h2,'
					+'.content .page-content h1.new-design,'
					+'.content .page-content .content-right h1,'
					+'.content .page-content .content-right h2.cufon-must-activate,'
					+'.content .search-results h2.stitle,'
					+'.content .jean-categories h1,'
					+'.content .content-right .institute h1,'
					+'.user .content .content-right .head h1,'
					+'.header .options .search form label span');
		Cufon.set('fontFamily', 'Futura Lt BT').replace('.content .content-right .similar-products h3');
		Cufon.set('fontFamily', 'Adobe Garamond Pro').replace('.content .brand-header .text1,'
			+'.content .brand-header .text2,'
			+'.content .philosophy-header .text1,'
			+'.content .philosophy-header .text2');

		$('body').click(function (event) {
			if (!$(event.target).is('.current-language,.current-language *')) {
				$('#all-languages').hide();
			}
		});

		$('.new-design-content p:first').css('margin-top',0);


		if ($.browser.msie) {
			setTimeout(jde.ie_sucks,100);
		}

		$('.content .sidebar-left ul li a').each(function(){
			$(this).click(function(){
				return jde.category.expand(this);
			});
		});
	},
	category: {
		expand: function(_this) {
			/*if ($(_this).parent().children('ul').length==1) {
				$(_this).parent().toggleClass('expanded');
				$(_this).parent().children('ul').slideToggle('fast');
				return false;
			}*/
			return true;
		}
	},
	findUs: {
		loadRegions: function(_this) {
			$('.column-regions').hide();
			$('.column-cities').hide();
			$('.column-addresses').hide();

			$('.column-countries ul li a').removeClass('selected');
			$(_this).addClass('selected');

			$(_this).children('.load').show();

			$.get($(_this).attr('href'),null,function(result){
				$('.column-regions').html(result);
				$('.column-regions').show();

				$(_this).children('.load').hide();
				$.scrollTo('#find-us-title', 500);
			});
			return false;
		},
		loadCities: function(_this) {
			$('.column-cities').hide();
			$('.column-addresses').hide();

			$('.column-regions ul li a').removeClass('selected');
			$(_this).addClass('selected');

			$(_this).children('.load').show();

			$.get($(_this).attr('href'),null,function(result){
				$('.column-cities').html(result);
				$('.column-cities').show();

				$(_this).children('.load').hide();
				$.scrollTo('#find-us-title', 500);
			});
			return false;
		},
		loadLocations: function(_this) {
			$('.column-addresses').hide();

			$(_this).children('.load').show();

			$('.column-cities ul li a').removeClass('selected');
			$(_this).addClass('selected');

			$.get($(_this).attr('href'),null,function(result){
				$('.column-addresses').html(result);
				$('.column-addresses').show();

				$(_this).children('.load').hide();
				$.scrollTo('#find-us-title', 500);
			});
			return false;
		}
	},
	user: {
		ready: function() {
			jde.user.resize();
		},
		resize: function() {
			var w = $('.user .content').width();
			var wl = $('.user .content .sidebar-left').width();
			if (wl>0) {
				var new_width = (w-wl-40);

				if ($.browser.msie && parseFloat(jQuery.browser.version)<8) {
					var new_width = (w-wl+220);
				}

				if (new_width<600) {
					new_width = 600;
					$('.user .content').css('width','910px');
				} else {
					$('.user .content').css('width','auto')
				}
				$('.user .content .content-right').css('width',new_width+'px');
			}
		}
	},
	product: {
		leftInterval: 0,
		rightInterval: 0,
		sliding: false,
		ready: function() {
			var max_el = $('.content .content-right .similar-products .middle .sizer');
			var min_el = $('.content .content-right .similar-products .middle');
			var max_width = $('.content .content-right .similar-products .middle ul').width();
			var min_width = min_el.width();


			if (max_width<=min_width) {
				$('.content .content-right .similar-products .left').hide();
				$('.content .content-right .similar-products .right').hide();
			} else {

				$('.content .content-right .similar-products .left a').click(function(event){
					jde.product.left();
					event.preventDefault();
				});
				$('.content .content-right .similar-products .right a').click(function(event){
					jde.product.right();
					event.preventDefault();
				});
				/*$('.content .content-right .similar-products .left a').mousedown(function(event){
					clearInterval(jde.product.leftInterval);
					clearInterval(jde.product.rightInterval);
					jde.product.leftInterval = setInterval(jde.product.left,10);
					event.preventDefault();
				});
				$('.content .content-right .similar-products .left a').mouseup(function(event){
					clearInterval(jde.product.leftInterval);
					clearInterval(jde.product.rightInterval);
					event.preventDefault();
				});
				$('.content .content-right .similar-products .right a').mousedown(function(event){
					clearInterval(jde.product.leftInterval);
					clearInterval(jde.product.rightInterval);
					jde.product.rightInterval = setInterval(jde.product.right,10);
					event.preventDefault();
				});
				$('.content .content-right .similar-products .right a').mouseup(function(event){
					clearInterval(jde.product.leftInterval);
					clearInterval(jde.product.rightInterval);
					event.preventDefault();
				});*/
			}
		},
		left: function () {
			if (!jde.product.sliding) {
				jde.product.sliding = true;
				var max_el = $('.content .content-right .similar-products .middle .sizer');
				var min_el = $('.content .content-right .similar-products .middle');
				var max_width = $('.content .content-right .similar-products .middle ul').width();
				var min_width = min_el.width();

				var left = parseInt(max_el.css('left'));
				if (left < 0) {
					left += 200;
				} else {
					left = 0;
				}
				max_el.animate({
					left: left
				},'normal',function(){
					jde.product.sliding = false;
				});
			}
		},
		right: function () {
			if (!jde.product.sliding) {
				jde.product.sliding = true;
				var max_el = $('.content .content-right .similar-products .middle .sizer');
				var min_el = $('.content .content-right .similar-products .middle');
				var max_width = $('.content .content-right .similar-products .middle ul').width();
				var min_width = min_el.width();

				var left = parseInt(max_el.css('left'));
				if (left > min_width - max_width) {
					left -= 200;
				} else {
					left = min_width - max_width;
				}
				max_el.animate({
					left: left
				},'normal',function(){
					jde.product.sliding = false;
				});
			}
		}
	}
}
$(document).ready(jde.ready);
