function static_adjs_swf(width, height, movie, wmode) {
  if (wmode == null) wmode = "window";
  var html;
  html += '<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="' + width + '" HEIGHT="' + height + '"  style="position: absolute; left: 0px; top: 0px;">';
  html += '<PARAM NAME=movie VALUE="' + movie + '">';
  html += '<PARAM NAME=wmode VALUE="' + wmode + '">';
  html += '<PARAM NAME="Quality" VALUE="High">';
  html += '<EMBED src="' + movie + '" quality=high ';
  html += ' WMODE="' + wmode + '" NAME="flashad" swLiveConnect="TRUE" WIDTH="' + width + '" HEIGHT="' + height + '"';
  html += ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" >';
  html += '</EMBED>';
  html += '</OBJECT>';

  return html;
}

function static_adjs_render() {
  var numItems = this.assets.length;
  if (numItems == 0) return;

  var randIndex = Math.floor(Math.random() * numItems);
  var asset = this.assets[randIndex];
  var html = "<div style=\"width: " + this.width + "px; height: " + this.height + "px; overflow: hidden; position: relative;\">";
  if (asset.imgUrl.match(/\.swf$/)) {
    html += static_adjs_swf(this.width, this.height, asset.imgUrl);
  } else {
    var lnkTarget = asset.target == "" ? "" : " target=\"" + asset.target + "\"";

    html += "<a href=\"" + asset.lnkUrl + "\"" + lnkTarget + ">" +
      "<img src=\"" + asset.imgUrl + "\" width=\"" + this.width + "\" height=\"" + this.height + "\"" +
      " border=\"0\" alt=\"" + asset.title + "\" title=\"" + asset.title + "\"></a>";
  }
  html += "</div>";

  document.write(html);
}

function static_adasset(imgUrl, lnkUrl, title, target) {
  if (target == null) target = "_blank";

  this.imgUrl = imgUrl;
  this.lnkUrl = lnkUrl;
  this.title = title;
  this.target = target;
}

function static_adjs(renderNow, width, height, assets) {
  if (assets == null) assets = [];

  this.width = width;
  this.height = height;
  this.assets = assets;
  this.render = static_adjs_render;

  if (renderNow) this.render();
}
/*
// ---- sample
var fotomac = new static_adjs(true, 468, 60, [
  new static_adasset("http://img....", "http://lnk", "title"),
  new static_adasset("http://img....", "http://lnk", "title"),
  new static_adasset("http://img....", "http://lnk", "title"),
  new static_adasset("http://img....", "http://lnk", "title")
]
);
*/

function MBGSkin_LocateBanner(id, width, height, left, top, disp, visib) {
	var obj, postfix = "px";

	if (document.getElementById) {
		obj = document.getElementById(id);
		if (obj != null) obj = obj.style;
	} else if(document.all) {
		obj = document.all[id];
		if (obj != null) obj = obj.style;
	} else if(document.layers) {
		obj = document.layers[id];
		postfix = "";
	} else {
		return;
	}
	if (obj == null) return;
	
	if (width > 0 && height > 0) {
		obj.width = width + postfix;
		obj.height = height + postfix;
	} else {
		obj.width = "0" + postfix;
		obj.height = "0" + postfix;
	}

	obj.left = left + postfix;
	obj.top = top + postfix;
	obj.display = disp;
	obj.visibility = visib;
}

function MBGSkin_BannerSILO() {
	var CScreenWidth;
	var CScreenHeight;
	var CScrollTop;

	if (oMBGSkin.ns) {
		CScreenWidth = window.innerWidth-20;
		CScreenHeight = window.innerHeight;
		if (window.pageYOffset) {
			CScrollTop = window.pageYOffset;
		} else {
			CScrollTop = document.body.scrollTop;
		}
		VISIB = 'visible';
	} else if (oMBGSkin.ie || oMBGSkin.opera) {
		CScreenWidth = document.body.clientWidth;
		CScreenHeight = document.body.clientHeight;
		CScrollTop = document.body.scrollTop;
		VISIB = 'visible';
	} else {
		CScreenWidth = 0;
		CScreenHeight = 0;
		CScrollTop = 0;
		VISIB = 'hidden';
	}

	if (CScreenWidth > oMBGSkin.PageWidth) {
		MBGSkin_LocateBanner(oMBGSkin.divID,
			CScreenWidth - oMBGSkin.PageWidth - 10,
			CScreenHeight - 10,
			oMBGSkin.PageWidth + 5,
			CScrollTop + 5,
			'block', VISIB);
	} else {
		MBGSkin_LocateBanner(oMBGSkin.divID, 1, 1, 1, 1, 'none', 'hidden');
	}
}

function MBGSkin_BannerInit() {
	if (screen.width >= this.MinScreenWidth) {
		if (this.bgURL != null && this.bgURL != "")
			document.body.style.background = "url('" + this.bgURL + "') left top no-repeat fixed";
		
		var skinHtml = "";
		skinHtml += "<div id=\"" + this.divID + "\" style=\"position: absolute; left: -1px; top: -1px; width: 1px; height: 1px; display: none; visibility: hidden;\">";
		if (this.spacerHtml == null)
			skinHtml += "<a href=\"" + this.linkURL + "\" target=\"_blank\"><img src=\"" + this.spacerURL + "\" width=\"100%\" height=\"100%\" border=\"0\" alt=\"\"></a>";
		else
			skinHtml += this.spacerHtml;
		skinHtml += "</div>";
		document.write(skinHtml);

		if (window.addEventListener) {
			window.addEventListener("resize", MBGSkin_BannerSILO, false);
			window.addEventListener("scroll", MBGSkin_BannerSILO, false);
			window.addEventListener("blur", MBGSkin_BannerSILO, false);
		}
		else if(window.attachEvent) {
			window.attachEvent("onresize", MBGSkin_BannerSILO);
			window.attachEvent("onscroll", MBGSkin_BannerSILO);
			window.attachEvent("onblur", MBGSkin_BannerSILO);
		}
		MBGSkin_BannerSILO();
	}
}


// constructs a new MBG Skin object
function MBGSkin(linkURL, bgURL, spacerHtml) {
	var agent = navigator.userAgent.toLowerCase();
	this.ns = (agent.indexOf('mozilla') != -1) &&
		(agent.indexOf('spoofer') == -1) &&
		(agent.indexOf('compatible') == -1) &&
		(agent.indexOf('opera') == -1) &&
		(agent.indexOf('webtv') == -1);
	this.opera = (agent.indexOf("opera") != -1);
	this.ie = !this.opera && (agent.indexOf("msie") != -1);

	this.linkURL = linkURL;
	this.bgURL = bgURL;
	this.spacerHtml = spacerHtml;

	// site specific settings
	this.divID = "mbgSkin";
	this.PageWidth = 788;
	this.MinScreenWidth = 810;
	this.spacerURL = "http://img.sabah.com.tr/i/_spacer.gif";

	this.BannerInit = MBGSkin_BannerInit;
}

var oMBGSkin = null;
function MBGSkinCreate(linkURL, bgURL, spacerHtml) {
	oMBGSkin = new MBGSkin(linkURL, bgURL, spacerHtml);
	oMBGSkin.BannerInit();
}

function MBGScrollCreate(spacerHtml, bgURL) {
	oMBGSkin = new MBGSkin("", bgURL, spacerHtml);
	oMBGSkin.BannerInit();
}

//*** Sample usage
//MBGSkinCreate("http://www.ceptemsn.com/", "/i/ceptemsn_prog_60.jpg");
//MBGScrollCreate("<div>scroll content</div>", "/i/ceptemsn_prog_60.jpg")
