
$(document).ready(function(){
	
	if ($.browser.msie && $.browser.version == 6) {
		$('input.but-order').hover( function(){ $(this).addClass('over'); } , function(){ $(this).removeClass('over'); } );
	}
	
	
	/*$('ul.ul-menu-left > li > a').click(function(){
		$("~ul",$(this)).slideToggle();
		$(this).toggleClass('current');
		return(false);
	});*/
	
	$('div.box-shop').each(function(){
		var param = {
			count:$('>div.right-col >div.scroll >table.tab-shop >thead td',this).length - 3,
			current:1,
			next:$('>div.box-scrolling >div.scrolling >a.next',this),
			prev:$('>div.box-scrolling >div.scrolling >a.prev',this),
			scrolling:$('>div.right-col >div.scroll',this),
			scrollBut:$('>div.box-scrolling div.but',this),
			scrollNum:$('>div.box-scrolling div.scroll',this),
			scrollWid:(Math.round(242/(($('>div.right-col >div.scroll >table.tab-shop >thead td',this).length - 1)/2))),
			scrollWid2:(Math.round((242/(($('>div.right-col >div.scroll >table.tab-shop >thead td',this).length - 1)/2)-20)/2))
		}
		
		if(param.count > 0){
			var param2 = {
				butStep:Math.round((242-param.scrollWid)/param.count),
				butLast:242-param.scrollWid
			}
			
			$(param.scrollBut).css('width',param.scrollWid);
			$('strong',param.scrollBut).css('width',param.scrollWid2)
			$(param.next).click(function(){
				if(param.current <= param.count){
					param.current++;
					$(param.scrolling).animate({left:parseInt($(param.scrolling).css('left')) - 150},300);
					$(param.scrollNum).animate({left:parseInt($(param.scrollNum).css('left')) - param.scrollWid2},300);
					$(param.scrollBut).animate({left:((param.current>param.count)?param2.butLast:parseInt($(param.scrollBut).css('left')) + param2.butStep)},300);
				}
				return(false);
			});
			
			$(param.prev).click(function(){
				if(param.current > 1){
					param.current--;
					$(param.scrolling).animate({left:parseInt($(param.scrolling).css('left')) + 150},300);
					$(param.scrollNum).animate({left:parseInt($(param.scrollNum).css('left')) + param.scrollWid2},300);
					$(param.scrollBut).animate({left:((param.current<=1)?0:parseInt($(param.scrollBut).css('left')) - param2.butStep)},300);
				}
				return(false);
			});
		}else $('>div.box-scrolling',this).hide();
		
		$('table.tab-shop >thead td >a',this).hover(function(){
				$('>div.box-about-shop-2','body').stop(true).filter('[id!='+$(this).parent().index()+']').remove();
				if(!$('>div.box-about-shop-2[id='+$(this).parent().index()+']','body').length)
					$(this).animate({marginRight:0},1000,function(){ listAbout({
							html:$('~div.box-about-shop-2',this).html(),
							height:$('~div.box-about-shop-2',this).height() + 5,
							lnk:$(this),
							index:$(this).parent().index()
						});
					});
			},function(){
				$(this).animate({marginRight:0},200,function(){ $('>div.box-about-shop-2','body').remove(); });
			});
	});
	
	$('ul.ul-list-1 li').each(function(){
		var param = {
			href:$('div.name >a',this).attr('href'),
			name:$('div.name >a',this).html(),
			img:$('div.img',this),
			desc1:$('div.desc-1',this).html(),
			desc2:$('div.desc-2',this).html(),
			rrt:$('div.rrt',this).html(),
			bestprice:$('div.best-price >b',this).html()
		}
		
		$('>div.box-2',this).hover(function(){
				$('>div.box-list-info','body').remove();
				$(this).animate({marginRight:0},1000,function(){ listInfo(param); });
			},function(){
				$(this).stop(true);
			}
		)
	});
	
	
	if($('#block-item-sub >div.box-2').length > 6){
		itemsPar = {
			block:$('#block-item'),
			subBlock:$('#block-item-sub'),
			count:$('#block-item-sub >div.box-2').length - 1,
			current:0
		}
		
		$('>h3',itemsPar.block).after('<a href="#prev" class="prev"><img src="/css/img/prev-1.gif" alt="prev" /></a><a href="#next" class="next"><img src="/css/img/next-1.gif" alt="next" /></a>');
		
		$(itemsPar.subBlock).append($(itemsPar.subBlock).html());
		
		$('> a',itemsPar.block).click(function(){
			move = ($(this).attr('class') == 'next')?++itemsPar.current:--itemsPar.current;
			
			if(move < 0){
				$(itemsPar.subBlock).animate({'left':(0-(itemsPar.count+1)*148)+'px'},0);
				itemsPar.current = itemsPar.count;
				move = itemsPar.count;
			}else if(move > itemsPar.count + 1){
				$(itemsPar.subBlock).stop(true).animate({'left':0},0);
				itemsPar.current = 1;
				move=1;
			}
			
			$(itemsPar.subBlock).stop().animate({'left':(0-(move*148))+'px'},300);
			return(false);
		});
	}
});


function listInfo(param){
	var div = '<div class="box-list-info"><div class="deco-1"><div class="deco-2">';
	div += '<h6>'+param.name+'</h6>';
	div += '<div class="desc-1">'+param.desc1+'</div>';
	div += '<div class="img">'+$(param.img).html()+'</div>';
	div += '<div class="desc-2">'+param.desc2+'</div>';
	div += '<div class="price"><small>RRT:</small> '+param.rrt+'<br /><small class="green">Bestprice:</small> <strong class="green">'+param.bestprice+'</strong></div>';
	div += '<a href="'+param.href+'" class="but-1"><b><small>More</small></b></a>';
	div += '</div></div></div>';
	
	$('body').append(div);
	var info = $('>div.box-list-info','body');
	var img = $('div.img >img',info);
	var offsetL = $(img).offset().left;
	var offsetT = $(img).offset().top;
	var offsetL2 = $(param.img).offset().left;
	var offsetT2 = $(param.img).offset().top;
	
	
	$(info).css({'top':offsetT2-offsetT,'left':offsetL2-offsetL,'opacity':0}).animate({opacity:1},600,function(){ $('a.but-1',this).css('position','relative'); $(this).hover(function(){
			$(this).stop(true);
		},function(){
			$(this).animate({marginLeft:0},200,function(){ $(this).remove(); });
		}).click(function(){ $(this).remove(); }); });
}

function listAbout(param){
	$('body').append('<div class="box-about-shop-2" id="'+param.index+'">'+param.html+'</div>');

	var about = $('>div.box-about-shop-2','body');
	var offsetL = $(param.lnk).offset().left;
	var offsetT = $(param.lnk).offset().top;
	
	$(about).css({'top':offsetT-param.height,'left':offsetL,'opacity':0}).animate({opacity:1},600).hover(function(){
			$(this).css('opacity',1).stop(true);
			$(param.lnk).stop(true);
		},function(){
			$(this).animate({marginLeft:0},200,function(){ $(this).remove(); });
		}).click(function(){ $(this).remove(); }); 
}


