//等比例缩放图片
function FullSize(o){
	var pic = o;
	//Get image Origin Size
	var OriginImage=new Image(); 
	function GetImageWidth(oImage) { 
		if(OriginImage.src!=oImage.src)OriginImage.src=oImage.src; 
		return OriginImage.width;

	} 
	function GetImageHeight(oImage) { 
		if(OriginImage.src!=oImage.src)OriginImage.src=oImage.src; 
		return OriginImage.height; 
	} 
	var imgsrc = pic.src;
	var ow = GetImageWidth(pic);
	var oh = GetImageHeight(pic);	

	var ch = document.documentElement.clientHeight; //client height
	var dh = document.body.clientHeight; //body height
	var cw = document.body.clientWidth;//client width
	var st = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop ; //scroll top
	var w = (ow-cw>=0)?(cw-100):ow;
	var h = oh*w/ow;
	var ot = st+(ch-h)/2 + "px";
	var ol = (cw-w)/2  + "px";
		$("#dialog").html('<img src='+imgsrc+' title="Click to close" width='+w+' ><br><span>81813游戏论坛</span>');
		$("#mask").css( {width:cw,height:dh,top:0,left:0,background:'#000',opacity:0.5,filter:'alpha(opacity=50)',display:'block'} );
		$("#dialog").css( {width:w,height:'auto',top:ot,left:ol,background:'#000',padding:'15px',display:'block'} );
		$("#dialog").click( function(){ $(this).css('display','none');$("#mask").css('display','none');} );
		$("#mask").click( function(){ $(this).css('display','none');$("#dialog").css('display','none');} );
}

					

function UE_ImgReset(w, h, id){
	//alert(1);
	var obj;
	var mask = document.getElementById('mask');
	var dialog = document.getElementById('dialog');
	var cont = document.getElementById('textMain');
	var winWidth = document.documentElement.clientWidth;
	var winHeight = document.documentElement.clientHeight ;
	if(!document.getElementById(id)){
		return false;
		obj=document.images;
	}
	else {
		obj=document.getElementById(id).getElementsByTagName('img');
	}
	for(var i=0; i<obj.length; i++){
		var img=obj[i];
		if(img.width < 600) continue;
		if(img.width>w && (img.height<img.width)){
			img.height=img.height-(img.height/(img.width/(img.width-w)))
			img.width=w;		
		}else if(img.width>w &&img.height>h && (img.height>img.width)){
			img.width=w;
			img.height=img.height-(img.height/(img.width/(img.width-w)))
		}
		var pic_con = document.createElement( "p" );
		var enlarge = document.createElement( "span" );
		pic_con.style.position = "relative";
		pic_con.style.width = img.width+'px';
		pic_con.style.height = img.height+'px';
		pic_con.className = "pic_enlarge";
		enlarge.style.position = "absolute";
		enlarge.style.top = "15px";
		enlarge.style.left = "15px";
		pic_con.appendChild( enlarge );
		if(img.parentNode.nodeName == "A"){	
			img.parentNode.parentNode.insertBefore( pic_con,img.parentNode );
			pic_con.appendChild( img );
		}else{
			img.parentNode.insertBefore( pic_con,img );
			pic_con.appendChild( img );
		}
		pic_con.onmouseover = function(){ this.className = 'pic_enlarge pic_enlarge_on'}
		pic_con.onmouseout = function(){ this.className = 'pic_enlarge'}
		img.onmouseover = function(){
			var l = this.offsetLeft+this.width-70;
			var t = this.offsetTop+this.height -70;
			var btn = $(this).siblings() ;
			var img = this;		
			btn.css({left:l+'px',top:t+'px'});
			btn.click(function(){FullSize(img)})
		}
		img.onclick = function(){FullSize(this);}
	}

}

$(document).ready(function(){ UE_ImgReset(700, 580, 'myImg');})
//加入收藏
function addFavor(board) {
//Fun.$fav(window.location.href, document.getElementsByTagName("title")[0].innerHTML);
	if(!confirm('确认将本帖子加入收藏？')) 	{
		return false;
	}
	Request.sendPOST("/member/favor/add", "board="+board, addFavorDone);
}
function addFavorDone(originalRequest) {
	var result = eval('('+originalRequest.responseText+')');
	alert(result.info);
}

//复制
function copyToClipBoard(){
	var clipBoardContent=document.getElementById("thread_title").innerText;
	clipBoardContent+="\r\n"+window.location.href;
	if(window.clipboardData){
		window.clipboardData.setData("Text",clipBoardContent);
		alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友！");
	}else{
		alert("您的浏览器不支持复制功能，请手动操作！");	 
	}
}

//ajax 请求
var Request = new Object();

