Function.prototype.createDelegate = function (obj, args, appendArgs)
{
	var method = this;
	return function() {
		var callArgs = args || arguments;
		if (appendArgs === true)
		{
			callArgs = Array.prototype.slice.call(arguments, 0);
			callArgs = callArgs.concat(args);
		}
		else if (typeof appendArgs == "number")
		{
			callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
			var applyArgs = [appendArgs, 0].concat(args); // create method call params
			Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
		}
		return method.apply(obj || window, callArgs);
	};
};

ferrariPromo = function()
{
	this.titleBgColor = '#c40901';
	this.titleTextColor = '#fff';
	this.titleHeight = 15;
	this.contentBgColor = '#e60004';
	this.contentTextColor = '#fff';
	this.content = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="394" height="368"><param name="movie" value="http://www.bravo.fiat.hu/dmcenter/pics/FiatFerrari_394x368.swf"><param name="quality" value="high"><param name="wmode" value="transparent"><embed src="http://www.bravo.fiat.hu/dmcenter/pics/FiatFerrari_394x368.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="394" height="368" wmode="transparent"></embed></object>';
	this.width = 394;
	this.height = 368;
	this.top = 0;
	this.left = 0;
	
	this.getCenterLeft = function(width)
	{
		var sw = screen.width;
		
		return Math.round(sw / 2) - Math.round(width / 2);
	}
	this.getCenterTop = function(height)
	{
		var sh = screen.height;
		
		return Math.round(sh / 2) - Math.round(height / 2);
	}
	this._createWindowHeader = function()
	{
		var d = document.createElement('div');
		var title = document.createElement('a');
		var close = document.createElement('a');
		var clr = document.createElement('br');
		d.style.width = '100%';
		d.style.height = this.titleHeight.toString() + 'px';
		d.style.padding = '2px';
		d.style.overflow = 'hidden';
		d.style.backgroundColor = this.titleBgColor;
		title.style.width = (new Number(this.width - 20)).toString() + 'px';
		title.style.fontSize = '11px';
		title.style.fontWeight = 'bold';
		title.style.display = 'block';
		title.style.cssFloat = 'left';
		title.style.styleFloat = 'left';
		title.style.color = this.titleTextColor;
		title.style.backgroundColor = this.titleBgColor;
		title.style.textDecoration = 'none';
		
		title.appendChild(document.createTextNode('Fiat-Ferrari'));
		title.href = 'http://www.bravo.fiat.hu/dmcenter/FiatPrAtvizsgalas090703.aspx';
		title.onclick = function()
		{
			var url = 'http://www.bravo.fiat.hu/dmcenter/FiatPrAtvizsgalas090703.aspx';
			var win=window.open(
				url,
				'ferrariPromoWin',
				[
					'width=600',
					'height=700',
					'status=no',
					'toolbar=no',
					'scrollbars=yes'
				].join(',')
			);
			return false;
		}
		close.style.width = '15px';
		close.style.fontFamily = '"Courier New", Courier, monospace';
		close.style.fontSize = '11px';
		close.style.fontWeight = 'bold';
		close.style.display = 'block';
		close.style.cssFloat = 'right';
		close.style.styleFloat = 'right';
		close.style.color = this.titleTextColor;
		close.style.backgroundColor = this.titleBgColor;
		close.style.textDecoration = 'none';
		
		close.appendChild(document.createTextNode('X'));
		close.href = '#';
		close.onclick = this._onClose.createDelegate(this);
		clr.style.overflow = 'hidden';
		clr.style.fontSize = '0';
		clr.style.height = '0';
		clr.style.clear = 'both';
		clr.style.cssFloat = 'none';
		clr.style.styleFloat = 'none';
		
		d.appendChild(title);
		d.appendChild(close);
		d.appendChild(clr);
		
		return d;
	}
	this._onClose = function()
	{
		this.ghost.style.display = 'none';
		this.win.style.display = 'none';
		this.targeter.style.display = 'none';
		return false;
	}
	this._createWindowContent = function()
	{
		var d = document.createElement('div');
		d.style.width = '100%';
		d.style.height = this.height.toString() + 'px';
		d.style.padding = '2px';
		d.style.overflow = 'hidden';
		d.style.backgroundColor = this.contentBgColor;
		
		d.innerHTML = this.content;
		
		return d;
	}
	
	/*_______________________________________________________________________*/
	/* constructor */
	this.top = 195;
	this.left = this.getCenterLeft(this.width);
	
	this.ghost = document.createElement('iframe');
	this.ghost.style.border = 'none';
	this.ghost.style.position = 'absolute';
	this.ghost.style.top = this.top.toString() + 'px';
	this.ghost.style.left = this.left.toString() + 'px';
	this.ghost.style.width = this.width.toString() + 'px';
	this.ghost.style.height = (new Number(this.height + this.titleHeight)).toString() + 'px';
	this.ghost.style.background = '#fff';
	this.ghost.style.zIndex = '1000';
	this.ghost.src = 'null.html';
	
	this.win = document.createElement('div');
	this.win.style.position = 'absolute';
	this.win.style.top = this.top.toString() + 'px';
	this.win.style.left = this.left.toString() + 'px';
	this.win.style.width = this.width.toString() + 'px';
	this.win.style.height = (new Number(this.height + this.titleHeight)).toString() + 'px';
	this.win.style.background = '#fff';
	this.win.style.zIndex = '1001';
	this.win.style.overflow = 'hidden';
	
	this.win.appendChild(this._createWindowHeader());
	this.win.appendChild(this._createWindowContent());
	
	this.targeter = document.createElement('div');
	this.targeter.style.position = 'absolute';
	this.targeter.style.top = (new Number(this.top + this.titleHeight)).toString() + 'px';
	this.targeter.style.left = this.left.toString() + 'px';
	this.targeter.style.width = this.width.toString() + 'px';
	this.targeter.style.height = this.height.toString() + 'px';
	this.targeter.style.background = (document.all? '#fff' : 'transparent');
	this.targeter.style.cursor = (document.all? 'hand' : 'pointer');
	this.targeter.style.filter = 'alpha(opacity=1)';
	this.targeter.style.zIndex = '1002';
	
	this.targeter.onclick = function()
	{
		var url = 'http://www.bravo.fiat.hu/dmcenter/FiatPrAtvizsgalas090703.aspx';
		var win=window.open(
			url,
			'ferrariPromoWin',
			[
				'width=600',
				'height=700',
				'status=no',
				'toolbar=no',
				'scrollbars=yes'
			].join(',')
		);
		return false;
	}
	
	document.body.insertBefore(this.win, document.body.firstChild);
	document.body.insertBefore(this.targeter, document.body.firstChild);
	document.body.insertBefore(this.ghost, document.body.firstChild);
};
