document.domain = "kamofie.com"; 
var backgroundImage =1;
var currentImage = 0;
var viewTime = 15;
var slideShowObjects = new Array();
$(document).ready(function () { 
	$.ajax({
		type: "POST",
		url: "/slideShow/xml.php",
		dataType: "xml",
		success: parseXML,
		complete: function(XMLHttpRequest, textStatus) {                
			//alert(textStatus);    
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {        
			alert(errorThrown);     
		} 
	});
}); 

function parseXML(xml){
	$(xml).find("item").each(function(){
		var myObject = new Object();
  		myObject.itemTitle = $(this).find("itemTitle").text();
		myObject.image = "/slideShow/images/" + $(this).find("image").text();
		myObject.itemLink = $(this).find("itemLink").text();
		slideShowObjects.push(myObject);
	});
	$('#bottomRightContent').prepend('<img id="bottomRightImg" src="' + slideShowObjects[currentImage].image +'" title ="' + slideShowObjects[currentImage].itemTitle + '" />');
	$("#bottomRightContent").click(function () {  
    	window.location.href =  slideShowObjects[0].itemLink;
    }); 
	$("#bottomRightContent").click(function () {  
    	window.location.href =  slideShowObjects[currentImage].itemLink;
   	}); 
	$("#bottomRightContent").css('background-image', 'url('+ slideShowObjects[backgroundImage].image + ')'); 
	setTimeout('swapImage()', viewTime * 1000);
}
function swapImage(){
	currentImage < slideShowObjects.length-1 ? currentImage++ : currentImage = 0
	backgroundImage < slideShowObjects.length-1 ? backgroundImage++ : backgroundImage = 0
	
	$("#bottomRightImg").fadeOut('slow', function(){
		$("#bottomRightImg").attr('src',slideShowObjects[currentImage].image);
		$("#bottomRightImg").attr('title',slideShowObjects[currentImage].itemTitle);
		$("#bottomRightImg").show();
		$("#bottomRightContent").css('background-image', 'url(' + slideShowObjects[backgroundImage].image + ')');
		setTimeout('swapImage()', viewTime * 1000);
	});
}
