/* Called in the onload event for all pages. */
function init() {
	activateMenu();
}

/* Inserts the products flash with the correct height and width for the current browser. */
function insertProducts(category) {
	/* Defaults */
	var height = 85;
	var width = 765;
	var bgcolor = '#FFFFFF';
	
	/* Override for Explorer < 7 */
	if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) {
		width = 760;
	/* Override for Safari */
	} else if (BrowserDetect.browser == 'Safari') {
		width = 768;
	}
	
	/* Set the background color based on the category selected. */
	switch(category) {
		case 'earthenware':
			bgcolor = '#CCCCCC';
			break;
		
		case 'domesticware':
			bgcolor = '#DDDDDD';
			break;
		
		case 'art':
			bgcolor = '#EEEEEE';
			break;
		
		default:
			alert('Unknown category provided to insertProducts(): ' + category);
			break;
	}
	
	/* Insert the movie */
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + String(width) + '" height="' + String(height) + '" id="products" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain">');
	document.write('<param name="movie" value="flash/' + category + '.swf">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="bgcolor" value="' + bgcolor + '">');
	document.write('<embed src="flash/' + category + '.swf" quality="high" bgcolor="' + bgcolor + '" width="' + String(width) + '" height="' + String(height) + '" name="products" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
	document.write('</object>');
}

/* Sets the appropriate events for each menu item. */
function activateMenu() {
	$('logo').onclick = function(node) {
		document.location.href = 'index.asp';
	}
	
	$A($('nav').childNodes).each(function(node) {
		/* Go to the specified page on a click. */
		node.onclick = function(el) {
			document.location.href = node.getAttribute('href');
		}
		
		/* Add the 'hover' class on mouse over. */
		node.onmouseover = function(el) {
			Element.addClassName(node, 'hover');
		}
		
		/* Remove the 'hover' class on mouse out. */
		node.onmouseout = function(el) {
			Element.removeClassName(node, 'hover');
		}
	});
}

/* Selects a different category in the products list. */
function selectCategory(id) {
	var new_url;
	document.location.href = 'studio.asp?category=' + String(id);
}