var timer;
var pause = 8000;
var fade = 1000;

var images = new Array();
var links = new Array();
var targets = new Array();

var eid;
var xpos;
var ypos;
var w;
var h;
var hasOverlay;
var hasLinks;
var hasButtons;

function initSlide(_eid, _x, _y, _w, _h, _hasLinks) {
	eid = _eid;
	xpos = _x;
	ypos = _y;
	w = _w;
	h = _h;
	hasLinks = typeof(_hasLinks) != 'undefined' ? _hasLinks : false;
	
	$.ajax({
		type: 'GET',
		url: '/images/Image/user/Redesign/events.xml', 
		dataType: 'xml',
		success: xmlLoaded
	});	
}

function xmlLoaded(xml) {
	$(xml).find('event').each(function() {
		images.push($(this).attr('image'));
		links.push($(this).attr('link'));
		targets.push($(this).attr('target'));
	});
	
	setupSlide();
}

function setupSlide() {
	for (i=0; i<images.length; i++) {
		var imageHTML = '';
		if (hasLinks) {
			imageHTML += '<a href="' + links[i] + '" target="' + targets[i] + '">';	
		}
		imageHTML += '<img class="inactive slide" src="/images/Image/user/Redesign/' + images[i] + '" border="0" alt="" />';
		if (hasLinks) {
			imageHTML += '</a>';	
		}
		
		$('#images', eid).append(imageHTML);
	}
	
	$('img.slide', eid).css('left', $(eid).css('width'));
	
	$('img.slide:first', eid).attr('class', 'active slide').animate({'left':'-26px'}, fade);
	timer=setTimeout('scanLeft()', pause);
}

function scanRight() {
	clearInterval(timer);
	var next_index = $('a', eid).index($('a:has(img.active)'))-1;
	var numSlides = $('img.slide', eid).length;
	
	if (next_index == -1) {
		next_index = numSlides-1;
	}
	
	$('img.active', eid).attr('class', 'inactive slide').stop().animate({'left':$(eid).css('width')}, fade);
	$('img.slide:eq('+next_index+')', eid).attr('class', 'active slide').css('left','-' + $(eid).css('width')).animate({'left':'-26px'}, fade);
	
	timer=setTimeout('scanLeft()', pause);
}

function scanLeft() {
	clearInterval(timer);
	var next_index = $('a', eid).index($('a:has(img.active)'))+1;
	var numSlides = $('img.slide', eid).length;
	
	if (next_index == numSlides) {
		next_index = 0;
	}
	
	$('img.active', eid).attr('class', 'inactive slide').stop().animate({'left':'-' + $(eid).css('width')}, fade);
	$('img.slide:eq('+next_index+')', eid).attr('class', 'active slide').css('left',$(eid).css('width')).animate({'left':'-26px'}, fade);
	
	timer=setTimeout('scanLeft()', pause);
}
