function slideShow(el, href){
	$.get(href, function(msg){ //get list of urls
		msg = msg.split("http://") //split them by the http tag
		var preload = [] //create array of images
		for(i=0;i<msg.length-1;i++){ //cycle through urls
			if("http://" + msg[i+1] == $(el).attr('src')){ //if url is same as initial image
				preload[i] = new Image(); //create new image
				preload[i].src = preload[0].src; //copy array[0].src to current position src
			 	preload[0].src = "http://" + msg[i+1]; //insert url of initial image into position zero
			} else {
				 preload[i] = new Image(); //create new image
				 preload[i].src = "http://" + msg[i+1]; //add src
			}
		}
		i = 0;
		slideShowTimer = window.setInterval(function(){	
			if(i==preload.length-1){ //if at end of cycle start again from beginning - uncomment clear interval if it should stop
				i = 0;
				//clearInterval(slideShowTimer); 
			}
			
			$(el).fadeOut("slow", function(){ //fade/swap images
				$(el).attr('src', preload[i].src).fadeIn();
			})
			i++;
		},4000); // time delay in milliseconds     
	})
};

function hidePrevNextLinks () {
	$(".homepage-box-link").each(function() {
		$(this).hide();
		if ($(this).find("a").length > 0) {
			$(this).show();
		}
	});
};

function showRandomArticleHomepage() {
	var $divs = $("#homepage-article-outer > div"); 
	var rndNum = Math.floor(Math.random() * $divs.length);
	
	$featured = $("#homepage-article-outer > div").get(rndNum);
	$($featured).show();
};		

$(document).ready(function(){
	$("#nav-pri ul.nav-pri").superfish();
  hidePrevNextLinks ();
  showRandomArticleHomepage();
  slideShow('#slideShow', 'http://www.selwyn.govt.nz/home-assets/asset-listings/rotating-image-list');
});

