var hideDelay = 10;
var hGap = 0;
$(document).ready(function()
	{ // when html is loaded
	$('div.popmenu').popMenu();
	//setTall();
	setTimeout(function()
		{
		setTall();
		}, 2000);
	//search box watermark
$('.searchbox').watermark('Search');
	//when the user is in the textbox if the value is Search  
	//clear it. If any other text is entered it will be ignored  
//	$('.searchbox').focus(function()
//		{    
//		$(this).filter(function()
//			{    
//			return $(this).val() == 'Search'    
//			}).val("");  
//		});  
	//when the user exits the search box check to see if the value  
	//is blank. If it is then put the word Search back in there.  
//	$('.searchbox').blur(function()
//		{    
//		$(this).filter(function()
//			{    
//			return ($(this).val() == '');
//			}).val('Search');  
//		});   
	});

(function($)
	{
	$.fn.popMenu = function()
		{
		return this.each(function()
			{
			var self = $(this);
			self.data('hiding', false); // init timeout id
			var id = self.attr('id');
			var menuEl = $('a.'+id); // menu link class = dropdown id
			// position under menu link; using offsetHeight because height() seems to give the link's non block height
			var pos = menuEl.offset();
			var height = menuEl.attr('offsetHeight');
			if (typeof(height) == "undefined")
				return;
			self.css({'left': (pos.left+hGap)+'px', 'top': (pos.top + height)+'px'});
			// apply hover (mouseover, mouseout) to both menu link and dropdown.
			$.each([self, menuEl], function()
				{
				$(this).hover(
					function()
						{
						if (self.data('hiding'))
							{
							clearTimeout(self.data('hiding'));
							self.data('hiding', false);
							}
var pos = menuEl.offset();
var height = menuEl.attr('offsetHeight');
self.css({'left': (pos.left+hGap)+'px', 'top': (pos.top + height)+'px'});
						$('div#'+id).show();
						menuEl.addClass('popped');
						},
					function()
						{ // delay hide so if the pointer passes between the menu and dropdown the hide can be cancelled
						self.data('hiding', setTimeout(function()
							{
							menuEl.removeClass('popped');
							$('div#'+id).hide();
							}, hideDelay));
						});
				});
			});
		}
	})(jQuery);

function setTall()
	{
	var content = $('#contentarea');
	var contentOuterHeight = content.outerHeight(true) - 10;
	var contentPadEtc = contentOuterHeight - content.height();

	var leftbar = $('#leftbar');
	var leftbarOuterHeight = leftbar.outerHeight(true);
	var leftbarPadEtc = leftbarOuterHeight - leftbar.height();

	var rightbarcontent = $('#rightbar .content');
	var rightbarcontentOuterHeight = rightbarcontent.outerHeight(true);
	var rightbarcontentPadEtc = rightbarcontentOuterHeight - rightbarcontent.height();

	var maxHeight = Math.max(contentOuterHeight, Math.max(rightbarcontentOuterHeight, leftbarOuterHeight));
	content.height(maxHeight - contentPadEtc);
	var leftbarNewHeight = maxHeight - 20;
	//if (leftbarNewHeight < leftbarOuterHeight)
	//	leftbarNewHeight = leftbarOuterHeight;
	var rightbarcontentNewHeight = maxHeight - 20;
	//if (rightbarcontentNewHeight < rightbarcontentOuterHeight)
	//	rightbarcontentNewHeight = rightbarcontentOuterHeight;
	var outerbarNewHeight = Math.max(leftbarNewHeight, rightbarcontentNewHeight);
	leftbar.height(outerbarNewHeight - leftbarPadEtc);
	rightbarcontent.height(outerbarNewHeight - rightbarcontentPadEtc);
	}

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=500,height=600,resizable,scrollbars,top=0,left=30');
	var d = w.document;
	d.write('<html><head><title>Name Badge World 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="' + 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=600,height=500,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 showPic()
  {
	//window.name='origin';
	var w = window.open('','gallery','width=400,height=400,resizable,scrollbars,status,left=0,top=0');
	w.document.clear();
	w.focus();
	return true;
	}
function checkShopBuy(formEl)
  {
	var value = formEl.quantity.value;
	if (value == "" || value == null || isNaN(value) || value < 1)
 		{
		alert("Please enter a quantity");
		return false;
		}
	return true;
	}
function initOverLabels()
	{
	if (!document.getElementById)
		return;      

	var labels, id, field;

	// Set focus and blur handlers to hide and show 
	// labels with 'overlabel' class names.
	labels = document.getElementsByTagName('label');
	for (var i = 0; i < labels.length; i++)
		{

		if (labels[i].className == 'overlabel')
			{

			// Skip labels that do not have a named association
			// with another field.
			id = labels[i].htmlFor || labels[i].getAttribute ('for');
			if (!id || !(field = document.getElementById(id)))
				{
				continue;
				} 

			// Change the applied class to hover the label 
			// over the form field.
			labels[i].className = 'overlabel-apply';

			// Hide any fields having an initial value.
			if (field.value !== '')
				{
				hideLabel(field.getAttribute('id'), true);
				}

			// Set handlers to show and hide labels.
			field.onfocus = function ()
				{
				hideLabel(this.getAttribute('id'), true);
				};
			field.onblur = function ()
				{
				if (this.value === '')
					{
					hideLabel(this.getAttribute('id'), false);
					}
				};

			// Handle clicks to label elements (for Safari).
			labels[i].onclick = function ()
				{
				var id, field;
				id = this.getAttribute('for');
				if (id && (field = document.getElementById(id)))
					{
					field.focus();
					}
				};

			}
		}
	};

function hideLabel (field_id, hide)
	{
	var field_for;
	var labels = document.getElementsByTagName('label');
	for (var i = 0; i < labels.length; i++)
		{
		field_for = labels[i].htmlFor || labels[i]. getAttribute('for');
		if (field_for == field_id)
			{
			labels[i].style.textIndent = (hide) ? '-2000px' : '0px';
			return true;
			}
		}
	}

function mailIt()
	{
  var email = "hello"
  var emailHost = "nextmarketing.com.au"
  document.write('<a href="' + 'mail' + 'to:' + email + '@' + emailHost + '?subject=Next%20Marketing%20-%20General%20Enquiry">click here</a>')
	}

