$(document).ready(function(){
	
if ($('#galery li').size() > 0)
{
	foto_height=parseInt($('#galery li').css('height'))+parseInt($('#galery li').css('marginBottom'));
	fix_height=parseInt($('#bord').css('height'));
	foto_cnt=$($('#galery').children().get()).length;
	zmina=false; //if setInterval can*t work (fast click?)
	item=10;
	
	function scroll_next(offset)
	{	
			if(foto_height*foto_cnt>fix_height && parseInt($('#galery').css('top'))>foto_height*foto_cnt*(-1)+fix_height)
			{
				new_top=parseInt($('#galery').css('top'))-offset;		
				$('#galery').css({'position':'relative', 'top':new_top+'px'});	
				zmina=true;
			}	
	}
	
	function scroll_prev(offset,click)
	{	
		if(foto_height*foto_cnt>fix_height && parseInt($('#galery').css('top'))<0)
		{	
			new_top=parseInt($('#galery').css('top'))+offset;		
			$('#galery').css({'position':'relative', 'top':new_top+'px'});
			zmina=true;
		}
	}
	
	$('#next').mousedown(function(){
		t=setInterval('scroll_next(item)',5);	
	})
	
	$('#next').mouseup(function(){
		clearInterval(t);
	})
	
	$('#next').click(function(){
		if(zmina==false)
		{
			scroll_next(item);
		}
		zmina=false;
	})
	
	$('#prev').mousedown(function(){
		t=setInterval('scroll_prev(item)',5);	
	})
	
	$('#prev').mouseup(function(){
		clearInterval(t);
	})
	
	$('#prev').click(function(){
		if(zmina==false)
		{
			scroll_prev(item);
		}
		zmina=false;
	})
	
	
	////////////////////////load foto//////////////////////////////
	
	$("#galery img").click(function(){
		link=$(this).attr('src').replace(/_2./,'_1.');	
		$("#main_galery_img").attr({'src': link});
		alt=$(this).attr('alt');
		$('#main_galery_comment').text(alt);
	
	})
}
	/////////////////////Rating stars////////////////////////////////
	var stars=new Array();
	for(i=1;i<=5;i++)
	{
		name="#star_"+i;
		stars[i]=$(name).attr('class');
	}
	
	
	$('.rating div').mouseover(
		function(event){	
			event = event || window.event
			event.stopPropagation ? event.stopPropagation() : (event.cancelBubble=true)	
		
			id=($(this).attr('id')).substr(5);
			for(i=1;i<=id;i++)
			{
				name='#star_'+i;									
				$(name).attr({'class' : 'full_star'});					
			}
			
			for(j=id;j<=5;j++)
			{
				name='#star_'+j;									
				$(name).attr({'class' : 'empty_star'});			
			}
			$(this).attr({'class' : 'full_star'})
		})
	
	
	$('.rating').mouseout(function(event){	
		for(i=1;i<=5;i++)
		{
			name='#star_'+i;	
			$(name).attr({'class' : stars[i]}); 		 
		}	
	})	
})

