var currentGalleryIndex;

$(document).ready(function(){
	resizeWindow();
	removeEmptyContent("div.contentBlock ul");
	removeEmptyContent("div.contentBlock");
	removeEmptyContent("div.imageBlock");
	removeEmptyContent("div.sIFRQuote");
	removeEmptyContent("div.quoteBlock");
	$("div.contentBlock").append("<div class=\"clear\"></div>");
	initGallery();
});

function resizeWindow() {
	var positionY = 0;
	if (window.screenY) {
		positionY = window.screenY;
	}
	if (screen.width > 800) {
		window.resizeTo(995,screen.availHeight - positionY);
	} else {
		window.resizeTo(screen.availWidth,screen.availHeight - positionY);
	}
}

function removeEmptyContent(selector) {
	var emptyContent = new Array();
	emptyContent.push("");
	emptyContent.push("<p></p>");
	emptyContent.push("<p>&nbsp;</p>");
	emptyContent.push("<h3>links</h3>");
	emptyContent.push("<h3>documents</h3>");
	$(selector).each(function() {
		var htmlStr = $(this).html().toLowerCase();
		var htmlStr = jQuery.trim(htmlStr);
		for (var i in emptyContent) {
			if (htmlStr == emptyContent[i]) {
				$(this).replaceWith("");
				break;
			}
		}
	});
}

function initGallery() {
	if ($("div.galleryItem").length > 1) {
		$("a.showAll").click(function() {
			showAllItems();					  
		});
		$("a.showGallery").click(function() {
			showGallery();					  
		});
		$("a.prev").click(function() {
			currentItemIndex--;
			showGallery();					  
		});
		$("a.next").click(function() {
			currentItemIndex++;
			showGallery();	  
		});
		$("div.galleryItem:first a.prev, div.galleryItem:last a.next").hide();
		$("div.galleryNav").show();
		currentItemIndex = 0;
		showGallery();
	}
	if ($("div.galleryItem").length < 1) {
		$("div#productGallery").hide();
	}
}

function showGallery() {
	$("div.galleryItem").hide();
	$("div.galleryItem div.galleryNav").show();
	$("a.showAll").show();
	$("a.showGallery").hide();
	$("div.galleryItem:eq(" + currentItemIndex + ")").show();
}

function showAllItems() {
	$("div.galleryItem div.galleryNav").hide();
	$("a.showAll, a.showGallery").toggle();
	$("div.galleryItem").show();
}


