$(document).ready(function() {
    var tabContainers = $('div#menu-nav > div');
    $('div#menu-nav ul.css-tabs a').click(function () {

        $('div#menu-nav ul.css-tabs a').removeClass('current');
        $(this).addClass('current');

    });
});

/* Gallery */
var initLightBox = function() {
	$('.gallery').each(function() {
		$(this).append('<ul></ul>');

		var albumInfo = eval('(' + $(this).attr('rel') + ')');

		for (i=1; i<=albumInfo.total; i++) {
			var html = '<li' + ((i==1) ? ' style="display:inline;"' : '') + '><a href="photos/' + $(this).attr('id') + '/image' + i + '.jpg" title=""><img src="photos/' + $(this).attr('id') + '/thumb_image' + i + '.jpg" width="125" height="125" alt="" /><br />' + albumInfo.title + '</a></li>';
			$(this).find('ul').append(html);
		}
		$(this).find('a').lightBox();
	});
}

// Loads the Gallery -----------------------------------[TN]
var loadGallery = function(galleryPage) {
	$('.galleryThumbs').load(galleryPage, function() {
		initLightBox();
	});
}
//------------------------------------------------------[TN]

$(function() {
	// Load First Gallery on Page Load ---------------------[TN]
	loadGallery('press-1.html');
	//------------------------------------------------------[TN]

	// Add Event Listener to Pagination Links --------------[TN]
	$('.pagination ul li a').click(function() {
		// Get The Gallery Number From the rel attribute -------[TN]
		var galleryNumber = $(this).attr('rel');
		//------------------------------------------------------[TN]

		if (galleryNumber == 'previous' || galleryNumber == 'next') {
			//------------------------------------------------------[TN]
			// The link clicked is prev/next and doesn't have a numerical
			//	rel value, so, we need to find the current page and
			//	add or subtract or return false if the button is disabled
			//------------------------------------------------------[TN]
			if ($(this).hasClass('disablelink'))
				return(false);

			currentPage = $('.pagination ul li a[class=currentpage]').attr('rel');

			if (galleryNumber == 'previous')
				galleryNumber = currentPage - 1;
			else
				galleryNumber = currentPage * 1 + 1;
		}

		// Load the Gallery that was clicked -------------------[TN]
		loadGallery('press-' + galleryNumber + '.html');
		//------------------------------------------------------[TN]

		// Update the Pagination Link states -------------------[TN]
		$('.pagination ul li a').removeClass('currentpage');

		if ($(this).attr('rel') != 'previous' && $(this).attr('rel') != 'next')
			$(this).addClass('currentpage');
		else
			$('.pagination ul li a[rel=' + galleryNumber + ']').addClass('currentpage');

		$('.prevnext').removeClass('disablelink');

		if ($('.currentpage').attr('rel') == $('.pagination ul li a').length - 2)
			$('.pagination ul li a[rel=next]').addClass('disablelink');
		else if ($('.currentpage').attr('rel') == 1)
			$('.pagination ul li a[rel=previous]').addClass('disablelink');
		//------------------------------------------------------[TN]

		return(false);
	});
	//------------------------------------------------------[TN]
});
