var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

$(document).ready(function(){

	/*Place any load code in here, functions should be built below, also below is the default calls to preload data from an EMS link, use one of these to load data into a form from EMS and ensure the value being passed matches the form name you are pre-populating
	preLoadData('testOnlineFormName');
	testPreLoadToken('testOnlineFormName');

	Here is the default code to populate errors into a error table from a querystring provided by the EMS, place this function call below the last script include, the first argument should never change, the second argument should pount to a container ID you wish to hold the error messages. The example below uses wrapper_EMSErrors
	displayOnlineFormErrorCodes("|","wrapper_EMSErrors");

	Below is code to load a flash movie using the flash loader developed by Adobe.  If you did not include the loader in your package this script will fail, so ensure it apears in the package file.  The variables below would need ot be populated with appropriate filenames and size attributes, the values below are just placeholders
	AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
		'width', '550',
		'height', '400',
		'src', 'Untitled-1',
		'quality', 'high',
		'pluginspage', 'http://www.adobe.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
		'id', 'Untitled-1',
		'bgcolor', '#ffffff',
		'name', 'Untitled-1',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', 'Untitled-1',
		'salign', ''
	);
	*/

	/*BIND EVENTS FOR THE MAIN NAV*/
	$("#nav-main > li").bind("mouseover", navmain_open);
	$("#nav-main > li").bind("mouseout",  navmain_timer);

	/*ACTIVATE THE SLIDER*/
 	$("#example").slider({
  	min:1,
  	max:6,
  	slide:function(e,ui) {
  		$("#wrapper-copy").attr("class","sliderIncrease" + ui.value);
  		$.cookie("fontsize", ui.value, { expires: 7, path: '/'});
  	}
  });

  if ($.cookie("fontsize")) {
		//alert($.cookie("fontsize"))
		if ($("#example")) {
			$("#example").slider('option','value',parseInt($.cookie("fontsize")));
			$("#wrapper-copy").attr("class","sliderIncrease" + parseInt($.cookie("fontsize")));
		}
	} else {
		$.cookie("fontsize", 2, { expires: 7, path: '/'});
		$("#wrapper-copy").attr("class","sliderIncrease2");
		$("#example").slider('option','value',2);
	}

	$("#wrapper-copy").show();

	$(".whitepaper").validate({
	  rules: {
			PIID_933_0: {
				equalTo: ".emailone"
			}
		}
	});

	$(".contact").validate();

	$("#career").validate();

	$(".link-awardtoggle").click(function(){
		$(".wrapper-awardstext").hide();
		$("#"+$(this).attr("title")).show();
	});

});

document.onclick = navmain_close;

/*function initMenu() {
	$("#nav-side li a").click(function() {
		$(this).next().slideToggle("fast");
	});
}*/

function navmain_open()
{
	navmain_canceltimer();
	navmain_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
	if(ddmenuitem.length>0) {
		$(this).find("a").addClass("open");
	}
}

function navmain_close()
{
	if(ddmenuitem) {
		ddmenuitem.css('visibility', 'hidden');
		$(ddmenuitem).parent().find("a").removeClass("open");
	}
}

function navmain_timer()
{
	closetimer = window.setTimeout(navmain_close, timeout);
}

function navmain_canceltimer()
{
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function loadAward(div) {
	$("div.wrapper_AwardInfo").hide();
	$("div#" + div).slideDown();
}

function openVideo() {
	$("div#wrapper_CarderVideo").addClass("videowindow");
	$("div#wrapper_CarderVideo").html("Chris Carder, ThinData CEO, discusses the good and the bad of email marketing on TVO's 'More to Life'.<br /><br /><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='320' height='240' id='Chris Carder' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='allowFullScreen' value='false' /><param name='movie' value='video.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' />	<embed src='video.swf' quality='high' bgcolor='#ffffff' width='320' height='240' name='Chris Carder' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>")
}
