var count;
var previous;
var next;

var articleID;

function onclickFunction() {
   startMagazineArticleSlideshow();
}

function startMagazineArticleSlideshow() {
	document.getElementById("prev_button").style.visibility = 'visible';
	document.getElementById("next_button").style.visibility = 'visible';

   articleID = document.getElementById("hdArticleID").value;
   count = 0;
   magazineArticleSlideshow();
   setInterval("magazineArticleSlideshow()", 12000);
}

function onclickNext() {
    //previous = false;
    next = true;
    magazineArticleSlideshow();
}

function onclickPrevious() {
    //next = false;
    previous = true;
    magazineArticleSlideshow();
}

function magazineArticleSlideshow() {

   if (next == true) {
        count = count + 1;
        next = false;
    }
    else if (previous == true) {
        if(count > 0)
            count = count - 1;
        previous = false;
    }
    else {
        count = count + 1;
    }

   $.ajax({
       type: "GET",
     
       url: "/xml/copyslideshowxml.php?id=" + articleID,
       dataType: "xml",
       success: function(xml) {
		document.getElementById("title-image").style.visibility = 'hidden';
		document.getElementById("mainImageCaption").style.visibility = 'hidden';
  
           	var banners = $(xml).find('slideshowItems');
           		if (count > banners.length) {
               		count = 1;
           		}

           		$(xml).find('slideshowItems').each(function() {
              	var id = $(this).find('id').text();
                	var img = $(this).find('img').text();
			var desc = $(this).find('desc').text();
                
                if (count == id) {
                    $('#magazine-article-slideshow').fadeOut(500, function() {
                        	$('#magazine-article-slideshow').css("background-image", "url(" + img + ")");
				
				if(desc != ''){
					$('#magazine-article-slideshow').attr("title", desc);
	                     	document.getElementById("img-caption").innerHTML = desc;
				}
                    });
                    
                    $('#magazine-article-slideshow').fadeIn(500);
                }           	
});
       }
   });
}


