var tag;
var section;

$(document).ready(function(){
	var gallery_button_graphics = ['../images/double_arrow_left.png', '../images/double_arrow_right.png', '../images/button_double_arrow.png'];
	$.each(gallery_button_graphics, function()
	{	// Proload the image
		var preloader = new Image();
		preloader.onload = function() {
			preloader.onload = null;
			preloader = null;
		};	preloader.src = this;
	});
	$('#signs').addClass('left');
	$('#indigo').addClass('right');
	$('#products_gallery').append('<div id="signsInformation"><img class="left" src="images/double_arrow_left.png" alt="arrows pointing left at sign products" /><img class="right" src="images/double_arrow_right.png" alt="arrows pointing right at print products" /><h3 class="center first">Choose A Product</h3><p class="center">Select a sign or print product to learn more.</p></div>');
	jQuery.each($('#signs dd, #indigo dd'), function () {
		$(this).hide();
	});
	
	jQuery.each($('#signs dt, #indigo dt'), function () {
		this.style.cursor = 'pointer';
		$(this).bind('click', function () {
			$.Lightbox = new $.LightboxClass();
			section = this.parentNode.parentNode.id;
			tag = this.parentNode.id;
			$('#signsInformation').fadeOut('normal', function () {
				loadTagInfo();
			});
		});
	});
});

loadTagInfo = function () {
	$('#products_gallery').append('<div id="galleryContainer"></div>');
	$('#galleryContainer').hide();
	loadTagInfo = function () {
		var current = '#'+section+' #'+tag+' dt';
		$('#signsInformation').empty();
		$('#signsInformation').append('<h3 class="center">'+$(current).html()+'</h3>');
		$(current).siblings('dd').children().clone().appendTo('#signsInformation');
		
		var uri = '/includes/Lightboxml.ajax.php'
		var sentData = 'section='+section+'&tag='+tag;
		//alert(sentData);
		// $('#galleryContainer').load(uri, function () {
			// if (!$('#galleryContainer').children().hasClass('error')) {
				// $('#galleryContainer a').lightbox();
				// if(!$('#signsInformation').children().is('.blue_button')) {
					// $('#signsInformation').append('<a class="blue_button center" href="javascript:;">View Gallery</a>');
					// $('#signsInformation .blue_button').bind('click', function () {
						// $('#galleryContainer a:first').trigger('click');
					// });
				// }
			// }
		// });
		$.ajax({
			url: uri,
			data: sentData,
			dataType: 'html',
			beforeSend: function () {
				$('#signsInformation').append('<img class="external_lb_loading" src="../images/loading.gif">');
			},
			success: function (external_lb) {
				$('#galleryContainer').empty();
				$('#galleryContainer').append(external_lb);
				$(".external_lb_loading").fadeOut();
				$(".external_lb_loading").remove();
			},
			complete: function (XMLHttpRequest, textStatus) {
				if (!$('#galleryContainer').children().hasClass('error')) {
					$('#galleryContainer a').lightbox();
					$('#signsInformation .blue_button').remove();
					$('#signsInformation').append('<a class="blue_button center" href="javascript:;">View Gallery</a>');
					$('#signsInformation .blue_button').bind('click', function () {
						$('#galleryContainer a:first').trigger('click');
					});
					//}
				}
			}
		});
		$('#signsInformation').fadeIn();
	}
	loadTagInfo();
}