// --------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------
// --- JS for advertising banner with flash overlay ---
// --------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------

var bannerManager = {
	current_banner: null,
	
	initialise: function() {
		var ad_banners = $$('.featureAdvert');
		
		for (var i=0, maxi = ad_banners.length; i<maxi; i++) 
			this.initialiseBanner(ad_banners[i]);
	},
	initialiseBanner: function(banner_el) {
		banner_el.swf = this.getClassValue(banner_el, 'swf');
		if (!banner_el.swf) return;
		banner_el.a = banner_el.getElementsByTagName('A')[0];
		if (!banner_el.a) return;
		
		this.createOverlayLayer(banner_el);
		
		banner_el.showBanner = function() {
			if (this.timeout) clearTimeout(this.timeout);
			this.timeout = null;
			if (this.showing) return;
			
			this.overlay_div.style.top = this.getTop() + this.getSize().size.y + 'px';
			this.overlay_div.style.left = this.getLeft() + 'px';			
			this.overlay_div.style.display = 'block';
			// write flash;
			var so = new SWFObject(this.swf, '', "710", "450", "8", "#ffffff");
			so.addParam("allowScriptAccess", "sameDomain");
			so.addParam("wmode", "transparent");
			so.write(this.overlay_div);
						
			this.showing = true;
			};
		banner_el.hideBanner = function() {
			if (this.timeout) clearTimeout(this.timeout);
			this.timeout = null;
			this.overlay_div.style.display = 'none';
			this.showing = false;
			};
		banner_el.setToHide = function() {
			bannerManager.current_banner = this;
			this.timeout = setTimeout('bannerManager.hideCurrentBanner()', 200);
			};
		banner_el.a.onmouseover = function() {this.parentNode.showBanner();};
		banner_el.a.onmouseout = function() {this.parentNode.setToHide();};
		banner_el.overlay_div.onmouseover = function() {this.parentNode.showBanner();};
		banner_el.overlay_div.onmouseout = function() {this.parentNode.setToHide();};
	},
    getClassValue: function(el, key) {
        if (!el.classNameSplit) el.classNameSplit = el.className.split(' ');
        for (var i=el.classNameSplit.length-1; i>=0; i--) 
            if (el.classNameSplit[i].indexOf(key)>-1) 
                return el.classNameSplit[i].split(':')[1];
        return null;
    },
    createOverlayLayer: function(banner_el) {
		var overlay_div = document.createElement('DIV');
		overlay_div.className = 'adOverlay';
		banner_el.appendChild(overlay_div);
		banner_el.overlay_div = overlay_div;
		
    },
    hideCurrentBanner: function() {
		if (this.current_banner) this.current_banner.hideBanner();
    }
}

window.addEvent('domready', function() {bannerManager.initialise();});


// --------------------------------------------------------------------------------------------------------------
// --- flash-driven variant - show and hide functions;
// --------------------------------------------------------------------------------------------------------------

function showBanner() {
	document.getElementById('flashBanner').className = 'open';
}

function hideBanner() {
	document.getElementById('flashBanner').className = '';
}

// --------------------------------------------------------------------------------------------------------------
// --- end of file;
// --------------------------------------------------------------------------------------------------------------
