﻿var oldfn = window.onload;
if(typeof window.onload != 'function')
{
	window.onload = loadAlbum;
} else {
	window.onload = function()
	{
		oldfn();
		loadAlbum();
	};
}
function loadAlbum(){
    var anchors = document.getElementsByTagName("a");
    
    // loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		
		var relAttribute = String(anchor.getAttribute('rel'));
		
		// use the string.match() method to catch 'lightbox' references in the rel attribute
		if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('photos'))){
			anchor.href = "javascript:openPhoto('" + anchor.id + "','" + anchor.className + "','" + anchor.getAttribute('href') + "');";
		}
	}
}
function openPhoto(id, className, img)
{
    $find('ModalBehavior').show();
    var i = $get('ctl00_ContentPlaceHolder1_fullImage');
    i.src = img;
    
    var anchors = document.getElementsByTagName("a");
    
    var currentAlbum = new Array();
    
    // loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		
		// use the string.match() method to catch 'lightbox' references in the rel attribute
		if (anchor.getAttribute('href') && (anchor.className.match(className)) ){
		    currentAlbum.push(anchors[i].id);
		}
	}

	for(var i=0; i<currentAlbum.length; i++){
        if(currentAlbum[i] == id)
	    {
	        if(i>0)
	        {
	            $get('previousPhoto').setAttribute('href',$get(currentAlbum[i-1]).getAttribute('href'));
	        }
    	    
	        if(i < currentAlbum.length)
	        {
	            $get('nextPhoto').setAttribute('href',$get(currentAlbum[i+1]).getAttribute('href'));
	        }
	    }
	}
}
function resetNavLink()
{
    $get('ctl00_ContentPlaceHolder1_fullImage').src = '';
    $get('previousPhoto').setAttribute('href','javascript:void(0);');
    $get('nextPhoto').setAttribute('href','javascript:void(0);');
}
