var portfolio_num = 0;
var portfolio_max = $('.gallery_container ul li').size()-3-1; // Всего - видимые - 1
var gallery = $('.gallery_container ul');
var gallery_item_width = -parseInt($('.gallery_container ul li').css('width'));

var Header = {
	addFade : function(selector)
	{
		$('<span class="fake-hover"></span>').css("display", "none").prependTo($(selector)); 
		$(selector+" a").bind("mouseenter",function(){
			$(selector+" .fake-hover").fadeIn("normal");
		});
		
		$(selector+" a").bind("mouseleave",function(){
			$(selector+" .fake-hover").fadeOut("normal");
		});
	}
}

$(document).ready(function(){
	
	$('.left_arrow span').click(function(){
		if(portfolio_num > 0){
			portfolio_num--;
		}else{
			portfolio_num = portfolio_max + 1;
		}
		gallery.animate({left:'' + (portfolio_num*gallery_item_width) + 'px'}, 'slow')
	})
	
	$('.right_arrow span').click(function(){
		if(portfolio_num <= portfolio_max){
			portfolio_num++;
		}else{
			portfolio_num = 0;
		}
		gallery.animate({left:'' + (portfolio_num*gallery_item_width) + 'px'}, 'slow')
		
	})
	
	$('#slider').mouseenter(function(){
		$(this).stop().animate({left:'0px'}, 'slow');
	})
	
	$('#slider').mouseleave(function(){
		$(this).stop().animate({left:'-245px'}, 'slow');
	})
	
	Header.addFade("#header");
	
	var img1= new Image();
	img1.src="../images/menu1_link.jpg";
	var img2= new Image();
	img2.src="../images/menu2_link.jpg";
	var img3= new Image();
	img3.src="../images/menu3_link.jpg";
	var img4= new Image();
	img4.src="../images/menu4_link.jpg";
	var img5= new Image();
	img5.src="../images/menu5_link.jpg";
	
	$("#button1").parent().mouseenter(function(){
		$("img", this).attr("src", "images/knopka1u.png");
	}).mouseleave(function(){
		$("img", this).attr("src", "images/knopka1.png");
	})
	$("#button2").parent().mouseenter(function(){
		$("img", this).attr("src", "images/knopka2u.png");
	}).mouseleave(function(){
		$("img", this).attr("src", "images/knopka2.png");
	})
	$("#button3").parent().mouseenter(function(){
		$("img", this).attr("src", "images/knopka3u.png");
	}).mouseleave(function(){
		$("img", this).attr("src", "images/knopka3.png");
	})
	$("#button4").parent().mouseenter(function(){
		$("img", this).attr("src", "images/knopka4u.png");
	}).mouseleave(function(){
		$("img", this).attr("src", "images/knopka4.png");
	})
});


