// Logo Slider Javascript
var slidespeed=1500; // duration of each slide animation in ms
var autodelay=5000; // interval between automatic slides in ms
var ease_in="easeInOutQuad";
var ease_out="easeInOutQuad";
// -----------------------------------------------------------
var autointerval;
var autoactive=false;
var texts=[];
var subtexts=[];
var currlogo=0;
var numlogos=0;
$(document).ready(function() {
	$.ajax({
		type: "GET",
		url: "logo-slider/slides.xml",
		dataType: "xml",
		success: function(xml) {
			var counter=0;
			var html='<ul>';
			$(xml).find('slide').each(function() {
				var image = $(this).find('image').text();
				var text = $(this).find('text').text();
				html+='<li id="slider-logo-' + counter + '"';
				if (counter>0) {
					html+=' style="display: none;"';	
				}
				html+='><a href="necklaces.php" title="Necklaces"><img src="logo-slider/slides/' + image + '" alt="' + text + '" border="0" /></a></li>';
				texts[counter]=text;
				counter++;
			});
			html+='</ul>';
			$("#slide").html(html);
			numlogos=counter;
			startAutoInterval();
		}
	});
	$("#caption").css("display","block");	
});
//$("#arrow-right").live('click', function() {
//	stopAutoInterval();
//	slideRight();
//	startAutoInterval();
//});
//$("#arrow-left").live('click', function() {
//	stopAutoInterval();
//	slideLeft();
//	startAutoInterval();
//});
function slideRight() {
	if (!$("#slider-logo-"+currlogo).is(':animated') && !$("#slider-logo-"+currlogo+1).is(':animated') && !$("#slider-logo-0").is(':animated') ) {
		$("#logotext").html('&nbsp;');
		$("#logosubtext").html('&nbsp;');
		$("#slider-logo-"+currlogo).animate({left: '-=864'}, slidespeed, ease_out, function() { 
				$(this).css("display","none");
				$(this).css("left",0);
		});	
		currlogo++;
		if (currlogo>=numlogos) {
			currlogo=0;	
		}					
		$("#slider-logo-"+currlogo).css("left", 864);
		$("#slider-logo-"+currlogo).css("display", "block");		
		$("#slider-logo-"+currlogo).animate({left: '-=864' }, slidespeed, ease_in, function() { 
				$(this).css("display","block");
				$(this).css("left",0);
				$("#logotext").html(texts[currlogo]);
				$("#logosubtext").html(subtexts[currlogo]);
		});		
	}
}
function slideLeft() {
	if (!$("#slider-logo-"+currlogo).is(':animated') && !$("#slider-logo-"+currlogo-1).is(':animated') && !$("#slider-logo-"+numlogos-1).is(':animated') ) {								
		$("#logotext").html('&nbsp;');	
		$("#logosubtext").html('&nbsp;');		
		$("#slider-logo-"+currlogo).animate({left: '+=864'}, slidespeed, ease_out, function() { 
				$(this).css("display","none");
				$(this).css("left",0);
		});
		currlogo--;
		if (currlogo<0) {
			currlogo=numlogos-1;	
		}
		$("#slider-logo-"+currlogo).css("left",-864);
		$("#slider-logo-"+currlogo).css("display", "block");	
		$("#slider-logo-"+currlogo).animate({left: '+=864'}, slidespeed, ease_in, function() { 
				$(this).css("display","block");
				$(this).css("left",0);
				$("#logotext").html(texts[currlogo]);
				$("#logosubtext").html(subtexts[currlogo]);				
		});	
	}
}
function startAutoInterval() {
	autointerval=setInterval("slideRight()", autodelay);
	autoactive=true;
}
function stopAutoInterval() {
	clearInterval(autointerval);	
	autoactive=false;
}
