/*********************************
========= Script Notice ==========
**********************************
Script Title: Random Banner Rotation Script
	* Feature:
		- Supports image element (image)
		- Supports flash element (flash)
		- Configurable Banner info
		- Script automatically detects if flash is being passed.
	* Modifications:
		- June 23, 2009
			> Object Oriented
			> Will use only one script and configuration is easily configured
			> Supports scripts, flash and images (Script is witty to distinguish one from the other)
		- June 12, 2009
			> Added Cookie detection for banner showing in sequence
		- June 5, 2009
			> Fix the bottom border bug issue for caption
			> Fix the broken link issue
			
Copyright: http://www.financial-spread-betting.com
Script Created by Raymond Angana (http://www.raymondangana.com)
Date Created: June 5, 2009

This notice must stay intact for legal use
***********************************
========= End of Notice ===========
**********************************/

////////// Edit at your own risk ////////
var ray = {
	loadRandomBannerScript : function ( obj ) { // loadRandomBannerScript
		
		var e = Number(this.checkCookie([obj.banners,obj.bannerName])); // Set/Check cookie for banner
		
		var getBanner = obj.banners[e]; // Get the banner configuration
		
		// Check at this early point if it's a script
		if (getBanner[1].toLowerCase() == 'script') {
			document.write ('<script type="text/javascript" src="'+getBanner[0]+'"><\/script>');
			
			document.write ('<p style="border:0px;margin-top:10px;text-align:center;clear:both;"><font size="1" face="Verdana"><b><a href="'+getBanner[3]+'" target="_blank">'+getBanner[2]+'</b></a></font></p>');
			return;
		}
		// End of check
		
		var getExt = getBanner[1].substr(getBanner[1].length-3,getBanner[1].length); // Gets the file extension
		
		var str = '<a href="'+getBanner[0]+'" target="_blank" class="text hover" id="mylink" onmouseover="this.style.textDecoration=\'none\'">';	
		var iHTML = (getExt.toLowerCase() == 'swf')?'<object type="application/x-shockwave-flash" width="728px" height="90px" data="'+((obj.bannerFolder)+getBanner[1])+'"><param name="movie" value="'+((obj.bannerFolder)+getBanner[1])+'"><param name="quality" value="high"><h1>You don\'t have "'+getBanner[1]+'" flash file on your machine</h1></object>':(str+'<img id="myimg" onmouseover="this.style.textDecoration=\'none\'" src="'+((obj.bannerFolder)+getBanner[1])+'" style="border:0px;width:728px;height:90px;" alt="'+getBanner[2]+'"></a>'); // Construct the HTML code
		
		// Create a caption if one is defined
		iHTML += (getBanner[3])?
			'<p style="border:0px;margin-top:10px;text-align:center;"><font size="1" face="Verdana"><b><a href="'+(getBanner[4]?getBanner[4]:getBanner[0])+'" target="_blank">'+getBanner[3]+'</b></a></font></p>':'';

		document.write(iHTML); // Write it now
	},
	
	checkCookie : function ( banners ) { // Checks if cookie exists
		
		var cookieName = (banners[1])?banners[1]:'banner';
		var banner=this.getCookie(cookieName); // Gets the cookie with name: banner
		if (banner >= (banners[0].length) - 1) // If the cookie is greater than or equal to the configured banner
			this.setCookie(cookieName,0,365); // Reset the cookie
		else if (banner[0]!=null && banner[0]!="") // If cookie exists already
		  this.setCookie(cookieName,Number(banner[0])+1,365); // Increment the cookie
		else // If for some circumstance
			this.setCookie(cookieName,0,365); // Just reset the cooie
		
		return this.getCookie(cookieName); // Return the cookie
	},
	
	setCookie : function (c_name,value,expiredays) { // Sets cookie's value
		var exdate=new Date(); // Get the current date
		exdate.setDate(exdate.getDate()+expiredays); // Set cookie's expiration date
		document.cookie=c_name+ "=" +escape(value)+ 
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString()); // Set cookie
	},
	
	getCookie : function (c_name) { // Gets cookie's value
		if (document.cookie.length>0) { // If a cookie exists
			c_start=document.cookie.indexOf(c_name + "="); // Check if the cookie exists
			if (c_start!=-1) { // If there's a match above
				c_start=c_start + c_name.length+1; // Set the start of cookie
				c_end=document.cookie.indexOf(";",c_start); // Set the end of cookie
				if (c_end==-1) // If doesn't exists
					c_end=document.cookie.length; // Just set it to cookie's length
			return unescape(document.cookie.substring(c_start,c_end)); // Set cookie
			}
		}
		return "";
	},
	
	// Custom function: Same as document.getElementById(element);
	getID : function (el) { return document.getElementById(el); }
}