$(document).ready(function () {

	$('#next').live('click', function(){
		$.ajax({
			url: $("#next").attr("rel"),
			beforeSend: function(){
			    $("#next").remove();
			    $("#prev").remove();
			    $("#title-pic").remove();
			    $(".hover").remove();			    
			    $("#loading").show();
			},
			cache: false,
			success: function(html){			    
				$("#layer-t").html(html);
				$("#loading").hide();
			}
		});
	});

	
	$('#prev').live('click', function(){
		$.ajax({
			url: $("#prev").attr("rel"),
			beforeSend: function(){
			    $("#next").remove();
			    $("#prev").remove();
			    $("#title-pic").remove();
			    $(".hover").remove();			    
			    $("#loading").show();
			},
			cache: false,
			success: function(html){
				$("#layer-t").html(html);
				$("#loading").hide();
			}
		});
		return false;
	});
	

	$('.hover').live('mouseenter', function() {
			$(this).find('div').fadeIn(200);
		});
	$('.hover').live('mouseleave', function() {
			$(this).find('div').fadeOut(200);
		});
	
	function ImageList()
	{
		var images = $('.product-pic-click img');
	    var num_images = images.size();
	    var prev_image = 1;
	    var cur_image = 0;
	    function changeImagel() {
		    prev_image = cur_image;
		    cur_image = (cur_image - 1 +num_images )%num_images;			
		    $(images[cur_image]).show();
		    $(images[prev_image]).hide();
	    }
	    $('.product-pic-click img').click(function() {changeImagel();});
	};
	
    ImageList();


    var div = $('#modules');
    div.css({overflow: 'hidden'});
    var position = 0;    
    var step = 20;
    $('#container').mousewheel( function(event, delta) {if (delta > 0){  if($('#scroll-left-arrow').is(':visible')) div.scrollLeft(div.scrollLeft()-delta*step); CheckPosition(); } else if (delta < 0) { if($('#scroll-right-arrow').is(':visible')) div.scrollLeft(div.scrollLeft()-delta*step); CheckPosition();} return false; });
    $('#scroll-right-arrow').click(function(){div.scrollLeft(div.scrollLeft()+2*step); CheckPosition();});
    $('#scroll-left-arrow').click(function(){div.scrollLeft(div.scrollLeft()-2*step); CheckPosition();});        
	
	function CheckPosition() {	
	    //Нужно уменьшать чтоб расширить
	    if($('#container a img:last').position().left<670-$('#container a img:last').width()) {$('#scroll-right-arrow').hide();} else {$('#scroll-right-arrow').show();}
	    if($('#container a img:first').position().left>=30) {$('#scroll-left-arrow').hide();} else {$('#scroll-left-arrow').show();}
	}
});
