	if(typeof(Array.prototype.push) == 'undefined'){

		Array.prototype.push = function(item){
			var max = -1;
			for(i=0;i<this.length;i++){
				max++;
			}
			this[max+1] = item;
		}
	}

	if(typeof(AdPlayer) == 'undefined'){
		function AdPlayer() {
			this.handleEvent = 'onclick';
			this.autoTime = 3000;
			this.items = 0;
			this.curIndex = 0;
			
			var rnd = this.getRndStr(5);
			this.instanceName = "AdPlayer" + rnd;
			this.containerName = "ItemContainer" + rnd;
			this.handleContainName = "AdPlayerHandle" + rnd;
			this.itemBaseName = "ItemBaseName" + rnd;
			this.width = "500px";
			this.height = "100px";
			this.handleOnStyle = null;
			this.handleOffStyle = null;
			this.timer = null;
		}
	}

	AdPlayer.prototype.init = function(param_items)
	{
		document.write("<div id='"+ this.instanceName +"' style='width:"+ this.width +";height:"+ this.height +";'>");
		document.write("<div id='"+ this.containerName +"' style='width:"+ this.width +";height:"+ this.height +";'></div>");
		document.write("<table border='0' align='right' style='position:absolute;visibility:hidden;filter:alpha(opacity=50);-moz-opacity:0.5;opacity: 0.5;z-index:99' id='"+ this.handleContainName +"' cellspacing='3'><tr>");
		document.write("</tr></table>");
		document.write("</div>");

		var handletable = document.getElementById(this.handleContainName);
		var container = document.getElementById(this.containerName);
		for(var i = 0;i < param_items.length;i++){
			var td = document.createElement("TD");
			td.id = this.handleContainName + "_" + i;
			td.style.border = "1px solid #333333";
			td.style.background = "#eeeeee";
			td.style.padding = "3px";
			td.style.width = "12px";
			td.style.height = "8px";
			td.style.fontSize = "12px";
			td.style.cursor = "pointer";
			td.align = "center";
			td.innerHTML = "<b>" + parseInt(i + 1) + "</b>";
			var f = this.proxycall(this,this.showItem,[i]);
			this.attachEventEx(td,this.handleEvent,f);
			handletable.childNodes[0].childNodes[0].appendChild(td);

			var html = "<img src='"+ param_items[i][0] +"' style='width:"+ this.width +";height:"+ this.height +";' border='0'>";
			if(param_items[i][0].indexOf(".swf") > -1){
				html = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+ this.width +"' height='"+ this.height +"' style='z-index:-999'>";
				html += "<param name='movie' value='"+ param_items[i][0] +"'>";
				html += "<param name='quality' value='high'>";
				html += "<param name='wmode' value='transparent'>";
				html += "<param name='menu' value='false'>";
				html += "<embed src='"+ param_items[i][0] +"' width='"+ this.width +"' height='"+ this.height +"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent' menu='false'></embed>";
				html += "</object>";
			}
			if(param_items[i].length > 1) html = "<a href='"+ param_items[i][1] +"' target='"+ (param_items[i].length > 2 ? param_items[i][2] : '') +"'>"+ html +"</a>";
			//html += "<div id='"+ (this.itemBaseName + "_" + i) +"' style='display:none'>"+ html +"</div>";
			var div = document.createElement("DIV");
			div.id = (this.itemBaseName + "_" + i);
			div.style.display = 'none';
			div.innerHTML = html;
			container.appendChild(div);
		}
		
		this.setTimeoutEx(this,this.initHandlePosition,3000);

		this.items = param_items;
		this.autoShow();
	}

	AdPlayer.prototype.autoShow = function(){
		this.showItem(this.curIndex);
		this.curIndex++;
		if(this.curIndex >= this.items.length) this.curIndex = 0;
		this.timer = this.setTimeoutEx(this,this.autoShow,this.autoTime);
	}

	AdPlayer.prototype.showItem = function(index){
		for(var i = 0;i < this.items.length;i++){
			var item = document.getElementById(this.itemBaseName + "_" + i);
			if(index != i) item.style.display = 'none';
			else item.style.display = '';
			
			var handle = document.getElementById(this.handleContainName + "_" + i);
			if(index != i){
				handle.style.background = "#eeeeee";
				handle.style.color = "#333333";
				if(this.handleOffStyle != null) handle.style = this.handleOffStyle;
			}else{
				handle.style.background = "#FF0000";
				handle.style.color = "#FFFFFF";
			}
		}
		this.curIndex = index;
	}
	
	/*
	AdPlayer.prototype.autoShow = function(){
		this.showItem(this.curIndex);
		this.curIndex++;
		if(this.curIndex >= this.items.length) this.curIndex = 0;
		this.setTimeoutEx(this,this.autoShow,this.autoTime);
	}
	
	AdPlayer.prototype.showItem = function(index){
		var container = document.getElementById(this.containerName);
		var html = "<img src='"+ this.items[index][0] +"' style='width:"+ this.width +";height:"+ this.height +";' border='0'>";
		if(this.items[index][0].indexOf(".swf") > -1){
			html = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+ this.width +"' height='"+ this.height +"' style='z-index:-999'>";
            html += "<param name='movie' value='"+ this.items[index][0] +"'>";
            html += "<param name='quality' value='high'>";
            html += "<param name='wmode' value='transparent'>";
            html += "<param name='menu' value='false'>";
            html += "<embed src='"+ this.items[index][0] +"' width='"+ this.width +"' height='"+ this.height +"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent' menu='false'></embed>";
            html += "</object>";
		}
		if(this.items[index].length > 1) html = "<a href='"+ this.items[index][1] +"' target='"+ (this.items[index].length > 2 ? this.items[index][2] : '') +"'>"+ html +"</a>";
		container.innerHTML = html;
		for(var i = 0;i < this.items.length;i++){
			var handle = document.getElementById(this.handleContainName + "_" + i);
			handle.style.background = "#eeeeee";
			handle.style.color = "#333333";
			if(this.handleOffStyle != null) handle.style = this.handleOffStyle;
		}
		var handle = document.getElementById(this.handleContainName + "_" + index);
		handle.style.background = "#FF0000";
		handle.style.color = "#FFFFFF";
		this.curIndex = index;
	}*/

	AdPlayer.prototype.initHandlePosition = function(){
		var container = document.getElementById(this.instanceName);
		var left = this.getOffsetLeft(container);
		var top = this.getOffsetTop(container);
		var handletable = document.getElementById(this.handleContainName);
		handletable.style.top = top + parseInt(this.height) - 28;
		handletable.style.left = left + parseInt(this.width) - handletable.clientWidth;
		handletable.style.visibility = 'visible';
		
	}

	AdPlayer.prototype.proxycall = function(obj,method,args){
		var f = (function(){ method.apply(obj, args);});
		return f;
	}

	AdPlayer.prototype.attachEventEx = function (eid,env,action){
		var object = typeof(eid) == 'object' ? eid:document.getElementById(eid);
		if (object && object.addEventListener){
			if(/^(on)/i.test(env)) env = env.substring(2);
			object.addEventListener(env,action,true);
		}else if(object){
			object.attachEvent(env,action);
		}
	}

	AdPlayer.prototype.getRndStr = function(length)
	{
		var str = "";
		for(i = 0;i < length;i++){
			var rnd = parseInt((122 - 97 + 1) * Math.random() + 97);
			var s = String.fromCharCode(rnd);
			str += s;
		}
		return str;
	}

	AdPlayer.prototype.getOffsetLeft = function(src){
		var set = 0;
		if(src)
		{
			if (src.offsetParent) set += src.offsetLeft + this.getOffsetLeft(src.offsetParent);
			if(src.tagName != "BODY")
			{
				var x = parseInt(src.scrollLeft,10);
				if(!isNaN(x)) set -= x;
			}
		}
		return set;
	}

	AdPlayer.prototype.getOffsetTop = function(src){
		var set = 0;
		if(src)
		{
			if (src.offsetParent) set += src.offsetTop + this.getOffsetTop(src.offsetParent);
			if(src.tagName != "BODY")
			{
				var y = parseInt(src.scrollTop,10);
				if(!isNaN(y)) set -= y;
			}
		}
		return set;
	}

	//жиди setTimeout
	var AdPlayerTimeout = window.setTimeout;
	AdPlayer.prototype.setTimeoutEx = function(obj,fRef, mDelay) 
	{ 
		if(typeof(fRef) == 'function')
		{ 
			var argu = Array.prototype.slice.call(arguments,2);
			var f = (function(){ fRef.apply(obj, argu);});
			return AdPlayerTimeout(f, mDelay);
		}
		return AdPlayerTimeout(fRef,mDelay);
	}
	// end of жиди setTimeout

