/*
    File: photoviewer.js
	Author: Peter Foran
	Purpose: Contains functionality for the javascript image viewer on client sites
	Created: 10 November 2007
*/

var targetWindow = '';
var ExternalPictureWindow = function(href, width, height) {
    var window_target = 'ExternalPictureWindow';
    var winleft = (screen.width - width) / 2;
    var wintop = (screen.height - height) / 2;

    if (!targetWindow.closed && targetWindow.location) {
        targetWindow.location.href = href;
    }
    else {
        targetWindow = window.open(href, window_target, "height=" + height + ",width=" + width + ",left=" + winleft + ",top=" + wintop + ",scrollbars=yes");
        if (!targetWindow.opener) targetWindow.opener = self;
    }
    targetWindow.focus();
}

function getElementBy(elemTag){
	var elem = document.getElementById (elemTag);
	if (elem)
		return elem;
	var elems = document.getElementsByName (elemTag);
	if (elems.length > 0)
		return elems[0];
	return null;
}

var lastImageShown = 0;
var blnPlaySlideShow = true;

function ImgChange(imgNumber)
{
    document.getElementById('lblCurrentImage').innerHTML = '' + imgNumber + '';
    lastImageShown = imgNumber;
	
    if (document.all){
        document.images['ImageFull'].style.filter='blendTrans(duration=2)';
        document.images['ImageFull'].style.filter='blendTrans(duration=crossFadeDuration)';
        document.images['ImageFull'].filters.blendTrans.Apply();
    }
    
    document.images['ImageFull'].src = eval('ImageFull' + imgNumber + ".src");
    
    if (document.all)
        document.images['ImageFull'].filters.blendTrans.Play();
}

function ImgPlay()
{
	blnPlaySlideShow = true;
	ImgChangeNext(true);
}

function ImgStop()
{
	blnPlaySlideShow = false;
}

function ImgTogglePlayStop()
{
	if(document.getElementById("btnPlay").value == "Stop")
	{
        ImgStop();
	    document.getElementById("btnPlay").value = "Play";
	}
	else
	{
	    ImgPlay();
	    document.getElementById("btnPlay").value = "Stop";
	}
}

function ImgChangeNext(blnAuto)
{
	if(blnAuto == false || (blnAuto == true && blnPlaySlideShow == true))
	{
	    var i = lastImageShown + 1;
	    if(i > imageCount)
	        i = 1;
    	    
	    ImgChange(i);
	    showPhotoDesc(i); //added this hoping it will update the description
	}
	
	if(blnAuto == true && blnPlaySlideShow == true)
	    setTimeout("ImgChangeNext(true)", 4000); //<`-- The number here is the # of milliseconds to wait before changing to the next photo
}

function ImgChangePrev()
{
	var i = lastImageShown - 1;
	if(i < 1)
	    i = imageCount;
	    
	ImgChange(i);
}

function showPhotoDesc(i) {
	if(photoDescArray[i] != undefined && photoDescArray[i].length > 0)
		getElementBy('photoDesc').innerHTML = photoDescArray[i];
	else
		getElementBy('photoDesc').innerHTML = "";
}

//configure menu width (in px):
var menuwidth='278';
//configure menu height (in px):
var menuheight='52';
//configure scroll speed (1-10), where larger is faster
var scrollspeed=6

//=============================
//BEGIN propertyphotoscroll.js

var cross_scroll;
var ns_scroll;
var loadedyes = 1;
var righttime;
var lefttime;

function moveleft(){
	cross_scroll=document.getElementById? document.getElementById("thumblist") : document.all.thumblist;

	if (loadedyes == 1 && cross_scroll.offsetLeft > (menuwidth - cross_scroll.offsetWidth))
		cross_scroll.style.left = cross_scroll.offsetLeft - scrollspeed+"px";
	lefttime=setTimeout("moveleft();",50);
}

function moveright(){
	cross_scroll=document.getElementById? document.getElementById("thumblist") : document.all.thumblist;

	if (loadedyes == 1 && cross_scroll.offsetLeft < 0)
		cross_scroll.style.left = cross_scroll.offsetLeft + scrollspeed+"px";
	righttime=setTimeout("moveright();",50);
}