Request.send = function(url, method, callback, data, urlencoded) {
        var originalRequest;        
        if (window.XMLHttpRequest) {
                originalRequest = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
                originalRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        originalRequest.onreadystatechange = function() {
                if (originalRequest.readyState == 4) {// only if req shows "loaded"
                        if (originalRequest.status < 400) {// only if "OK"
                                (method=="POST") ? callback(originalRequest) : callback(originalRequest,data);
                        } else {
                                //alert("There was a problem loading data :\n" + req.status+ "/" + req.statusText);
                        }
                }
        }
        if (method=="POST") {
                originalRequest.open("POST", url, true);
                if (urlencoded) originalRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                originalRequest.send(data);
        } else {                
                originalRequest.open("GET", url, true);
                originalRequest.send(null);
        }
        
        return originalRequest;
}

Request.sendRawPOST = function(url, data, callback) {
        Request.send(url, "POST", callback, data, false);
}
Request.sendPOST = function(url, data, callback) {
        Request.send(url, "POST", callback, data, true);
}
Request.sendGET = function(url, callback, args) {
        return Request.send(url, "GET", callback, args);
}
/**
 * 分页View层
 *
 * example:
 *		<code>
 *			slicePage.showPage(100, 20, 3, "page", "qwerw=test&sohu=laji");
 *		</code>
 * CSS Interface slicePage,currentPage
 *
 * Last Modify:	2005-11-8
 * @author:		Seateng
 * @version:	0.01
 */
var slicePage = new Object();

slicePage.showPage = function(total, currentPage, showNum, url, param)
{
	var i;

	//当前页左右的页数
	var base_num = 5;

	//传递的URL
	this.url = url;

	//传递参数
	this.param = param;

	//总页数
	this.totalPage = Math.ceil(total/showNum);

	//当前页
	currentPage = currentPage>this.totalPage?this.totalPage:currentPage;
	this.currentPage = currentPage;

	//如果记录数小于显示数则不显示分页
	if (total<=showNum){
	    //document.write('<span id=slicePage>共'+this.totalPage+"页&nbsp;&nbsp;</span>");
	    return;
	}

	//生成分页
	document.write('<span id=slicePage class=us91_pages_con>');
	//document.write('共'+this.totalPage+"页&nbsp;&nbsp;");
	//document.write("<span>Pages: (" + currentPage + "/" + this.totalPage +" total)</span>");
	if (currentPage != 1) {
		document.write('<a href="'+this.go(1)+'">&lt;First</a>');
		document.write('<a href="'+this.go(currentPage-1)+'">&lt;Prev</a>');
	} else {
		document.write('<a href="'+this.go(1)+'" class="disabled">&lt;First</a>');
		document.write('<a href="'+this.go(currentPage-1)+'" class="disabled">&lt;Prev</a>');
	}

	for (i=((currentPage-base_num)>0?currentPage-base_num:1);
	i <= ((currentPage+base_num)<this.totalPage?currentPage+base_num:this.totalPage);
	i++)
	{
		if (currentPage == i) {
			document.write('<strong class=on>'+ i +'</strong>');
		}else{
			document.write('<a href="'+this.go(i)+'">'+ i +'</a>');
		}
	}

	if(this.totalPage>10 && this.totalPage > currentPage+base_num) {
	   document.write('<a href="'+this.go(this.totalPage)+'">..'+ this.totalPage +'</a>');
	}
	if (currentPage<this.totalPage) {
		document.write('<a href="'+this.go(currentPage+1)+'" class="next">Next&gt;</a></li>');
	}
	if (this.totalPage!=currentPage) {
		document.write('<a href="'+this.go(this.totalPage)+'" class="next">End&gt;</a></li>');
	}
	document.write('&nbsp;Go:<input type="text" size="2" onkeydown="javascript: if(event.keyCode==13) window.location=slicePage.go(this.value)"></span>');
}

/**
 * 跳转方法
 */
slicePage.go = function(page)
{
	page = parseInt(page);
	if (page>0 && page != this.currentPage) {
		if (page>this.totalPage) {
			return this.url.replace("?", this.totalPage)+(this.param==""?"":"?"+this.param);
		}else{
			return this.url.replace("?", page)+(this.param==""?"":"?"+this.param);
		}
	}
	return "javascript:void(0)";
}


var slicePageForGetOwnerThread = new Object();

slicePageForGetOwnerThread.showPage = function(owner_thread_info_array, currentPage, showNum,getVar, url)
{
	var prev_page, next_page;
	prev_page = currentPage-1;
	if (owner_thread_info_array['has_next_page'])
		next_page = currentPage+1;
	else 
		next_page = 0;
	if (prev_page>=1) {
		document.write((prev_page>=1 ? '<a href="' + getVar + '-' + prev_page + '.html' + '">'  : '') + 'Prev' + (prev_page>=1 ? '</a>'  : ''));
	}
	if (next_page) {
		document.write('&nbsp;');
		document.write((next_page ? '<a href="' + getVar + '-' + next_page + '.html' + '">'  : '') + 'Next' + (next_page ? '</a>'  : ''));
	}
}
