/**
 * @desc		Create banner html code and detect flash
 * @author	Robert Fokken
 * @since		Banner systeem 1.0
 * @version	1.0
 * @package Advertisement
 * @history 20-2-2009 12:28 RF Initially build
 *
 * @todo 	Random banners in holder
 * 
 */ 
var Banner = new Class({
	Implements: [Options],
	
	options: {		
		iHeight : 100,
		iWidth : 142,
		iLanguageID : 0,
		sAlt : 'No alt text available',
		sBannerDestinationURL : '/phplib/advertisement/banner_redirect.php'				
	},
	
	initialize: function(element, options, taBanners)
	{
		this.setOptions(options);
		
		this.oBannerContainer = element;		
		var aSplittedID = this.oBannerContainer.get("id").split("_");						
		this.iBannerID = aSplittedID[1].toInt();		
		this.oBanner   = taBanners.get(this.iBannerID);
		
		this.options.iWidth = this.oBanner.iWidth;
		this.options.iHeight = this.oBanner.iHeight;
		this.options.sTarget = this.oBanner.sTarget;
		this.options.sAlt = this.oBanner.sImageAlt;
		this.options.iLanguageID = this.oBanner.iLanguageID;
		this.options.sBannerDestinationURL += '?iBannerID='+this.iBannerID+'&iLanguageID='+this.oBanner.iLanguageID+'&iNodeID='+ this.oBanner.iNodeID + '&iAffiliateID=' + this.oBanner.iAffiliateID + '&iRegionID=' + this.oBanner.iRegionID + '&iPositionID=' + this.oBanner.iPositionID + '&iCampingID=' + this.oBanner.iCampingID;
		
		// Hack for premium plaatsen
		if (this.oBanner.iCampingID > 0)
		{			
			this.sURL = '/imagelib/premium_plaatsen/' + this.oBanner.iCampingID + '.jpg';			
			this.makePremiumBanner();
		}
		else
		{
			this.sURL = '/phplib/advertisement/banner_image.php?iBannerID='+this.iBannerID+'&iLanguageID='+this.oBanner.iLanguageID;
			bFlashEnabled = (Browser.Plugins.Flash.version > 0);
			if (bFlashEnabled && this.oBanner.bFlashAvailable)
			{
				this.makeFlashBanner();
			}
			else
			{
				this.makeImageBanner();
			}
		}
	},
	
	makeFlashBanner : function()
	{		
		// Inject flash element in div element
		sHTMLData  = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	 	sHTMLData += '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" ';
	 	sHTMLData += '	WIDTH=' + this.options.iWidth + ' HEIGHT=' + this.options.iHeight + '>';
	 	sHTMLData += ' <PARAM NAME=movie VALUE="' + this.sURL + '&sType=flash"> <PARAM NAME=quality VALUE=high> <PARAM NAME="bgcolor" VALUE="#000000">  '; 
	 	sHTMLData += ' <EMBED src="' + this.sURL + '&sType=flash" quality=high bgcolor="#000000"  ';
	 	sHTMLData += ' swLiveConnect=FALSE WIDTH=' + this.options.iWidth + ' HEIGHT=' + this.options.iHeight;
	 	sHTMLData += ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
	 	sHTMLData += ' </EMBED></OBJECT>';
	 	
	 	this.oBannerContainer.set('html', sHTMLData);	 	
	},
	
	makeImageBanner : function()
	{		
		oLink  =  new Element('a',
			{			
				'href' : this.options.sBannerDestinationURL,
				'target' : this.options.sTarget,
				'title' : this.options.sAlt,
				'style' : 'width: '+this.options.iWidth+'px; height: '+this.options.iHeight+'px; '
			}
		);
		
		oLink.injectInside(this.oBannerContainer);
		
		oImage = new Element('img',
			{
				'style' : 'width: '+this.options.iWidth+'px; height: '+this.options.iHeight+'px; border: 0px; ',
				'alt' : this.options.sAlt,
				'src' : this.sURL + '&sType=img'
			}
		);
		
		oImage.injectInside(oLink);
	},
	
	makePremiumBanner : function()
	{	
		var aTrans = new Translation("29258", {'iLanguageID' : this.oBanner.iLanguageID} ).getTranslations();
		
		sPremiumBanner =  '<div id="banner-'+this.iBannerID+'" class="banner-premium">';
		sPremiumBanner += ' <div class="banner-premium-image">';
		sPremiumBanner += '  <a href="'+this.options.sBannerDestinationURL+'&iInternalLink=1" rel="nofollow" title="'+this.oBanner.sCampingName+'"><img src="'+this.sURL+'" style="width: 192px; border:0;" alt="'+this.oBanner.sCampingName+'" /></a>';
		sPremiumBanner += '  <div class="banner-premium-campingname"><a href="'+this.options.sBannerDestinationURL+'&iInternalLink=1" title="'+this.oBanner.sCampingName+'">'+this.oBanner.sCampingName+'</a></div>';
		sPremiumBanner += ' </div>';
		sPremiumBanner += ' <a href=" '+this.options.sBannerDestinationURL + '" rel="nofollow" class="banner-premium-link" title="'+this.oBanner.sCampingName+'" target="_blank">'+aTrans[29258]+'</a>';
		sPremiumBanner += '</div>';
		
		this.oBannerContainer.set('html', sPremiumBanner);	
	}
	
});