
var count = 0;
if (count == 4) { count = 0; }
var ad1;
var ad2;
var ad3;

var gallery = new Array();
gallery[0] = new Array();//"link-1.jpg","link-2.jpg","link-3.jpg");
gallery[1] = new Array();//"link-1.jpg","link-2.jpg","link-3.jpg");
gallery[2] = new Array();//"link-1.jpg","link-2.jpg","link-3.jpg");
gallery[3] = new Array();

/**
	Within the following set of arrays, place the urls of the images in corresponding
	positions.?  
	
	*Note:?  if there's a certain prefix/path that you'd like to include (which all 
	the links share), just prepend that to the href attribute of the anchor tag below,
	using JS's concantenation operator (+);
*/

var href = new Array();
href[0] = new Array();//"http://www.georgialinatix.com","http://www.feedyourbeak.com","http://www.windsorfinejewelers.com");
href[1] = new Array();//"http://www.georgialinatix.com","http://www.feedyourbeak.com","http://www.windsorfinejewelers.com");
href[2] = new Array();//"http://www.georgialinatix.com","http://www.feedyourbeak.com","http://www.windsorfinejewelers.com");
href[3] = new Array();

$(function() {
	$.get(
		"include/ads.xml",
		function(xml) {
			//alert("hello");
			var i = 0;
			$(xml).find('ad').each(function() {
				var title = $(this).find('title').text();
				var url = $(this).find('url').text();
				var img = $(this).find('img').text();
				
				gallery[0][i] = img;
				gallery[1][i] = img;
				gallery[2][i] = img;
				gallery[3][i] = img;
				href[0][i] = url;	
				href[1][i] = url;
				href[2][i] = url;	
				href[3][i] = url;
				
				i++;	
				
			});
			
			pickImageFrom(0);
			pickImageFrom(1);
			pickImageFrom(2);
			pickImageFrom(3);
			//alert(gallery.length+"\n"+href.length);
		}, 
		"xml"
	);
});


function pickImageFrom(whichGallery){	
	var idx = Math.floor(Math.random() * gallery[whichGallery].length);
	
	// use following block as long as each add shares same array structure.
	
	if(count == 0) {
		ad1 = idx;
		count++;
		
		$("#img0").html(
			"<a href=\"" + href[whichGallery][idx] + "\" target=\"new\">"+
			"<img src=\"" + gallery[whichGallery][idx] + "\" class=\"adImgs\" />"+
			"</a>"
		);
		return;
	} 
	
	if (count == 1) {
		if (idx == ad1) {
			pickImageFrom(whichGallery);			
		} else {
			ad2 = idx;
			count++;
			
			$("#img1").html(
				"<a href=\"" + href[whichGallery][idx] + "\" target=\"new\">"+
				"<img src=\"" + gallery[whichGallery][idx] + "\" class=\"adImgs\" />"+
				"</a>"
			);
		}
		return;
	} 
	
	if (count == 2) {
		if ((idx == ad1) || (idx == ad2)) {
			pickImageFrom(whichGallery);			
		} else {
			ad3 = idx;
			count++;
			
			$("#img2").html(
				"<a href=\"" + href[whichGallery][idx] + "\" target=\"new\">"+
				"<img src=\"" + gallery[whichGallery][idx] + "\" class=\"adImgs\" />"+
				"</a>"
			);
		}
		return;
	}
	
	if (count == 3) {
		if ((idx == ad1) || (idx == ad2) || (idx == ad3)) {
			pickImageFrom(whichGallery);			
		} else {
			ad4 = idx;
			count++;
			
			$("#img3").html(
				"<a href=\"" + href[whichGallery][idx] + "\" target=\"new\">"+
				"<img src=\"" + gallery[whichGallery][idx] + "\" class=\"adImgs\" />"+
				"</a>"
			);
		}
		return;
	}
	
}


