function InfoData() {
	this.info = {};
	this.observeres = [];
}
InfoData.prototype.register = function(observer) {
	this.observeres.push(observer);
};
var browserCanBlend = (true);
var transitions = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
var arrPreload = new Array();
var imageSrcArray = new Array();
var imageLittleSrcArray = new Array();
var imageNameArray =new Array();
var imageContentArray =new Array();
var SHOWINGSTRING='第<FONT color=#ff6600>%slideNum</FONT>/%slideTotal张';
var _PRELOADRANGE = 4;		//缩略图数量
var _PREVIEW_WIDTH = 202;	//缩略图的宽度
var curImg = 0;				//当前图片的index
var numImgs = 0;			//总照片数
var begImg  = 0;			//初始化的图片的index
var firstframeindex  = -1;	//缩略图左边第一张的index
var inittimer  = null;		//用于首次打开时显示图片


function scalePhoto(imgId, width, height) {
    var img = document.getElementById(imgId);

    if (img != null) {
        var imgWidth = img.width;
        var imgHeight = img.height;
        if (imgWidth == 0)
        {
            img.width = width;
        }
        if (imgHeight == 0) {

            img.height = height;
        }
        if (imgWidth > width && imgHeight > height) {
            //both image's width and height are larger than required one
            var widthRate = imgWidth / width;
            var heightRate = imgHeight / height;
            if (widthRate > heightRate) {
                //use width to retrieve the image
                img.width = width;
                img.height = imgHeight * (width / imgWidth);
            } else {
                img.height = height;
                img.width = imgWidth * (height / imgHeight);
            }
        }
        else if (imgWidth > width) {
            //the image width lg than the required width
            img.width = width;
            img.height = imgHeight * (width / imgWidth);
        }
        else if (imgHeight > height) {
            //the image height lg than the required
            img.height = height;
            img.width = imgWidth * (height / imgHeight);
        }
    }
}

function replaceNum(myinput, token, newstr)
{
    var input = myinput;
    var output = input;
    var idx = output.indexOf(token);
    if (idx > -1)
	{
		output = input.substring(0, idx);
		output += newstr;
		output += input.substr(idx+token.length);
    }
    return output;
}

function preloadRange(intPic,intRange) {
	var divStr = "";

	for (var i=intPic; i<intPic+intRange&&i<numImgs; i++) {
		arrPreload[i] = new Image();
		arrPreload[i].src = imageSrcArray[i];
	}

	var strIn = "";
	var k = 0;
	for (i=intPic; i<intPic+intRange; i++) {
		j = i;
		var strA = "";
		var nextImg = curImg;
		if(j<numImgs && j>=0){
			strA = "<td width=\"80\"><table border=\"0\" cellspacing=\"2\" "+GetBorder(j,curImg)+"><tr><td align=center>"+
			"<a href='product.asp?ID=102'><img id="+j+" width="+_PREVIEW_WIDTH+" height=139 border=0 src='"+
			imageLittleSrcArray[j]+"'></a></td></tr></table></td>";
		}
 		divStr += strA;
	}
	document.getElementById("div1").innerHTML = "<table><tr>"+divStr+"</tr></table>";
	return true;
}

function GetBorder(i,j)
{
	if(i==j)  return " bgcolor=\"#FFCC00\" ";
	return " bgcolor=\"#FFFFFF\" onmouseover=\"this.style.backgroundColor='#ffcc00'\" onmouseout=\"this.style.backgroundColor=''\"";

}

function navforward()
{
    firstframeindex++;
    if(firstframeindex>numImgs-_PRELOADRANGE)  firstframeindex = numImgs-_PRELOADRANGE;
    if(firstframeindex<0)  firstframeindex=0;
    preloadRange(firstframeindex,_PRELOADRANGE);
}

function navrewind()
{
    firstframeindex--;
    if(firstframeindex<0)  firstframeindex=0;
    preloadRange(firstframeindex,_PRELOADRANGE);
}

function initalbum(photo)
{
    imageSrcArray = new Array();
    imageLittleSrcArray = new Array();
    imageNameArray =new Array();
	imageContentArray =new Array();
	//begImg = 0;
    numImgs=0
	if(photo==null)  return;
    numImgs = photo.length;
	for(i=0;i<photo.length;i++){
        imageSrcArray[i] = photo[i].url
        imageLittleSrcArray[i] = photo[i].littleUrl
        imageNameArray[i] = photo[i].name
		imageContentArray[i] = photo[i].content
	}

	curImg = begImg;
	firstframeindex = curImg-Math.floor((_PRELOADRANGE-1)/2);
    if (curImg < 0 || curImg > numImgs - 1)
    	  curImg = numImgs - 1;
	
}

/********************ajax operations******************************/
function UFolderesView(){
	this.onrefresh = function(infoes){
		global["albuminfolist"] = infoes;
		procPoint('albumslideshow', 'mainpoint', global);
	}
	this.onchange = function(item){}
	this.ondelete = function(item){}
}
var uFolderes = new InfoData();
uFolderes.register(new UFolderesView());
function cAlbumBackParam(stask){
	global.album_currentid = parseInt(stask.pop());
	begImg = parseInt(stask.pop());
}
function procAlbumShowFolder(id,beginid,folderid){
		var ajax = new AjaxWrap(null);
		ajax.openText("getalbumfolder.do?uid=" + id+"&beginid=" + beginid+"&folderid=" + folderid, true);
}
