var galW;
var qty;

function openGallery(){
	window.scrollTo(0,0);
	docWidth = $(window).width();
	docHeight = $(window).height();
	popupWidth = $('#gallery').width();
	popupHeight = $('#gallery').height();
	
	posLeft = (docWidth/2)-(popupWidth/2);
	posTop = (docHeight/2)-(popupHeight/2);
	
	$('#gallery').css({'left': posLeft+'px','top' : posTop+'px'});
	$('#gallery-shadow').show();
	$('#gallery').show();
}
function closeGallery(){
	$('#gallery-shadow').hide();
	$('#gallery').hide();
}

function next() {
	actualPos = $('#gallery-list ul').css('left');
	newPos = actualPos.replace('px','')-galW;
	if(newPos==(-(galW*qty))) newPos=0;
	$('#gallery-list ul').css('left',newPos+'px');
	//$('#gallery-list ul').animate({left:newPos+'px'},1000);
}

function previous() {
	actualPos = $('#gallery-list ul').css('left');
	newPos = parseInt(actualPos.replace('px',''))+parseInt(galW);
	if(newPos==galW) newPos=-(galW*(qty-1));
	$('#gallery-list ul').css('left',newPos+'px');
	//$('#gallery-list ul').animate({left:newPos+'px'},1000);
}

$(document).ready(function(){
	$('#gallery-shadow').css({opacity:0.5});
	galW = parseInt($('#gallery-list ul').attr('class'));
	qty = parseInt($('#gallery-list ul').attr('id'));
	
	$('#gallery-list').css('width',galW+'px');
	$('#gallery-link a').click(function(){
		openGallery();
	});
	$('#gallery-close').click(function(){
		closeGallery();
	});
	$('#gallery-prev').addClass();
	$('#gallery-prev').click(function(){
		previous();
	});
	$('#gallery-next').addClass();
	$('#gallery-next').click(function(){
		next();
	});
	
});
