$(document).ready(function()
	{ // when html is loaded
	setTall();
	setGallery();
	});

function setTall()
	{
	var leftcontent = $('#leftcontent');
	var leftcontentOuterHeight = leftcontent.outerHeight(true);
	var leftcontentPadEtc = leftcontentOuterHeight - leftcontent.height();

	var rightcol = $('#rightcol');
	rightcolOuterHeight = 0;
	if (rightcol != null)
		rightcolOuterHeight = rightcol.outerHeight(true);

	var rightcontent = $('#rightcontent');
	var rightcontentOuterHeight = 0;
	var rightcontentPadEtc = 0;
	if (rightcontent != null)
		{
		rightcontentOuterHeight = rightcontent.outerHeight(true);
		rightcontentPadEtc = rightcontentOuterHeight - rightcontent.height();
		}

	var gallery = $('#gallery');
	galleryOuterHeight = 0;
	if (gallery != null)
		galleryOuterHeight = gallery.outerHeight(true);

	var maxHeight = Math.max(leftcontentOuterHeight, rightcolOuterHeight + 10);
//alert(leftcontentOuterHeight+" "+rightcolOuterHeight+" "+rightcontentOuterHeight+" "+galleryOuterHeight+" "+maxHeight);
	leftcontent.height(maxHeight - leftcontentPadEtc);
	rightcontent.height(maxHeight - galleryOuterHeight - rightcontentPadEtc - 10);
	}

function setGallery()
	{
	var largeimage = $('#gallery').find('img');
	$('#thumbnail a').each(function()
		{
		var src = $(this).find('img').attr('src').replace(/thumbnail/, 'image');
		jQuery("<img>").attr('src', src);
		$(this).mouseover(function()
			{
			$(this).fadeTo(0, .8);
			largeimage.attr('src', src);
			});
		$(this).mouseout(function()
			{
			$(this).fadeTo(0, 1);
			});
		});
	}

function showOrder()
	{
	window.name='origin';
	var w = window.open('','order',
		'width=500,height=400,resizable,scrollbars,status,top=10,left=10');
	w.document.clear();
	w.focus();
	return true;
	}
function showProduct(pic)
	{
	var w = window.open('', 'product', 'width=350,height=400,resizable,scrollbars,top=20,left=30');
	var d = w.document;
	d.write('<html><head><title>Simplycrafts close up</title></head><body bgcolor="white" leftmargin="6" topmargin="6">');
	d.write('<center><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center">');
	d.write('<img src="/products/largeimages/' + pic + '">');
	d.write('</td></tr><tr><td align="center"><form>');
	d.write('<input type="button" value="Close this window" onClick="window.close();">');
	d.write('</form></td></tr></table></center></body></html>');
	d.close();
	w.focus();
	return false;
	}
function showWin()
  {
  var w = window.open('','popup',
      'width=500,height=400,resizable,scrollbars,status,left=80,top=80');
  w.document.clear();
  w.focus();
  return true;
  }
function showSearch()
	{
	window.name='origin';
	var w = window.open('','search',
		'width=250,height=550,resizable,scrollbars,status,top=0,left=0');
	w.document.clear();
	w.focus();
	return true;
	}

function mailIt()
	{
  var email = "info"
  var emailHost = "hrbt.com.au"
  document.write("<a href=" + "mail" + "to:" + email + "@" + emailHost + ">(Click here)</a>")
	}

addDOMLoadEvent = (function()
	{
	// create event function stack
	var load_events = [],
		load_timer,
		script,
		done,
		exec,
		old_onload,
		init = function ()
			{
			done = true;
			// kill the timer
			clearInterval(load_timer);
			// execute each function in the stack in the order they were added
			while (exec = load_events.shift())
				exec();
			if (script)
				script.onreadystatechange = '';
			};
	return function (func)
		{
		// if the init function was already ran, just run this function now and stop
		if (done)
			return func();
		if (!load_events[0])
			{
			// for Mozilla/Opera9
			if (document.addEventListener)
				document.addEventListener("DOMContentLoaded", init, false);
			// for Internet Explorer
			/*@cc_on @*/
			/*@if (@_win32)
			document.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");
			script = document.getElementById("__ie_onload");
			script.onreadystatechange = function()
				{
				if (this.readyState == "complete")
					init(); // call the onload handler
				};
			/*@end @*/
			// for Safari
			if (/WebKit/i.test(navigator.userAgent))
				{ // sniff
				load_timer = setInterval(function()
					{
					if (/loaded|complete/.test(document.readyState))
						init(); // call the onload handler
					}, 10);
				}
			// for other browsers set the window.onload, but also execute the old window.onload
			old_onload = window.onload;
			window.onload = function()
				{
				init();
				if (old_onload)
					old_onload();
				};
			}

		load_events.push(func);
		}
	})();
