$(document).ready(function(){

	setInterval(function(){
  $('#more').click();
  },4000);
	
	if ($('dl.accordion').length){
		$('dl.accordion dd:gt(0)').hide();
		$('dl.accordion dt a').click(function(){
			var el = $(this).parent().next('dd');
			$('dl.accordion dd').not(el).hide();
			el.toggle();
			return false;
		});
	}

	if($('.order-card ul').length){
		var sht = $('.order-card ul li').height();
		$('.order-card ul').css({overflow:'hidden'});
        function hidscroll(){
	        var oheight = $('.order-card ul').height();
	        var sheight = $('.order-card ul').get(0).scrollHeight;
			if (oheight < sheight){
				if ($('.order-card ul').scrollTop() < (sheight-oheight)){
	        		$('.order-card .stb').css({visibility: 'visible'});
	        	}else{
					$('.order-card .stb').css({visibility: 'hidden'});
	        	}
	        	if ($('.order-card ul').scrollTop() > 0){
	        		$('.order-card .stt').css({visibility: 'visible'});
	        	}else{
	        		$('.order-card .stt').css({visibility: 'hidden'});
	        	}
			}else{
				$('.order-card .stt, .order-card .stb').css({visibility: 'hidden'});
			}
		}
		hidscroll();

		$('.order-card .stt').hover(
		function(){$(this).css({'background-position': 'top right'});},
		function(){$(this).css({'background-position': 'top left'});});

		$('.order-card .stb').hover(
		function(){$(this).css({'background-position': 'bottom right'});},
		function(){$(this).css({'background-position': 'bottom left'});});

		$('.order-card .stt').click(function(){
			$('.order-card ul').animate({'scrollTop': '-='+sht},200, null, hidscroll);
		});
		$('.order-card .stb').click(function(){
			$('.order-card ul').animate({'scrollTop': '+='+sht},200, null, hidscroll);
		});
	}

	if ($('.gallery').length){
		function sdisable(){
			var owg = $('.container').get(0).offsetWidth;
			var swg = $('.container').get(0).scrollWidth;
			if (owg<swg){
				if ($('.container').scrollLeft() < (swg-owg)){
        			$('a.toright').removeClass('disable');
	        	}else{
					$('a.toright').addClass('disable');
	        	}
	        	if ($('.container').scrollLeft() > 0){
	        		$('a.toleft').removeClass('disable');
	        	}else{
	        		$('a.toleft').addClass('disable');
	        	}
			}else{
				$('a.toleft, a.toright').addClass('disable');
			}
		}
		sdisable();
		$(document).load(function(){
			$(window).resize(sdisable);
			sdisable();
		});
		$('a.toleft').click(function(){
			$('.container').animate({
				'scrollLeft': '-=200'
			},200, null, sdisable);
			return false;
		});
		$('a.toright').click(function(){
			$('.container').animate({
				'scrollLeft': '+=200'
			},200, null, sdisable);
			return false;
		});
		$('.container a').click(function(){
			$('.container a').removeClass('active');
			$(this).addClass('active');
			var gurl = this.href;
			$('.gallery-img').empty().addClass('load');
			var gimg = $('<img src="'+gurl+'" alt="">').appendTo("body").css({position:'absolute',top:-5000,left: -5000});
			gimg.load(function(){
				$('.gallery-img').animate({
					height: this.height,
					width: this.width
				},200,null,function(){
					$('.gallery-img').empty().removeClass('load');
					gimg.appendTo($('.gallery-img')).css({position:'static',top:'auto',left:'auto'});
					$('.footer p').get(0).innerHTML+='';
				});
                return false;
			});
			return false;
		});
		$('.container a:eq(0)').trigger('click');
	}

	$('#form-show').click(function(){
		$('.form-hidden').toggle();
		$('.form-hidden').find('.close').click(function(){
			fh.remove();
			$('.form-hidden').hide();
		});
		var fh = $('<div></div>').css({
			height: $('body').get(0).offsetHeight,
			width: '100%',
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex: 10
		}).click(function(){
			$('.form-hidden').hide();
			$(this).remove();
		}).appendTo($('body'));
		return false;
	});
	$('.ipod a').click(function(){
		$('.ipod').css({'background-position': 'top center'});
		$(this).hide();
		return false;
	});

	if ($('#more').length){
		var an = 0;
		var nws = $('.new-item');
		$('#more').click(function(){
			if (an<nws.length-1){
				an++;
			}else{
				an = 0;
			}
			$('.ncnt').animate({
				marginLeft: '-'+(an*100)+'%'
			},1000);
			return false;
		});
	}

	$('.product-item').click(function(){
		$('.products-form').show();
		$('.products-form div.titem').hide();
		$('.'+this.id).css({display:'block',top: $(this).offset().top});
		return false;
	});

	$('.products-form div.bg').click(function(){
		$('.products-form').hide();
	});

	$('.formsubmit').click(function(){
		$(this).parents('form').submit();
		return false;
	});
	
	
	$('div.footer a.sl').click(function(){
		$('div.footer div.sl').toggle();
		return false;
	});
});

		function open_window(link,w,h) //opens new window
		{
			var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
			newWin = window.open(link,'newWin',win);
			newWin.focus();
		}

		function confirmDelete() //unsubscription confirmation
		{
			temp = window.confirm('Удалить?');
			if (temp) //delete
			{
				window.location="index.php?killuser=yes";
			}
		}

		function validate_custinfo() //validate customer information
		{
			if (document.custinfo_form.first_name.value=="" || document.custinfo_form.last_name.value=="")
			{
				alert("Укажите имя");
				return false;
			}
			if (document.custinfo_form.email.value=="")
			{
				alert("Укажите адрес электронной почты");
				return false;
			}
			if (document.custinfo_form.country.value=="")
			{
				alert("Укажите страну");
				return false;
			}
			if (document.custinfo_form.state.value=="")
			{
				alert("Укажите область");
				return false;
			}
			if (document.custinfo_form.zip.value=="")
			{
				alert("Укажите почтовый индекс");
				return false;
			}
			if (document.custinfo_form.city.value=="")
			{
				alert("Укажите город");
				return false;
			}


			return true;
		}


