
/* developer: team@richmediamanila.com */

var image = new Array();
var title = new Array();
var text = new Array();
var link = new Array();
var url = new Array();

var autoplay;
var seconds;
var count;
var prev;
var now;
var next;
var interval;

if (count==undefined) count = 0;
if (prev==undefined) prev = 1;
if (now==undefined) now = 1;
if (next==undefined) next = 2;

function autoSlide() {
	
	now++;
	if (now == (count+1)) now = 1;
	showImage(now-1);
	
}

function pauseSlideShow() {
	
	if (autoplay) {
		clearInterval(interval);
	}
	
}

function resumeSlideShow() {
	
	if (autoplay) {
		interval = setInterval(autoSlide, seconds*3000);
	}
	
}

function init() {
	
	setup();
	count = image.length;

	replaceSlide(now-1);
	replaceImage(now-1);
	createMenu();
	
	if (autoplay) {
		interval = setInterval(autoSlide, seconds*3000);
	}
	
}

function replaceSlide(num) {
	$('#slide_title').replaceWith('<div id="slide_title">' + title[num] + '</div>');
	$('#slide_text').replaceWith('<div id="slide_text">' + text[num] + '</div>');
	$('#slide_link').replaceWith('<a id="slide_link" href="' + url[num] + '">' + link[num] + '</a>');
}

function replaceImage(num) {
	
	$('#slide_image').replaceWith('<img id="slide_image" src="' + image[num] + '" alt="' + title[num] + '" width="946" height="433" />');

}

function click(num) {
	
	clearInterval(interval);
	showImage(num);
	
}


function showImage(num) {

	if (num < (count-1)) {
		next = num + 1;
	} else {
		next = count;
	}
	$('#slide_container').css('background-image','url("' + image[next-1] + '")');

	now = num + 1;
	createMenu();

	$('#slide_image').fadeOut('slow', function() {
		replaceImage(next-1);
	});
	
	replaceSlide(num);

}

function createMenu() {

	var anchor = '';
	var x = count - 1;
	
	for (i=0; i<=x; i++) {
		if ((i+1) == now) {
			anchor += '<div class="current">' + (i+1) + '</div>';
		} else {
			anchor += '<a href="javascript:showImage(' + (i) + ');">' + (i+1) + '</a>';
		}
	}
	
	$('#slide_menu').replaceWith('<div id="slide_menu">' + anchor + '</div>');
	
}

