$(document).ready(function() {

	// Set Scroll Default
	$.scrollTo.defaults.axis = 'x';

	// Apply classes, get the list ready for action
	$("#slidebox ul.portfolio > li").addClass("frame");

	// Select the first frame and get its width 
	// ?? // ?? // ?? ===== SAFARI CALCULATES THIS WRONG
	var firstFrame = $("#slidebox ul.portfolio > li:first");
	var frameWidth = $(firstFrame).width();
	
	// Find out how many frames there are
	var frameCount = $("#slidebox ul.portfolio > li").length;
	
	// Calculate and set the frame width of the parent ul
	var parentWidth = frameCount * (frameWidth + 77);
	$("#slidebox ul.portfolio").width(parentWidth);
					
	
	// START THE CLOCK
	var position = 0;
	var max_pos = frameCount;
	
	// Button Oppacity
	//$("#prev").animate({opacity: 0.5}, 0);
	var prev = 0;
	var next = 1;
	
	
	// If you click next
	$("#next").click(function() {
			
		
		if(position == (max_pos - 1)) {
			$("#slidebox").scrollTo($("#slidebox ul li:first"), 1730, {offset:-15, easing:'easeOutQuint'});
			position = 0;
			return false;
		}else{
			position = position + 1;
			$("#slidebox").scrollTo($("#slidebox ul li:eq("+position+")"), 1730, {offset:-15, easing:'easeOutQuint'});	
			//alert(position);
			return false;
	
		}
	});
	
	$("#prev").click(function() {
	
		if(position == 0) {
			$("#slidebox").scrollTo($("#slidebox ul li:last"), 1730, {offset:-15, easing:'easeOutQuint'});
			position = max_pos - 1;
			return false;
		}else{
			position = position - 1;
			$("#slidebox").scrollTo($("#slidebox ul li:eq("+position+")"), 1730, {offset:-15, easing:'easeOutQuint'});	
			//alert(position);
			return false;
	
		}
	});
	
	
	
	// Debug
	//alert(frameWidth);

});
