 
var SwitchPicture = Class.create();

SwitchPicture.prototype = {
	//服务器提供的服务的标识
	OBJECTID: "DocInfo",
	
	imageWidth 	: 300,		//图片宽度
	setImageWidth : function(w) { this.imageWidth = w },
	getImageWidth : function( ) { return this.imageWidth },
	
	imageHeight	: 200,		//图片高度
	setImageHeight : function(h) { this.imageHeight = h },
	getImageHeight : function( ) { return this.imageHeight },
	
	textHeight	: 20,		//文字高度
	setTextHeight : function(h) { this.textHeight = h },
	getTextHeight : function( ) { return this.textHeight },
	
	textLength	: 0,		//显示文字的字个数
	setTextLength : function(l) { this.textLength = l },
	getTextLength : function( ) { return this.textLength },
	
	rows : 5,				//显示记录数
	setRows : function(r) { this.rows = r },
	getRows : function( ) { return this.rows },
	
	start : 1,				//起始记录序号
	setStart : function(i) { this.start = i },
	getStart : function( ) { return this.start },
	
	
	//构造方法
	initialize: function(){},
	
	create : function(alias, containerID) {
		var url = CONTEXT_PATH + "getXML?object=" + this.OBJECTID 
			+ "&action=getImageList"
			+ "&alias=" 	+ alias
			+ "&start=" 	+ this.start
			+ "&rows=" 		+ this.rows 
			+ "&length="	+ this.textLength;
		
		//alert(url);
		
		if(arguments.length > 2 && typeof(arguments[2]) == "function") {
			this.render = arguments[2];
		}
		
		var parent = this;
		
		var ajaxObj = new Ajax.Request(
			url,
			{
				method : 'get',
				onComplete : function(resp) {
					//alert(parent);
					parent.render(resp,containerID);
				}
			}
		);
		
	},
	
	renderImage : function(resp,containerID) {
		var container = $(containerID);
		
		if(!container) {
			alert("SwitchPicture -> rendar error: container [" + containerID + "] 未定义。");
			return ;
		}
				
		//获取XML数据
		var data = resp.responseXML;
		
		//获取链接结点数组
		var docs = data.getElementsByTagName("row");
		
		var imgs = new Array();
		var titles = new Array();
		var urls = new Array();
		var node = null;
		
		//循环显示每条记录
		if(docs.length > 0) {
			var i=0
			var mainpic = getValue(docs[i],"mainpic");
			if(mainpic.length == 0)  return ; 
			
			var id 			= getValue(docs[i],"id");
			var fullTitle 	= getValue(docs[i],"title");
			var title 		= getValue(docs[i],"title");
			if(this.textLength > 0 && title.length > this.textLength) title = title.substring(0,this.textLength) + "...";
			var contentType		= getValue(docs[i],"contenttype");			
			var createdDate		= getValue(docs[i],"createddate");
			if(createdDate.length > 10) createdDate = createdDate.substring(0,10);
			
			var url = "#";
			contentType = parseInt(contentType);
			
			switch(contentType) {
				case 1:
					url = DOCINFO_DETAILURLBASE + id;
					break;
				case 2:
					url = getValue(docs[i], "contenturl");
					break;
					
				case 3:
					url = DOCINFO_UPLOADPATH + getValue(docs[i], "contenturl");
					break;
			}
			
		
			var html = "<a href='NewsDetail.jsp?ID=" + id + "' title='" + fullTitle + "' target='_blank'><img src='" + DOCINFO_UPLOADPATH + mainpic + "' border='0'/></a>";
					  ///+ "<div style='line-height:28px'><a href='NewsDetail.jsp?ID=" + id + "' title='" + fullTitle + "' target='_blank'>" + title + "</a></div>";
		
			alert(html);
			container.innerHTML = html;

		}

	},
	
	render : function(resp,containerID) {
		var container = $(containerID);
		
		if(!container) {
			alert("SwitchPicture -> rendar error: container [" + containerID + "] 未定义。");
			return ;
		}
				
		//获取XML数据
		var data = resp.responseXML;
		
		//获取链接结点数组
		var docs = data.getElementsByTagName("row");
		
		var imgs = new Array();
		var titles = new Array();
		var urls = new Array();
		var node = null;
		
		//循环显示每条记录
		for(var i=0 ; i<docs.length ; i++) {
			var mainpic = getValue(docs[i],"mainpic");
			
			if(mainpic.length == 0)  continue ; 
			
			
			var id = getValue(docs[i],"id");
			
			var fullTitle = getValue(docs[i],"title");
			
			var title = getValue(docs[i],"title");

			if(this.textLength > 0 && title.length > this.textLength) title = title.substring(0,this.textLength) + "...";
			
			var contentType	= getValue(docs[i],"contenttype");
			
			var createdDate	= getValue(docs[i],"createddate");
			
			createdDate = createdDate.substring(0,10);
			
			var url = "#";
			contentType = parseInt(contentType);
			
			switch(contentType) {
				case 1:
					url = DOCINFO_DETAILURLBASE + id;
					break;
				case 2:
					node = getValue(docs[i],"contenturl");
					if(node) url = node.nodeValue;
					break;
					
				case 3:
					node = getValue(docs[i],"contenturl");
					if(node) url = DOCINFO_UPLOADPATH + node.nodeValue;
					break;
			}
			
			
			imgs.push(DOCINFO_UPLOADPATH + mainpic);
			
			urls.push(url);
			titles.push(title);
			
			
		}
		
		var ovalue = "pics=" + imgs.join("|") 
				+ "&links=" + urls.join("|") 
				+ "&texts=" + titles.join("|")
				+ "&borderwidth=" + this.imageWidth 
				+ "&borderheight=" + this.imageHeight
				+ "&textheight=" + this.textHeight;
				
		var html = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" "
			+ "codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" "
			+ "width=\"" + this.imageWidth + "\" height=\"" + (this.imageHeight + this.textHeight) + ">"
			+ "<param name=\"allowScriptAccess\" value=\"sameDomain\">"
			+ "<param name=\"movie\" value=\"" + SWITCHPICTURE_IMAGE + "\">"
			+ "<param name=wmode value=transparent>"
			+ "<param name=\"quality\" value=\"high\">"
			+ "<param name=\"menu\" value=\"false\">"
			+ "<param name=wmode value=\"opaque\">"
			+ "<param name=\"FlashVars\" value=\"" + ovalue + "\">"
			+ "<embed src=\"" + SWITCHPICTURE_IMAGE + "\" wmode=\"opaque\" "
			+ "FlashVars=\"" + ovalue + "\" menu=\"false\" bgcolor=\"#DADADA\" quality=\"high\" "
			+ "width=\"" + this.imageWidth + "\" height=\"" + (this.imageHeight + this.textHeight) + "\" allowScriptAccess=\"sameDomain\" "
			+ "type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />"
			+ "</object>"
		//alert(html);
		container.innerHTML = html;
		
	}
	
	
};
