/* ---| Advertisement Object |--- */
function Ad(ad_id, file_url, real_file_url, click_url, ad_type) {
	this._ad_id = ad_id;
	this._file_url = file_url;
	this._real_file_url = real_file_url;
	this._click_url = click_url;
	this._target = "_blank";
	this._ad_type = ad_type;
	this._record_impression=true;
}

/* ---| Advertisement Attributes |--- */
Ad.prototype._ad_id;
Ad.prototype._ad_type;
Ad.prototype._file_url;
Ad.prototype._real_file_url;
Ad.prototype._click_url;
Ad.prototype._target;
Ad.prototype._record_impression;

/* ---| Advertisement Functions |--- */
Ad.prototype.getAdId = function() { return this._ad_id; }
Ad.prototype.getAdType = function() { return this._ad_type; }
Ad.prototype.getFileUrl = function() { return this._file_url; }
Ad.prototype.getRealFileUrl = function() { return this._real_file_url; }
Ad.prototype.getClickUrl = function() { return this._click_url; }
Ad.prototype.getTarget = function() { return this._target; }
Ad.prototype.getRecordImpression = function() { return this._record_impression; }
Ad.prototype.setRecordImpression = function(recordImpression) { this._record_impression=recordImpression; }

/* ---| Advertisement Relocate Functions |--- */
function Relocate(click_url) { window.open (click_url); }

/* ---| Position Object |--- */
function Position(code, container, overlay, timeout, width, height, ads) {
	this._code = code;
	this._container = container;
	this._overlay = overlay;
	this._timeout = (timeout*1000);
	this._width = width;
	this._height = height;
	this._ads = ads;
	this._current_ad = 0;
}

/* ---| Position Attributes |--- */
Position.prototype._code;
Position.prototype._container;
Position.prototype._overlay;
Position.prototype._timeout;
Position.prototype._width;
Position.prototype._height;
Position.prototype._ads;

/* ---| Position Functions |--- */
Position.prototype.getCode = function() { return this._code; }
Position.prototype.getContainer = function() { return this._container; }
Position.prototype.getOverlay = function() { return this._overlay; }
Position.prototype.getTimeout = function() { return this._timeout; }
Position.prototype.getWidth = function() { return this._width; }
Position.prototype.getHeight = function() { return this._height; }

/* ---| Position Init Functions |--- */
Position.prototype.init = function() {
	var positionObject=this;
	this._ads[0].setRecordImpression(false);
	if (this._ads.length>1) {
		setTimeout(function () { positionObject.rotate() },this._timeout);
	}
}

/* ---| Position Rotate Functions |--- */
Position.prototype.rotate = function() {

	if (this._current_ad >= this._ads.length-1) {
		this._current_ad=0;
	} else {
		this._current_ad++;
	}

	var _positionContainer = document.getElementById(this._code);
	var _objAd = this._ads[this._current_ad];

	var _fileUrl = "";
	if (_objAd.getRecordImpression()) {
		_fileUrl=_objAd.getFileUrl()+"&recordImpression="+_objAd.getRecordImpression();
	} else {
		_fileUrl=_objAd.getRealFileUrl();
	}
	_objAd.setRecordImpression(false);

	if (_objAd.getAdType()=="flash") {
		var flashvars = {};
			flashvars.clickURL = escape(_objAd.getClickUrl());
			flashvars.flashBannerURL = escape(_fileUrl);
			flashvars.target = _objAd.getTarget();
		var params = {};
			params.quality = "high";
			params.wmode = "transparent";
			params.scale = "noscale";
			params.allowscriptaccess = "always";
			params.allownetworking = "all";
			params.movie = "/common_scripts/flash/flashBannerLoader/flashBannerLoader.swf";
		var attributes = {};
		swfobject.embedSWF("/common_scripts/flash/flashBannerLoader/flashBannerLoader.swf", this._container, this._width, this._height, "9.0.0", false, flashvars, params, attributes);
		jQuery('#' + this._overlay).show();
	} else {
		_positionContainer.innerHTML = "<a href='" + _objAd.getClickUrl() + "' target='" + _objAd.getTarget() + "'><img src='" + _fileUrl + "' /></a>";
		jQuery('#' + this._overlay).hide();
	}
	
	jQuery('#' + this._overlay).unbind('click');
	jQuery('#' + this._overlay).click(function() { Relocate(_objAd.getClickUrl()); });


	var positionObject=this;
	setTimeout(function () { positionObject.rotate() },this._timeout);

}


