var galleryTabs;
var galleryThumbs;
var section;

function initialize()
{	
	// home gallery tabs
	if($('gallerytabs'))
	{
		galleryTabs = $$('#gallerytabs .tabs li');
		galleryTabs.each(function(tab) {
			tab.observe('click', function(e) {
				e.stop();
				selectGalleryByTab(Event.element(e).ancestors()[0]);
			});
		});
		
		galleryThumbs = $$('#gallerytabs .thumbs');
		/*
		var thumbsIndex;
		galleryThumbs.each(function(thumbs) {
			thumbsindex = galleryThumbs.indexOf(thumbs);
			$A(thumbs.getElementsByTagName('a')).each(function(thumb) {
				thumb.writeAttribute("rel", "lightbox[set" + thumbsindex + "]");
			});
		});
		*/
		$('galleryloader').hide();
		loadFirstThumbs();
	}
}

function selectGalleryByTab(aTab)
{
	galleryTabs.each(function(tab) {
		tab.className = (aTab == tab ? 'selected' : '');
	});
	galleryThumbs.each(function(thumbs) {
		thumbs.hide();
		if(galleryThumbs.indexOf(thumbs) == galleryTabs.indexOf(aTab)) thumbs.appear();
	});
}

function selectGalleryByIndex(aIndex)
{
	galleryTabs.each(function(tab) {
		tab.className = (tab.id == 'gallerytab' + aIndex ? 'selected' : '');
	});
	galleryThumbs.each(function(thumbs) {
		thumbs.hide();
		if(thumbs.id == 'gallerythumbs' + aIndex) thumbs.appear();
	});
}

function loadFirstThumbs()
{
	section = parseInt(window.location.hash.substring(1));
	if(section >= 0) {
		selectGalleryByIndex(section);
	} else {
		selectGalleryByTab(galleryTabs[0]);
	}
}

Event.observe(window, 'load', initialize);