/*********************************
========= 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 5, 2009
			> Fix the bottom border bug issue for caption
			> Fix the broken link issue
		- June 12, 2009
			> Added Cookie detection for banner showing in sequence
Script Author: Raymond Angana (http://raymondangana.com)
Date Created: June 5, 2009

This notice must stay intact for legal use
***********************************
========= End of Notice ===========
**********************************/


// Edit this line
var bannerFolder = 'banner/'; // Name of the folder to where the banners resides
var bannerAreaID = 'banner_area'; // ID of the element that will hold the banner
var captionAreaID = 'caption_area'; // ID of the element that will hold the captions

var bannerConfig = [ 
	// Accepts 4 parameters
	// [Image's Link, location of the image prior to the "bannerFolder" defined above, alternating text, caption, caption's link ]
	
	['http://www.financial-spread-betting.com/ccount/click.php?id=31','107_728x90_FSB.gif','GFT Image','',''],
	['http://www.financial-spread-betting.com/ccount/click.php?id=27','32_728x90_FSB.gif','GFT image','',''],
]; // Configuration
// End of edit



/** Do not edit this line. Edit at your own risk. **/
window.addEventListener?window.addEventListener('load',function() {
	ray.loadRandomBanner
	Script();
	},false):
window.attachEvent('onload',function () {
	ray.loadRandomBannerScript();
	}); // FF : IE
	
var ray ={
	banners : this.bannerConfig, // Copy the array defined above
	
	loadRandomBannerScript : function () { 
		var e = Number(this.checkCookie());
		var getBanner = this.banners[e]; // Get the banner configuration
		var getExt = getBanner[1].substr(getBanner[1].length-3,getBanner[1].length); // Gets the file extension
		var iHTML = '<a href="'+getBanner[0]+'" target="_blank" class="text" id="mylink" onmouseover="this.style.textDecoration=\'none\'">';	
		iHTML += (getExt.toLowerCase() == 'swf')?'<object type="application/x-shockwave-flash" width="728px" height="90px" data="'+(bannerFolder+getBanner[1])+'" onclick="return false;"><param name="movie" value="'+(bannerFolder+getBanner[1])+'"><param name="quality" value="high"><h1>You don\'t have "'+getBanner[1]+'" flash file on your machine</h1></object>':'<img id="myimg" onmouseover="this.style.textDecoration=\'none\'" src="'+(bannerFolder+getBanner[1])+'" style="border:0px;width:728px;height:90px;" alt="'+getBanner[2]+'">'; // Construct the HTML code		
		iHTML += '</a>';
		
		this.getID(bannerAreaID).innerHTML = iHTML; // Paste into the DOM
		this.getID(captionAreaID).innerHTML = (getBanner[3] != '' || typeof getBanner[3]!='undefined')?
			'<p style="font-family:Verdana;font-size:8pt;font-weight:bold;background:none;border:0px;margin-top:-2px;"><a href="'+(getBanner[4]?getBanner[4]:getBanner[0])+'" target="_blank" class="text">'+getBanner[3]+'</a></p>':''; // Create a caption if one is defined
	},
	
	checkCookie : function () {
		var banner=this.getCookie('banner');
		if (banner >= bannerConfig.length - 1)
			this.setCookie('banner',0,365);
		else if (banner!=null && banner!="")
		  this.setCookie('banner',Number(banner)+1,365);
		else
			this.setCookie('banner',0,365);
		
		return this.getCookie('banner');
	},
	
	setCookie : function (c_name,value,expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	},
	
	getCookie : function (c_name) {
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) {
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1)
					c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
			}
		}
		return "";
	},
		
	getID : function (el) { return document.getElementById(el); }
}
