//W20 Banner JS NON-OBSTRUSIVE Implementation using jQuery library


//Define no conflict to maximize compatibility with other libraries/languages
jQuery().noConflict;
//Check if variables exists and if not gives the default value of swf in loop, big size
if (typeof(size)=='undefined'){
		var size='medium';
	}
if (typeof(url)=='undefined'){
	var url='loop';
}
//banner url
//On Load executes function loadbanner
jQuery(document).ready(function(){
//checks if swf is suposed to be random	
	
	loadBanner(true)
	
});
//This function creates a Div with position absolute and zindex after Body element
//Another div is created inside the first one. This div is where the swf object will be loaded
function loadBanner(rand){
	
	jQuery('body').prepend("<div id='BannerId'></div>")
	//css centers the swf in browser window and prepends it after body tag. Css is dependable of size
	if (size=='big'){
	jQuery('#BannerId').css({position:'absolute',zIndex:'9999',left:'50%',top:'0',marginLeft:'-400px'}).prepend("<div id='loadBannerSWF'></div>")
	jQuery('#BannerId').prepend("<span id='closebuttonbanner'><img src='http://www.banners2site.com/images/close.png' /></span>")
	jQuery('#closebuttonbanner').css({position:'absolute',width:'30px',height:'30px',zIndex:'9999',left:'90%',top:'40px',cursor:'pointer',color:'#CCCCCC'})
	
	}else{
	jQuery('#BannerId').css({position:'absolute',zIndex:'9999',left:'80%',top:'10',marginLeft:'-322px'}).prepend("<div id='loadBannerSWF'></div>")
	jQuery('#BannerId').prepend("<span id='closebuttonbanner'><img src='http://www.banners2site.com/images/close.png' /></span>")
	jQuery('#closebuttonbanner').css({position:'absolute',width:'30px',height:'30px',zIndex:'9999',left:'91%',top:'10px',cursor:'pointer',color:'#CCCCCC'})
	
	}
	//Make Close bottom hide the SWF
	jQuery('#closebuttonbanner').bind('click',function(){
	jQuery('#BannerId').toggle('slow');
	
	 });
	
	
	loadSWF(true)
	
}
//Using SwfObject js we load the banner inside the div created. Wmode transparent is really important to put the swf above the other elements. If not working in IE, put the other swfs in the page with wmode=opaque
function loadSWF(rand){
	var params = {
		wmode : "transparent",
		quality : "high",
		allowscriptaccess : "always"
	}
	var flashvars = {
		rid : rid //Passado por parametro no HTML
	}
	
	url='http://www.banners2site.com/ResellerFiles/banners.swf';
	swfobject.embedSWF(url, "loadBannerSWF", "403", "292", "7.0.0", "",flashvars, params);
}
	
//For support contact diogo.silva@w20.pt