﻿/*
*descrition:幻灯片图片方法：包括小图导航、大图切换效果等
*author:cici
*date：2009-06-30
*/
function imageonmousemove(evnt)
{
	var photopos = getpos($("bigImage"));

	if (evnt)
	{
		//nx = (parseInt(evnt.clientX)-photopos2.left) / $("bigImage").width;
		nx = (parseInt(evnt.clientX)-photopos.left) / $("bigImage").width;
		if((nx>0.5 && $("nextLink")) ||($("preLink")==null && $("nextLink")))
		{
			$("bigImage").style.cursor = "url("+"http://img.ifeng.com/tres/TemplateRes/right.cur"+"),auto";
			$("bigImage").title = "点击浏览下一张>>";
		}
		
		if ( (nx<=0.5 && $("preLink")) || ($("nextLink")==null && $("preLink")))
		{
			$("bigImage").style.cursor = "url("+"http://img.ifeng.com/tres/TemplateRes/left.cur"+"),auto";
			$("bigImage").title = "<<点击浏览上一张";
		}
	}
}
function imageonclick(evnt)
{
	var photopos = getpos($("bigImage"));

	if (evnt)
	{
		nx = (parseInt(evnt.clientX)-photopos.left) / $("bigImage").width;
	}

	if((nx>0.5 && $("nextLink")) ||($("preLink")==null && $("nextLink")))
	{
		var href= $("nextLink").href;
		window.location.href = href;
	}
	
	if ( (nx<=0.5 && $("preLink")) || ($("nextLink")==null && $("preLink")))
	{
		var href= $("preLink").href;
		window.location.href = href;
	}
}
/*
切换图片时图片幻灯展示的效果
*/
function ChangeImg(){
	var transition = 12;//图片切换时渐变方式 1－－23
	var tranSpeed = 0.5;//图片切换渐变速度。 值越小速度越快
	
	var oImg = $("bigImage");
	if(!oImg) return;
	if (document.all){ 
		oImg.filters.revealTrans.apply();
	}
	if (document.all)
	{
		if(!this.tranRandom) oImg.filters.revealTrans.transition = transition;
		oImg.style.visibility = "";
		oImg.style.display ="block";
		oImg.filters.revealTrans.play(tranSpeed);
	}
	else
	{
		oImg.style.visibility = "";
	}
}

//获取元素的位置
function getpos(element)
{
        if ( arguments.length != 1 || element == null )
        {
               return null;
        }
        var elmt = element;
        var offsetTop = elmt.offsetTop;
        var offsetLeft = elmt.offsetLeft;
        var offsetWidth = elmt.offsetWidth;
        var offsetHeight = elmt.offsetHeight;
        while( elmt = elmt.offsetParent )
        {
                // add this judge
                if ( elmt.style.position == 'absolute'
//              || elmt.style.position == 'relative'
                || ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) )
                {
                        break;
                }
                offsetTop += elmt.offsetTop;
                offsetLeft += elmt.offsetLeft;
        }
        return {top:offsetTop, left:offsetLeft, right:offsetWidth+offsetLeft, bottom:offsetHeight+offsetTop };
}
//关于图片的方法 结束

//页面的方法 开始
var defaultSmallPic = "http://img.ifeng.com/tres/TemplateRes/pic70.jpg";
var curIndex = currentSmallImgIndex;
	//////////////////////////图片方法////////////////////////////////////
function nextPic2()
{
	curIndex++;
	ResetSmallImage();
}
function prePic2()
{
	curIndex--;
	ResetSmallImage();
}
function ResetSmallImage()
{
	if(curIndex>=imgs.picCount()) return;
	$("picCount2").innerHTML = imgs.picCount();
	$("picIndex2").innerHTML = (curIndex+1) +" ";


	$("photoList1").src = imgs.get(curIndex)==null?defaultSmallPic:imgs.get(curIndex).smallpic;
	$("photoList2").src = imgs.get(curIndex+1)==null?defaultSmallPic:imgs.get(curIndex+1).smallpic;
	$("photoList3").src = imgs.get(curIndex+2)==null?defaultSmallPic:imgs.get(curIndex+2).smallpic;
	$("photoList4").src = imgs.get(curIndex+3)==null?defaultSmallPic:imgs.get(curIndex+3).smallpic;
	$("photoList5").src = imgs.get(curIndex+4)==null?defaultSmallPic:imgs.get(curIndex+4).smallpic;
	
	$("photoList1").parentNode.href =  imgs.get(curIndex)==null?"javascript:void(0);": imgs.get(curIndex).url;
	$("photoList2").parentNode.href =  imgs.get(curIndex+1)==null?"javascript:void(0);": imgs.get(curIndex+1).url;
	$("photoList3").parentNode.href =  imgs.get(curIndex+2)==null?"javascript:void(0);": imgs.get(curIndex+2).url;
	$("photoList4").parentNode.href =  imgs.get(curIndex+3)==null?"javascript:void(0);": imgs.get(curIndex+3).url;
	$("photoList5").parentNode.href =  imgs.get(curIndex+4)==null?"javascript:void(0);": imgs.get(curIndex+4).url;
	
	for(var i=1;i<=5;i++)
	{
		$("photoList" + i).parentNode.parentNode.className="";
	}
	
	var currentObj = $("photoList" + (currentSmallImgIndex-curIndex+1));
	if(currentObj) 
		currentObj.parentNode.parentNode.className = "current";
	
	if(curIndex==0)//第一张
	{
		$("preli2").innerHTML = '<img src="http://img.ifeng.com/tres/DocRes/8/tjicon_14.gif" border="0" />';
		//preli2.innerHTML = '';
	}
	else
	{
		$("preli2").innerHTML = '<a id="pre2" href="javascript:prePic2();"><img src="http://img.ifeng.com/tres/DocRes/8/tjicon_14.gif" border="0" /></a>';
	}

	
	if(curIndex == imgs.picCount()-1)//最后一张
	{
		$("nextli2").innerHTML = '<img src="http://img.ifeng.com/tres/DocRes/8/tjicon_18.gif" border="0" />';
		//$("nextli2").innerHTML = '';
	}
	else
	{
		$("nextli2").innerHTML = '<a id="next2" href="javascript:nextPic2();"><img src="http://img.ifeng.com/tres/DocRes/8/tjicon_18.gif" border="0" /></a>';
	}	
}


function ImgItem() {
	this.title="";
	this.url="";
	this.pic="";
	this.smallpic="";
	this.memo="";
	this.width=0;
	this.height=0;	
}
ImgItem.prototype = {           
	toImgHTML:function()
	{
		//todo...
	},
	toAHTML:function()
	{
		//todo...
	}
}
function ImgItems(){
	
	this.Imgs = new Array();
	
	this.add = addImg;
	this.get = getImg;
	this.picCount = picCount;
	this.toLiHtml = toLiHtml;
	this.doDivHtml = doDivHtml;
	
	function addImg(item){
		this.Imgs[this.Imgs.length] = item;
	}
	
	function getImg(i){
		if(i<this.Imgs.length) return this.Imgs[i];
		else return null;
	}
	function picCount()
	{
		return this.Imgs.length;
	}
		   
	function toLiHtml(){
		//todo...
	}
	
	function doDivHtml(){
		//todo...
	}
}
function $(id)
{
	return document.getElementById(id);
}

