//$Id: global.js,v 1.1.1.1 2009/02/25 20:47:26 nick Exp $

Photo = function(iPos,iId,sTitle,sCaption,iWidth,iHeight,sUrlFull,sUrlVideo,bIsVideo,sDateTaken)
{
	this.id=iId;
	this.sTitle=sTitle;
	this.sCaption=sCaption;
	this.iWidth=iWidth;
	this.iHeight=iHeight;
	this.sUrlFull=sUrlFull;
	this.sUrlVideo=sUrlVideo;
	this.bIsVideo=bIsVideo;
	this.pImage=null;
}

function showPhoto(iPos)
{
	iNumPhotos = gaPhotos.length;
	iPos = (iPos + iNumPhotos) % iNumPhotos;
	giPos = iPos;
	photo = gaPhotos[giPos];

	aSize = scalePhoto(photo);
	w=aSize[0];
	h=aSize[1];

	iNextPos = (iPos + 1 + iNumPhotos) % iNumPhotos;
	var sLoader = "http://dev.83degrees.com/pwLoader.php?action=show&video="+photo.bIsVideo+"&videoUrl="+
		encodeURIComponent(photo.sUrlVideo)+"&h="+ h +"&w="+ w +"&url="+encodeURIComponent(photo.sUrlFull)+
		"&nextUrl="+gaPhotos[iNextPos].sUrlFull;
	getEl('loaderDiv').src = sLoader;
	getEl('photoDiv').style.height = getWinHeight()+'px';

	var sTitleHtml = "<div class='small left'>"+photo.sTitle + "</div>";
	sTitleHtml += "<div class='smallest left'>"+photo.sCaption+"</div>";
	sTitleHtml += "<div class='smallest left textLight'>Photo "+(iPos+1)+" of "+gaPhotos.length+"</div>";

	getEl('titleDiv').innerHTML = sTitleHtml;
}

function scalePhoto(photo)
{
	var w = photo.iWidth;
	var h = photo.iHeight;

	maxW = getWinWidth()-190;
	maxH = getWinHeight()-20;

	scaleW = maxW/w;
	scaleH = maxH/h;

	var scale = Math.min(scaleW, scaleH);
	if (scale > 1)
		scale=1;

	w = Math.round(w * scale);
	h = Math.round(h * scale);
	return new Array(w,h);
}

function  fullScreen(url)
{
	window.open(url,'',
		'height='+screen.height+', width='+screen.width+', toolbar=no, scrollbars=no, resizable=yes, status=no, copyhistory=no, location=no, menubar=no');
	return false;
}

function processReqChange()
{
	// only if req shows "loaded"
    if (req.readyState == 4)
    {
        if (req.status == 200) // only if "OK"
        {
        	str = req.responseText;
//alert(str);
//alert(gaLastRequest['reaction']);
        	if (gaLastRequest['reaction'] && gaLastRequest['reaction'].length)
        		eval(gaLastRequest['reaction']);
        	else
        		eval(str);
        }
        else
            alert("There was a problem retrieving the data:" + req.statusText);
    }
}

