$(document).ready(function(){
	
	$("div.scrollable").scrollable({size:7});
	
	$('#galerieLight .thumbAp').each(function(index){
		$(this).click(function(event){
			var title = $('img',$(this)).attr('title');
			var src =  $(this).attr('href');

			$('.img_name p').text('Stadiul construţiei: '+title);					
			
			//$('#resize').attr('src',src);
			
			$('.thumb').removeClass('thumb_activ');
			$(this).addClass('thumb_activ');
			return false;
		});
	});
	
	var images_source = new Array();
	var images_name = new Array();
	$('.thumb').each(function(){
		var src = $(this).attr('href');
		images_source.push(src);
		var title = $('img',$(this)).attr('title');
		images_name.push(title);
	});
	
	var len = images_source.length;
	var pos = 0;
	showLinks(pos,len);
	$('.thumb img').each(function(){
		$(this).css('margin-top',((86-$(this).height())/2)+'px');
	});
	
	
	$('.thumb').each(function(index){
		$(this).click(function(event){
			pos = index;
			event.preventDefault();
			showLinks(pos,len);
			return pos;
		});
	});
	
	$('.next_photo').click(function(){
		
		$('.thumb').removeClass('thumb_activ');
		$('.thumb').eq(pos+1).addClass('thumb_activ');
		
		$('#resize').attr('src',images_source[pos+1]);
		$('.img_name p').text('Stadiul construţiei: '+images_name[pos+1]);
		pos = pos+1;
		if(pos%7==0){
			$("div.scrollable").scrollable().nextPage();
		}
		showLinks(pos,len);
		return false;
	});
	$('.prev_photo').click(function(){
		
		$('.thumb').removeClass('thumb_activ');
		$('.thumb').eq(pos-1).addClass('thumb_activ');
		
		$('#resize').attr('src',images_source[pos-1]);
		$('.img_name p').text('Stadiul construţiei: '+images_name[pos-1]);
		
		if(pos%7==0){
			$("div.scrollable").scrollable().prevPage();
		}
		pos = pos-1;
		console.log(pos);
		showLinks(pos,len);
		return false;
	});	
	
});

function  showLinks(pos,len){
	
		
	
	
	if(pos==len-1){
		$('.next_photo').hide();
		$("div.scrollable").scrollable().nextPage();
	}else{
		$('.next_photo').show();
		
	}
	
	if(pos==0){
		$('.prev_photo').hide();
		$("div.scrollable").scrollable().prevPage();
	}else{
		$('.prev_photo').show();
		
	}
}

