var curItem = 1;
var maxItem = 8;
var timer = null;

var slides = new Array(	
	"/themes/tutorial/images/slide1.jpg",
	"/themes/tutorial/images/slide2.jpg",
	"/themes/tutorial/images/slide1.jpg",
	"/themes/tutorial/images/slide2.jpg",
	"/themes/tutorial/images/slide1.jpg",
	"/themes/tutorial/images/slide2.jpg",
	"/themes/tutorial/images/slide1.jpg",
	"/themes/tutorial/images/slide2.jpg"
);

var urls = new Array(	
	"http://www.google.fi",
	"http://www.focusflow.fi",
	"http://www.recommended.fi",
	"http://www.focusflow.fi",
	"http://www.google.fi",
	"http://www.recommended.fi",
	"http://www.focusflow.fi",
	"http://www.recommended.fi"
);

$(document).ready(function(){
	showPagination();
});

function selectPage(i) {
	curItem = i;

	$("#slide img").attr("src", slides[i-1]);
	$("#slide").attr("href", urls[i-1]);
	$("#numbers a").removeClass("active");
	$("#numbers .page"+i).addClass("active");
	
	clearTimeout(timer);
	timer = setTimeout("nextPage()", 10000);
}

function showPagination() {
	$("#numbers").html("");
	for(var i = 1; i <= maxItem; i++) {
		preloadImg(slides[i-1]);
		$("#numbers").append('<a href="#" class="page'+i+'" onclick="selectPage('+i+'); return false;">'+i+'</a>');
	}
	selectPage(1);
	$("#numbers").fadeIn("normal");
}

function preloadImg(path) {
	pic = new Image(700, 321); 
	pic.src = path; 
}

function nextPage() {
	if(curItem < maxItem) {
		curItem++;
		selectPage(curItem);
	} else {
		selectPage(1);
	}
}

function prevPage() {
	if(curItem > 1) {
		curItem--;
		selectPage(curItem);
	}
}
