$(function(){
	if ($.browser.msie) {
		$('ul.menu a, ul.mn a').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
	}
//	if ($('div.models').length) {
//		
//		function svalidate(){
//			if (mpointer.position().left <= 0) {
//				$('#tl').addClass('nactive');
//			}
//			else {
//				$('#tl').removeClass('nactive');
//			}
//			if (mpointer.position().left >= Math.round(mow - pw)) {
//				$('#tr').addClass('nactive');
//			}
//			else {
//				$('#tr').removeClass('nactive');
//			}
//		}
//		
//		var dmodels = $('div.models').css('overflow', 'hidden');
//		dmodels.scrollLeft(0);
//		var msc = $('<div class="scroll"><div class="cnt"><span class="p"></span></div><a href="#" id="tl"></a><a href="#" id="tr"></a></div>');
//		var mscroll = msc.find('div.cnt');
//		var mpointer = mscroll.find('span.p');
//		msc.insertAfter('div.wrap');
//		
//		var mow = 890;
//		var msw = dmodels.get(0).scrollWidth;
//		
//		var pw = (mow * mow / msw);
//		var shag = (msw - mow) / (mow - pw);
//		mpointer.css('width', pw);
//		mpointer.draggable({
//			containment: 'parent',
//			snap: true,
//			axis: 'x',
//			drag: function(event, ui){
//				dmodels.scrollLeft(ui.position.left * shag);
//			},
//			stop: svalidate
//		});
//		
//		var a = [];
//		dmodels.find('ul').each(function(){
//			var tle = $(this).attr('title');
//			if ($.inArray(tle, a) == -1) {
//				a.push(tle);
//				$('<span><a href="#' + tle + '">' + tle + '</a></span>').css({
//					left: ($(this).position().left / shag)
//				}).appendTo(mscroll);
//			}
//		});
//		
//		function anim(l){
//			mpointer.animate({
//				left: ((l + pw) >= mow) ? Math.round(mow - pw) : ((l <= 0) ? 0 : l)
//			}, 300);
//			dmodels.animate({
//				scrollLeft: ((l * shag) >= msw - mow) ? Math.round(msw - mow) : l * shag
//			}, 300, '', svalidate);
//		}
//		mscroll.find('span a').click(function(){
//			var l = $(this).parent().position().left;
//			anim(l);
//			return false;
//		});
//		
//		svalidate();
//		$('#tr, #hr').click(function(){
//			if (!$(this).hasClass('nactive')) {
//				var l = mpointer.position().left + (130 / shag);
//				anim(l);
//			}
//			return false;
//		});
//		$('#tl, #hl').click(function(){
//			if (!$(this).hasClass('nactive')) {
//				var l = mpointer.position().left - (130 / shag);
//				anim(l);
//			}
//			return false;
//		});
//	}
	
	$('#hr').hover(function(){
		$('#strl').css('background-position','-21px 0');
	},function(){
		$('#strl').css('background-position','');
	});
	$('#hl').hover(function(){
		$('#strl').css('background-position','-42px 0');
	},function(){
		$('#strl').css('background-position','');
	});
	
	if ($('div.preview').length){
		$('div.preview').css('overflow', 'hidden');
		$('div.preview').scrollLeft(0);
//		$('#hr').click(function(){
//			$('div.preview').animate({
//				scrollLeft: '+=110px'
//			},200);
//			return false;
//		});
//		$('#hl').click(function(){
//			$('div.preview').animate({
//				scrollLeft: '-=110px'
//			},200);
//			return false;
//		});
		
		function block(){
			$('div.preview a').unbind('click');
			$('div.preview a').click(function(){
				return false;
			});
		}
		function unblock(){
			$('div.preview a').unbind('click');
			$('div.preview a').click(function(){
				$('div.preview a').removeClass('active');
				$(this).addClass('active');
				var ur = this.href;
				var cn = $('dl.model dt');
				cn.css('height',cn.height());
				cn.empty().addClass('load');
				var im = $('<img />').load(function(){
					var cn = $('dl.model dt');
					cn.empty().removeClass('load');
					var h = this.height;
					cn.animate({
						height: h
					},100,'',function(){
						im.appendTo(cn);
						unblock();
					});
				});
				im.attr('src',ur);
				block();
				return false;
			});
		}
		unblock();
		$('div.preview a:eq(0)').click();
	}
	
	$('dl.lang dt a').click(function(){
		$('dl.lang dd').slideToggle(200);
		return false;
	});
	
	$('form.ac p.add a').click(function(){
		var cl = $('<p class="photo"><label class="s4"><input type="file" class="file" name="photo[]" /> <a href="#" class="del"></a></label></p>');
		cl.insertAfter('form.ac p.photo:last');
		cl.find('a.del').click(function(){
			$(this).parents('p.photo').remove();
			return false;
		});
		return false;
	});
	
	$('div.crumbs select').change(function(){
		document.location.href = this.value;
	});
});
