// JavaScript Document
var w = 0;
var imageIndex = 0;

$(document).ready(function() {
						   
	$('#arrowleft').click(function() {
		moveRight();
	});
	
	$('#arrowright').click(function() {
		moveLeft();
	});
	
	$('a[rel=external]').attr('target','_blank');
	
	$('#imageGallery img').each(function(){
		w+= $(this).attr('width');
	});
	
	$('.cycle').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	//$('a.fancy').colorbox();
	
	$('a.fancy').prettyPhoto({
			social_tools: '',
			overlay_gallery: false
	});
	
	Cufon.replace('#headmenu li a', {hover: 'true'});
	Cufon.replace('#headmenu li span,#gallery #info p, .collection .controls .info p, .textblock h2, .store h2, #column4 h2, .textblock h1');
	
});

function moveRight(){
	var rightPos = $('#imageGallery').position().left;
	
	if(!$("#imageGallery").is(':animated'))
	{
		if(rightPos < 0){
			imageIndex--;
			
			var imageWidth = $('#imageGallery img:eq('+(imageIndex)+')').attr('width');
			var newPos = rightPos + imageWidth;
			
			$('#imageGallery').animate({'left':''+newPos+'px'},500);
		}
	}
}

function moveLeft(){
	var leftPos = $('#imageGallery').position().left;
	
	if(!$("#imageGallery").is(':animated'))
	{
		if(leftPos >= -(w-500)){
			imageIndex++;
			
			var imgWidth = $('#imageGallery img:eq('+(imageIndex-1)+')').attr('width');
			var newPosition = leftPos - imgWidth;
		
			$('#imageGallery').animate({'left':''+newPosition+'px'},500);
		}
	}
}
