var __photo_Script=document.getElementsByTagName("script");
var __photo_Path=__photo_Script[__photo_Script.length-1].src.substring(0,__photo_Script[__photo_Script.length-1].src.lastIndexOf("/")+1);
	var photoPlayer = function () {
	var _this = this; //播放器宽度
	this.width = 0; //播放器高度
	this.height = 0; //图片编号
	this.id = ""; //图片标题
	this.title = ""; //图片地址
	this.url = ""; //图片原始宽度
	this.photoWidth = 0; //图片原始高度
	this.photoHeight = 0; //定时器
	this.timer = null; //预读图片对象
	this.image = null; //当前索引
	this.currentIndex = 0; //图片资源数组
	this.elements = []; //添加资源
	this.addPhoto = function(id,title,url){
		var resource = id + "|" + title + "|" + url; this.elements.push(resource);
	} 
	//工具栏
	this.tools = ["prev","next","resize","zoom","camera","about"];
	this.initializeTools = function (){
		var tools = document.getElementById("tools");
		for (var toolsIndex=0;toolsIndex<this.tools.length ;toolsIndex++){
			switch (this.tools[toolsIndex]){
				case "prev":
					var anchor = document.createElement("a"); anchor.href = "javascript:";
					anchor.innerHTML = "<img src=\""+__photo_Path+"images/js/2008716105033972.gif\" alt=\"上一张\"/>";
					anchor.onclick = function() { _this.prev() }; tools.appendChild( anchor );
					break;
				case "next":
					var anchor = document.createElement("a"); anchor.href = "javascript:";
					anchor.innerHTML = "<img src=\""+__photo_Path+"images/js/2008716105037205.gif\" alt=\"下一张\"/>";
					anchor.onclick = function() { _this.next() }; tools.appendChild( anchor );
					break;
				case "resize":
					var anchor = document.createElement("a"); anchor.href = "javascript:";
					anchor.innerHTML = "<img src=\""+__photo_Path+"images/js/2008716105038303.gif\" alt=\"实际大小\"/>";
					anchor.onclick = function() { _this.resize() }; tools.appendChild( anchor );
					break;
				case "zoom":
					var anchor = document.createElement("a"); anchor.href = "javascript:";
					anchor.innerHTML = "<img src=\""+__photo_Path+"images/js/2008716105038322.gif\" alt=\"自动缩放\"/>";
					anchor.onclick = function() { _this.zoom() }; tools.appendChild( anchor );
					break;
				case "about":
					var anchor = document.createElement("a"); anchor.href = "javascript:";
					anchor.innerHTML = "<img src=\""+__photo_Path+"images/js/20092395813131.gif\" alt=\"关闭窗口\"/>";
					anchor.onclick = function() { closephotoPlayer() }; tools.appendChild( anchor );
					break;
			}
		}
	}
	this.show = function () {
		var playerHTML = "";
		playerHTML += "<div id=\"photoPlayer\" style=\"width:";
		playerHTML += this.width;
		playerHTML += "px;height=\"";
		playerHTML += this.height;
		playerHTML += "px;\">\n";
		playerHTML += "<div id=\"photo\" align=\"center\">\n";
		playerHTML += "<img id=\"photoResource\" alt=\"\"/>\n"
		playerHTML += "</div>\n";
		playerHTML += "<div id=\"title\">\n";
		playerHTML += "</div>\n";
		playerHTML += "<div id=\"tools\">\n";
		playerHTML += "</div>\n";
		playerHTML += "</div>\n";
		document.writeln( playerHTML ); this.initializeTools();this.render();
	}
	this.render = function(){
		var photo = this.elements[this.currentIndex].split("|");
		this.id = photo[0]; this.title = photo[1]; this.url = photo[2];
		this.image = new Image(); this.image.src = this.url;
		this.photoWidth = this.image.width; this.photoHeight = this.image.height;
		var photoResource = document.getElementById("photoResource");
		if( this.photoWidth > 0 && this.photoHeight > 0 ){
			if( this.photoWidth/this.photoHeight >= this.width/this.height ){
				if( this.photoWidth > this.width ){
					photoResource.width = this.width; photoResource.height = (this.photoHeight * this.width ) / this.photoWidth;
				}else{
					photoResource.width= this.photoWidth; photoResource.height = this.photoHeight;
				}
			 }else{
				if( this.photoHeight > this.height){
					photoResource.height = this.height; photoResource.width = (this.photoWidth * this.height) / this.photoHeight;
				}else{
					photoResource.width = this.photoWidth; photoResource.height = this.photoHeight;
				} 
			}
		}
		photoResource.src = this.image.src; photoResource.alt = this.title; this.image = null;
	}
	this.prev = function(){
		if ( (this.currentIndex-1) >= 0 ){
			this.currentIndex--;
		}else{
			this.currentIndex = this.elements.length - 1;
		}
		this.render();
	}
	this.next = function(){
		if ( (this.currentIndex+1) < this.elements.length){
			this.currentIndex++;
		}else{
			this.currentIndex = 0;
		}
		this.render();
	}
	this.resize = function(){
		var photoResource = document.getElementById("photoResource");
		photoResource.width = this.photoWidth; photoResource.height = this.photoHeight;
	}
	this.zoom = function(){this.render();}
	this.slider = function (){
		if ( this.currentIndex + 1 >= this.elements.length ){
			this.currentIndex = 0;
		}else{
			this.currentIndex++;
		}
		this.render();
	}
	this.camera = function() {
		if ( this.timer ){
			window.clearInterval( this.timer ); this.timer = null;
		}else{
			this.timer = window.setInterval( function() { _this.slider(); },3000 );
		}
	}
	this.about = function(){
	}
}

function openphotoplayer(N){
	var e=window.event.srcElement,Obj;
	if (arguments.length == 0 ){
		Obj = e;
    }else{
		if(typeof(arguments[0])=='object'){
			Obj=arguments[0];
		}else{
        	Obj = document.getElementById(arguments[0]);
		}
    }
	//取得对象位置给层定位
	var t = e.offsetTop,  h = e.clientHeight, l = e.offsetLeft,p = e.type;//控件的信息
	while (e = e.offsetParent){t += e.offsetTop; l += e.offsetLeft;}
	
	var cw = $("photoPlayer").clientWidth, ch = $("photoPlayer").clientHeight;
    var dw = document.body.clientWidth, dl = document.body.scrollLeft, dh = document.body.clientHeight,dt = document.body.scrollTop;
	//if (document.body.clientHeight + dt - t - h >= ch) {
        $("photoPlayer").style.top = ((p=="image")? t + h : t + h -250 )+'px';
		
    //}else {
        //$("photoPlayer").style.top  = ((t - dt < ch) ? ((p=="image")? t + h : t + h+3) : t - ch)+'px';
   // }
    //if (dw + dl - l >= cw){
       // $("photoPlayer").style.left = (l-380)+'px'; 
   // }else{ 
       // $("photoPlayer").style.left = ((dw >= cw) ? dw - cw + dl : dl)-24+'px';
    //}

//alert('dd')
player.currentIndex=N;

document.getElementById("photoPlayer").style.display="";
}
function closephotoPlayer(){
document.getElementById("photoPlayer").style.display="none";
}
