/*------------------------------------------------------------------------------
Popup window control
------------------------------------------------------------------------------*/
function openPictureWindow(myPath) {
    myWindow = window.open(myPath, "myPopUp", "width=595,height=450");
    myWindow.focus();
}
/*------------------------------------------------------------------------------
Image preloading functions - for photo browser

Checking the 'complete' property of an image seems unreliable unless it is
rendered to the screen. So this little lot places hidden images at the bottom
of the page and then checks them for being complete.
When they are, it removes the 'images are loading' message.
------------------------------------------------------------------------------*/
loadingMsg="Images are loading and may take a moment to display";

function checkImages() {
    for (i=0;i<document.images.length;i++) {
        if (!document.images[i].complete) {
            return false
        }
    }
    return true
}

function checkLoaded() {
    if (!checkImages()) {
        setTimeout("checkLoaded()",200);
    } else {
        MM_setTextOfLayer('loadingMsg','','');
    }
}
function initImages() {
    for(i=1; i<=totalPics; i++) {
        document.write('<div style="display: none"><img src="../photos/'+mySection+'_'+[i]+'.jpg"></div>');
    }
	MM_setTextOfLayer('clickLoad','',loadingMsg);
    checkLoaded();
}
/*------------------------------------------------------------------------------
Menu functions
------------------------------------------------------------------------------*/
var menuTimer, currentMenu;

function pageLink(myUrl,mySection) {
    parent.main.location.href= myUrl;
    swapTitle(mySection)
}

function swapTitle(mySection) {
    if(currentMenu) {
		hideMenu();
	}
    MM_swapImage('titleImg','',('images/title_'+mySection+'.gif'));
}


function showMenu(subMenu) {
	// stop current menu activities
	if (menuTimer) {
		stopTimer();
	}
	if(currentMenu) {
		hideMenu();
	}

	MM_showHideLayers(subMenu,'','show');
	// log status
	currentMenu = subMenu;
}

function hideMenu() {
	// hide submenu
	MM_showHideLayers(currentMenu,'','hide');
}

function startTimer(myImg,subMenu) {
	menuTimer=setTimeout("hideMenu()",200)
}

function stopTimer() {
	clearTimeout(menuTimer)
	menuTimer = null;
}

/*------------------------------------------------------------------------------
Page scroller functions
------------------------------------------------------------------------------*/

// set frame to scroll
var myFrame = parent.gallery;

// initialise
var scrollLog = 0;
var amOver = false;

// handle mouseover
function doJsScroll(howMuch) {
    amOver = true;
	scrollLog = howMuch;
	myScroll();
}

// handle mouseout
function endScroll() {
    amOver = false;
}

// the scroller
function myScroll() {
    // move frame
    myFrame.scrollBy(scrollLog,0);

    // move again if mouse is over
    if (amOver) {
        setTimeout('myScroll()',10);
    }
}
