addLoadEvent( checkFrames );
addLoadEvent( initDeleteItem );
addLoadEvent( highlightThumb );



function keyLeft()
{
	var prevPage = Nav.getPrevPage();
	var url      = prevPage.match( /(\w+\.php)\D+(\d+)/ );
	if ( url != null && url[1] == 'frame.php' ) {
		changeFrames( url[2] );
	}
	else {
		top.location.href = prevPage;
	}
}



function keyRight()
{
	var nextPage = Nav.getNextPage();
	var url      = nextPage.match( /(\w+\.php)\D+(\d+)/ );
	if ( url != null && url[1] == 'frame.php' ) {
		changeFrames( url[2] );
	}
	else {
		top.location.href = nextPage;
	}	
}



function changeFrames( catId )
{
	top.frames['main'].location.href   = top.frames['main'].location.pathname + '?catId=' + catId;
	top.frames['thumbs'].location.href = top.frames['thumbs'].location.pathname + '?catId=' + catId;
}



Navigation.prototype.noWhiteFlash = function()
{
	var navLinks = this.mainNav.getElementsByTagName( 'A' );
	for ( var i = 0; i < navLinks.length; i++ ) {
		navLinks[i].onclick = function() {
			try {
				var dest = this.parentNode.getElementsByTagName( 'LI' )[0].firstChild; // First subCat
			}
			catch( e ) {
				var dest = this;
			}
			if ( dest.href.indexOf('frame.php') != -1 ) {
				// Destination is a photo page
				top.document.title = dest.innerHTML;
				var catId = dest.href.match( /catId=(\d+)/ )[1];
				changeFrames( catId );
				return false;
			}
		}
	}
}



function initDeleteItem()
{
	var itemDelete = document.getElementById( 'itemDelete' );
	if ( itemDelete ) {
		itemDelete.disabled    = false;
		itemDelete.style.color = '#f00';
		itemDelete.onclick = function() {
			var msg = translate( 'Deze foto wissen?' );
			if ( confirm(msg) ) {
				top.location.href = '/frame.php?catId=' + catId + '&itemId=' + itemId + '&deleteItem=1';
			}
		}
	}
}
	


function highlightThumb()
{
	try {
		var thumbsFrame = top.frames['thumbs'];
		if ( !thumbsFrame || thumbsFrame.imgs.length <= 1 ) {
			return;
		}
	}
	catch( e ) {
		// thumbsFrame not fully loaded yet, try again later
		setTimeout( 'highlightThumb()', 1000 );
		return;
	}
	
	var curThumb = thumbsFrame.curThumb;
	var defaultClass;
	
	if ( curThumb ) {
		// Reset class to default
		defaultClass = thumbsFrame.lookup[curThumb].className.replace( /\s?curThumb/, '' );
		thumbsFrame.lookup[curThumb].className = defaultClass;
	}
	
	// Store value of itemId so that class 'curThumb' can be removed later
	thumbsFrame.curThumb = itemId;
	
	if ( thumbsFrame.lookup ) {
		// Assign class 'curThumb'
		thumbsFrame.lookup[itemId].className += ' curThumb';
	}
	
}