// JavaScript Document

// Assign frameset document URL and default content frame document
var defaultFramesetURL = "/catalog/press/item.aspx";
var defaultMSPFramesetURL = "/press_specialty/default.htm";
var defaultContentURL = "/catalog/press_cards/holiday/thumbs1.aspx";
var frameHeight = 710;
var altFrameHeight = 1695;

// Function for viewing an enlargement of the current image.
function viewGC(thumbimg) {
	var lgimg = document.getElementById("lgimg");
	if (lgimg && thumbimg) lgimg.src = thumbimg.src.replace('/smthumb/', '/full/');
}

// Function for viewing an enlargement of the current image.
function viewGCFlat(mode) {
	var lgimg = document.getElementById("lgimg");
	if (lgimg) {
		lgimg.src = lgimg.src.replace(/(front|back)/, mode);
	}
}

// Sets up greeting card thumbnail onclick events and preload enlargements
function setupGCThumbs() {
	var container = document.getElementById("GCThumbs");
	if (container) {
		var imgs = container.getElementsByTagName("img");
		if (imgs.length > 0) {
			for (var x = 0; x < imgs.length; x++) {
				// Preload enlargement of the current thumbnail
				var lgimg = imgs[x].src.replace('/smthumb/', '/full/');
				(new Image()).src = lgimg;
				// Set style and onclick method
				imgs[x].style.cursor = 'pointer';
				imgs[x].onclick = function() { viewGC(this); }
			}
		}
	}
}

// Sets up greeting card view buttons to toggle view modes
function setupGCViewButtons() {
	var container = document.getElementById("GCButtons");
	if (container) {
		var links = container.getElementsByTagName("a");
		if (links.length > 0) {
			for (var x = 0; x < links.length; x++) {
				links[x].onclick = function() { toggleButtons(this, container); }
			}
		}
	}
}

// Function to toggle view buttons when one is clicked
function toggleButtons(elem, container) {
	// Get all of the links in the current container and set the appropriate up/down states
	var links = container.getElementsByTagName("a");
	for (var x=0; x < links.length; x++) {
		if (links[x].className.indexOf("left") != -1) links[x].className = 'left';
		else if (links[x].className.indexOf("mid") != -1) links[x].className = 'mid';
		else if (links[x].className.indexOf("right") != -1) links[x].className = 'right';
	}
	elem.className = elem.className + '-hit';
}

// Switches view modes for thumbnails
function viewThumbs(mode) {
	// Get the thumbnail nodes
	var horiz = document.getElementById("horiz");
	var verti = document.getElementById("verti");
	var square = document.getElementById("square");
	switch (mode) {
		case "h":
			if (horiz) horiz.style.display = '';
			if (verti) verti.style.display = 'none';
			if (square) square.style.display = 'none';
			break;
		case "v":
			if (horiz) horiz.style.display = 'none';
			if (verti) verti.style.display = '';
			if (square) square.style.display = 'none';
			break;
		case "s":
			if (horiz) horiz.style.display = 'none';
			if (verti) verti.style.display = 'none';
			if (square) square.style.display = '';
			break;
	}
}

// Press OnLoad directive
function pressOnLoad() {
	setupGCThumbs();
	setupGCViewButtons();
}

if (window.addEventListener) window.addEventListener("load", pressOnLoad, false);
else if (window.attachEvent) window.attachEvent("onload", pressOnLoad);