/***********************************************************
	Argument List
	'type': type of banner to use (fadeslideshow, randombanner)
	'wrapperid': id of blank div to house banner
	'defaultimages': array of default images
	'forcedefault': override possible dynamic images with default images
	
	--------- FadeSlideShow Items ---------
	'width': width of gallery in pixels. Should reflect dimensions of largest image
	'height': height of gallery in pixels. Should reflect dimensions of largest image
	'pause': how long to show each image (milliseconds)
***********************************************************/

// setup banner item
function DNABanner(args)
{
	forceDefault = false;
	try { if(args.forcedefault) { forceDefault = args.forcedefault; } } catch(ex) { }
	
	// set up the image list
	if(typeof(imageList) == "undefined"
		|| imageList == null
		|| forceDefault)
	{
		imageList = new Array();
		try
		{
			for(count = 0; count < args.defaultimages.length; count++)
			{
				imageList.push(args.defaultimages[count]);
			}
		}
		catch(ex) { }
	}
	
	type = "";
	try { type = args.type; } catch(ex) { }
	
	wrapperId = "";
	try { wrapperId = args.wrapperid; } catch(ex) { }
	
	if(type == "fadeslideshow")
	{
		width = 500;
		try { width = args.width; } catch(ex) { }
		height = 500;
		try { height = args.height; } catch(ex) { }
		imagePause = 5000;
		try { imagePause = args.pause; } catch(ex) { }

		// set fadeslideshow specific formatting
		var images = new Array();
		for(count = 0; count < imageList.length; count++) { images.push([imageList[count]]); }
		
		mygallery = new fadeSlideShow({
			wrapperid: wrapperId,
			dimensions: [width, height],
			imagearray: images,
			displaymode: {type:'auto', pause:imagePause, cycles:0, wraparound:false, randomize:true},
			persist: false,
			fadeduration: 1000,
			descreveal: "ondemand",
			togglerid: ""
		})		
	}
	else if(type == "randombanner")
	{
		try
		{
			jQuery("#" + wrapperId).ready(function() { changeBgImage(wrapperId); });
		}
		catch(ex) { }
	}
}

function randomBanner()
{
	imagePath = "";
	try
	{
		var imgCount = imageList.length;
		var rnd_no = Math.floor(imgCount * Math.random());
		imagePath = imageList[rnd_no];
	}
	catch(ex) { }
	
	return imagePath;
}

function changeBgImage(containerId)
{
	var newBanner = "url('" + randomBanner() + "')";
	document.getElementById(containerId).style.backgroundImage = newBanner;
}

