$(document).ready(function(){
    
    $('h1, p.head').gradientText({
        colors: ['0a87c3', 'c909d7']
    });    
    
    $('.cart .border').html('<div class="added"><b>Товар добавлен в корзину</b></div>' + $('.cart .border').html());
   	   	
   	$('.cart .border').hover(function(){
		
		$(this).css({'border-style':'solid'});
		$('.border .more').show();
	
	},
	function(){
		
		$(this).css({'border-style':'dashed'});
		$('.border .more').hide();
		
});

$(
	function() {
		var $photoLink = $('p.photo a'),
			$popupBlock = $('#popup_block')
			$popup = $('#popup_block .popup')
			$itemImage = $('.description .image');
		
		$itemImage.css({'cursor':'pointer'});
		$itemImage.html('<div class="zoom"></div>'+$itemImage.html()); 
		
		$photoLink.click(function(){
			$popupBlock.show();				
			return false;		
		});
		
		$itemImage.click(function(){
			$popupBlock.show();				
			return false;		
		});
		
		$popupBlock.click(function(){
			$popupBlock.hide();
		});	
		
	}
);

$(
	function() {
		var $item_package_line = $('.mpcatalog ul li');
										
		$item_package_line.each(function(i){			
			$(this).hover(function(){
				$item_hover_line = $('.bg', $(this));
				$item_hover_line.css({'background':'#ebebeb'});
			}, 
			function(){
				$item_hover_line = $('.bg', $(this));
				$item_hover_line.css({'background':'none'});
			});
		});
	}
)

$(
	function() {
		var $loginLink = $('.header .memberlogin a.enterlink'),
			$loginBlock = $('.header .loginform')
			$popup = $('.header .loginform .popup')
			$closeBut = $('.header .loginform .close');
			
		$('.loginform table td input, #lgn input').keypress(function(event) {
			 if (event.which == '13') {
			    $('.loginform form').submit();
			  }
		});
		
		$loginLink.click(function(){
			$loginBlock.show();				
			return false;		
		});		
		
		$closeBut.click(function(){
			$loginBlock.hide();
		});	
		
	}
);

$(
	function() {
		var $packages_row = $('.mpcatalog .spacer .packages table tr');
										
		$packages_row.each(function(i){			
			$(this).hover(function(){
				$(this).css({'background':'#ebebeb'});				
			}, 
			function(){
				$(this).css({'background':'none'});
			});
		});
	}
)

$(
	function() {
		var $packages_td = $('.mpcatalog .spacer .packages table td.one ins');			
										
		$packages_td.each(function(i){						
			$(this).hover(function(){
				$(this).html($(this).html()+'<div class="bonustip"><b>5</b> табл. Дженерик Виагры <b>абсолютно бесплатно!</b></div>')
				$bonusLink = $('.bonustip', $(this));
				$bonusLink.fadeIn(200);			
			}, 
			function(){				
				$bonusLink.fadeOut(100);
			});
		});
	}
)



$(
	function() {
		var $lenta = $('.adv .lenta'),
			$arLeft = $('.adv .arr_left'),
			$arRight = $('.adv .arr_right');
			cl=0,
			running=false,
			hw=0,
			count = $('.adv .lenta ul li').length;
			
			if(count < 2) {
				$arLeft.hide();
				$arRight.hide();	
			}
			
			rnd = Math.floor(Math.random()*count);
			cl = rnd;
			hw = -728*rnd;
			$lenta.css( { 'margin-left': -728*rnd+"px" });
									
			$arRight.click(function(){					
					if (!running)
					{					
						
						
						running=true;
						cl++;
						
						if (cl==count)
						{							
							hw = 728;
							cl = 0;
						}	
									

						$lenta.stop().animate( { 'margin-left': (hw-740)+"px" }, 500, null, function(){
							$lenta.animate({'margin-left': (hw-728)+"px" },200,null,function(){
								running=false;
								hw-=728;
							});
						});						

					}



					return false;
				});
			
				$arLeft.click(function(){

						if (!running)
						{	
							if (cl==0)
							{
								cl=count;
								hw = -728*cl;
							}								
																			
							running=true;
							cl--;

									

							$lenta.stop().animate( { 'margin-left': (hw+740)+"px" }, 500, null, function(){
								$lenta.animate({'margin-left': (hw+728)+"px" },200,null,function(){
									running=false;
									hw+=728;
								});
							});
							
						}



						return false;
					});
					
				
				
			
	}
)

  
   
});



