	$(document).ready(function(){
		// Open all external links in a new window:
		$("a[@href^=http]").each(
			function(){
				if(this.href.indexOf(location.hostname) == -1) { 
					$(this).attr('target', '_blank');
				}
			}
		);

		// Show the default video if necessary:
		$('#video').show();

		// Show the appropriate video when someoen clicks a video link:
		$('.flv_video').click(function(){
			// Slide all videos up:
			$('.video').slideUp();


			// And show the selected video:
			$(this).parent().parent().find('.video:first').slideDown();

			return false;
		});

		// Cycle through the index images if necessary:
		$('#splash_product_image').cycle({
			timeout: 2500
		});

		// Show the mail form if they are trying to email this page to someone:
		$('#email_this_page').click(function(){
			$('#mailer_form').slideDown();

			// Hide the mail result:
			$('#mail_result').hide();
			$('#mail_result').html('Waiting for the results of the mail request...');

			return false;
		});
	
		// Hide the mail form if they clicked cancel:
		$('#mail_cancel').click(function(){
			// Hide and clear the form:
			$('#mailer_form').slideUp();
			$('#mail_recipient_name').val(''); $('#mail_recipient_email').val(''); $('#mail_subject').val(''); $('#mail_message').val('');

			// Hide the mail result:
			$('#mail_result').hide();
			$('#mail_result').html('Waiting for the results of the mail request...');
		});

		// Send the mail:
		$('#mailer_form .inputSubmit').click(function(){
			// Dispay a message to let the user know sending is beginning:
			$('#mail_result').slideDown('slow');

			// Get the values from each field:
			var mail_recipient_name = $('#mail_recipient_name').val();
			var mail_recipient_email = $('#mail_recipient_email').val();
			var mail_subject = $('#mail_subject').val();
			var mail_message = $('#mail_message').val();
			var mail_from_name = $('#mail_from_name').val();
			var mail_from_email = $('#mail_from_email').val();
			var mail_url = '' + $('input[@name=page_url]').val();
			//var mail_url = mail_url.replace(/&/g, ':::');

			// Perform the ajax request:
			$.getJSON('/page_mailer.php', {
				send_to: mail_recipient_email,
				send_to_name: mail_recipient_name,
				subject: mail_subject,
				message: mail_message,
				from_name: mail_from_name,
				from_email: mail_from_email,
				page_url: mail_url
			// process the results:
			}, function(data){
				// See if it was successful:
				if( data.response.result_code == 0 ){
					// There was an error:
					$('#mail_result').html('<strong>The following errors were encountered when trying to send your mail</strong>:<br />' + data.response.error_message);
				} else{
					// Success!
					$('#mail_result').html('Message sent! <a id="close_mail_result" href="#">close</a>');

					// Close the mail result div:
					$('#close_mail_result').click(function(){
						$('#mail_result').hide();
						$('#mail_result').html('Waiting for the results of the mail request...');
					});

					// Hide and clear the form:
					$('#mailer_form').slideUp();
					$('#mail_recipient_name').val(''); $('#mail_recipient_email').val(''); $('#mail_subject').val(''); $('#mail_message').val('');
				}
			});
		});

		// Close the mail result div:
		$('#close_mail_result').click(function(){
			$('#mail_result').hide();
			$('#mail_result').html('Waiting for the results of the mail request...');
		});
	});
	
	function getObject(objectId) {

		// cross-browser function to get an object given the id
		if(document.getElementById && document.getElementById(objectId)) {
			return document.getElementById(objectId);
		} else if (document.all && document.all(objectId)) {
			return document.all(objectId);
		} else { // we're not going to support other browsers
			return false;
		}
	}

	function switchPane(tabToHighlightId, panelToShowId) {

		// store objects in local variables
		var tabToHighlight = getObject(tabToHighlightId);
		var panelToShow    = getObject(panelToShowId);

		var newT = getObject("newTab");
		var eduT = getObject("eduTab");
		var nutT = getObject("nutTab");
		var cliT = getObject("cliTab");
		var tesT = getObject("tesTab");
		var docT = getObject("docTab");
		var relT = getObject("relTab");
		var detT = getObject("detTab");
		var newP = getObject("newPanel");
		var eduP = getObject("eduPanel");
		var nutP = getObject("nutPanel");
		var cliP = getObject("cliPanel");
		var tesP = getObject("tesPanel");
		var relP = getObject("relPanel");
		var docP = getObject("docPanel");
		var detP = getObject("detPanel");

		// deactivate tabs and hide all panels
		if(newT) newT.className = "";
		if(eduT) eduT.className = "";
		if(nutT) nutT.className = "";
		if(cliT) cliT.className = "";
		if(tesT) tesT.className = "";
		if(relT) relT.className = "";
		if(docT) docT.className = "";
		if(detT) detT.className = "";

		if(newP) newP.style.display = "none";
		if(eduP) eduP.style.display = "none";
		if(nutP) nutP.style.display = "none";
		if(cliP) cliP.style.display = "none";
		if(tesP) tesP.style.display = "none";
		if(relP) relP.style.display = "none";
		if(docP) docP.style.display = "none";
		if(detP) detP.style.display = "none";

		// highlight active tab and show selected panel
		if(tabToHighlight)
			tabToHighlight.className = "active";
		if(panelToShow)
			panelToShow.style.display = "block";
	}

	function openWindow(url, w, h) {
		var features = "scrollbars,width=" + w + ",height=" + h;
		var win = window.open(url, 'popup', features);
		win.focus();
	}

	function playMultimedia(clipName){
		//var clipFileName = clipName;
		var url = "/store/mediaplayer.html?clip=" + clipName;
		var pw = window.open(url,"Video clip","width=400,height=350");
	}

	/*
	* logout
	*/
	var back_to = "<?= $FULL_URL ?>";
	function logout() {
		//alert(new_location);
		//location = new_location;
		var backto = "<?= $FULL_URL ?>";
		backto = backto.replace(/&/g,":::");
		location = "/logout.html?backto=" + backto;
	}
