var Class = {
	create:function(){
		return function(){
			this.initialize.apply(this,arguments);
		}
	}
}

var picSwitch = Class.create();

picSwitch.prototype = {
	array:[],
	img:new Image(),
	title:null,
	content:null,
	time:5000,
	adNum:0,
	instance:this,
	timeout:null,
	setArray:function(array){
		this.array = array;
	},
	setTime:function(time){
		this.time = time;
	},
	setDuration:function(duration){
		this.img.filters.revealTrans.Duration = duration;
	},
	setStyle:function(o,_style){
		for(property in _style){
			o.style[property] = _style[property];
		}
	},
	initialize:function(Options){
		this.img = Options["img"];
		this.array = Options["array"];
		this.title = Options["title"];
		this.content = Options["content"];
		this.time = Options["time"];
		this.moreLink = Options["moreLink"];
		this.menuList = Options["menuList"];
		this.img.filters.revealTrans.Duration = Options["duration"];
		var _style = {
			"cursor":"pointer"
		}
		this.setStyle(this.img,_style);
		//alert(img.filters.revealTrans.Transition);
		this.play();
	},
	play:function(n){
		with(this){
			adNum = adNum==array.length?0:adNum;
			if(typeof(n)!='undefined'){
				adNum = n;
			}
			if(document.all){
				img.filters.revealTrans.Transition=18;
				img.filters.revealTrans.apply();
				img.filters.revealTrans.play();
			}
			var i = adNum;
			img.innerHTML = array[i].src;
			if(array[i].link.length>0){
				img.style.cursor = "pointer";
				img.onclick = function(){
					window.open(array[i].link);
					//location.href=array[i].link;
				}
			}
			if(array[i].title){
				title.innerHTML = array[i].title;
			}
			if(array[i].link.length>0){
				/*img.onclick = function(){
					window.open(array[i].link);
				}*/
				title.innerHTML = "<a href=\""+array[i].link+"\" target=\"_blank\">"+title.innerHTML+"</a>";
				moreLink.href = array[i].link;
			}
			content.innerHTML = array[i].content;
			write(adNum);
			adNum++;
			if(timeout){
				window.clearTimeout(timeout);
			}
			timeout = window.setTimeout(function(){play()},time);
		}
	},
	write:function(n){
		var writeDiv = document.createElement("div");
		for(var i = 0;i<this.array.length;i++){
			var className = "menuImgNoSel";
			var isThis = false;
			if(i == n){
				className = "menuImgSel";
				isThis = true;
			}
			var childDiv = document.createElement("div");
			childDiv.className = className;
			childDiv.innerHTML = i+1;
			childDiv.style.cursor = "pointer";
			childDiv.i = i;
			if(!isThis){
				with(this){
					childDiv.onmouseover = function(){
						this.className = "menuImgSel";
					}
					childDiv.onmouseout = function(){
						this.className = "menuImgNoSel";
					}
					childDiv.onclick = function(){
						play(this.i);
					}
				}
			}
			writeDiv.appendChild(childDiv);
		}
		this.menuList.innerHTML = "";
		this.menuList.appendChild(writeDiv);
	},
	stop:function(){
		with(this){
			window.clearTimeout(timeout);
			img.filters.revealTrans.stop();
		}
	}
}