// JavaScript Document

function initThumbs() {
$$('.thumbPic').each(function(thumb) {
	
		thumb.observe('click',function(event) {
Event.stop(event);
setPic(thumb.id.sub('img',''));
		
		


			return false;
		});
		
	});

}

function initAll() {

initThumbs();


$('prevBtn').observe('click',function(event) {
Event.stop(event);
if (current > minbound) {
setPic(parseInt(current)-1);
} else {
if (current > 1) {
$('photoBoxes').update('<img src="/images/loading.gif">');

    new Ajax.Updater('photoBoxes', 'getboxes.php?album='+album+'btn=prev&photo='+(current-1),
  {
	evalScripts: true
  });
} else {
}
}

			return false;
		});

$('prevPge').observe('click',function(event) {
Event.stop(event);
if (Math.floor((current-1)/20) > 0) {
$('photoBoxes').update('<img src="/images/loading.gif">');

    new Ajax.Updater('photoBoxes', 'getboxes.php?album='+album+'btn=prev&photo='+parseInt(Math.floor((current-1)/20)*20),
  {
	evalScripts: true
  });
} else {
}

			return false;
		});

$('nextPge').observe('click',function(event) {
Event.stop(event);
if (Math.floor((current-1)/20) < Math.ceil(maxval/20)-1) {
$('photoBoxes').update('<img src="/images/loading.gif">');

    new Ajax.Updater('photoBoxes', 'getboxes.php?album='+album+'btn=prev&photo='+parseInt(((Math.floor((current-1)/20)+1)*20)+1),
  {
	evalScripts: true
  });
} else {
}
		
			return false;
		});

$('nextBtn').observe('click',function(event) {
Event.stop(event);
if (current < maxbound) {
setPic(parseInt(current)+1);
} else {
if (current < maxval) {
$('photoBoxes').update('<img src="/images/loading.gif">');
    new Ajax.Updater('photoBoxes', 'getboxes.php?album='+album+'btn=next&photo='+(current+1),
  {
	evalScripts: true

  });
  } else {

}
}
		


			return false;
		});		
}

function setPic(newPic, removePic) {

if (removePic === undefined) { removePic = true; }

if (removePic) {
$('tiny_'+current).removeClassName('tinypicsel');
		$('tiny_'+current).addClassName('tinypic');
}		
		current = parseInt(newPic);
		$('current').update(current);
		$('tiny_'+current).addClassName('tinypicsel');
		$('tiny_'+current).removeClassName('tinypic');
		
		photo = $('tiny_'+current).getAttribute('src').sub('_tiny.jpg','');
		$('main_photo').setAttribute('src',photo+'_large.jpg');


$('fb_share').setAttribute('share_url', "http://"+host+"/photography/viewalbum.php?album="+album+"&amp;photo="+current);
$('fb_share').setAttribute('href', "http://www.facebook.com/sharer.php?u=http%3A%2F%2F"+host+"%2Fphotography%2Fviewalbum.php%3Falbum%3D"+album+"%26photo%3D"+current);
$('thumbpath').value = "http://"+host+photo;
$('previewpath').value = "http://"+host+photo+'_large.jpg';
$('caption').replaceChild($('caption').firstChild,document.createTextNode($($('tiny_'+current).getAttribute('alt'));

}

Event.observe(window, 'load', function() { initAll(); });

