//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
	var IE;
//-------------------------------------------------------------------------------------------------------
//	Track Public & Extranet Downloads
//-------------------------------------------------------------------------------------------------------
$(document).ready(function(){	
 
	//	Bind click event for downloads
	$(".trackDownload").click(function(){

		//	Set event info
		var	event_type		= 'Download',
			event_category	= $(this).attr("category"),
			event_label		= $(this).attr("filename");

		//	If filename not specifiec, get from URL
		if( !event_label )
		{
			var trackURL = $(this).attr("href");
			event_label = trackURL.substr(trackURL.lastIndexOf("/") + 1);
		}
 
//		alert( event_type + " : " + event_category + " : " + event_label );

		//	Send the event to Analytics
		pageTracker._trackEvent( event_type, event_category, event_label );
	});

	//	PDF links open new tab
	$("a[href$='pdf']").click(function(){
		$(this).attr("target","_blank");
	});

});

$(document).ready(function(){	
 
	//Bind tracking classes
	$(".trackOutbound,.trackEmail").click(function(){
 
		var eventType = this.className,
			relValue = $(this).attr("rel"),
			eventCategory;		
 
		//Check if rel attribute is set. If so, use the rel value as the event label.
		if (relValue.length) {
 
			var eventLabel = relValue;
 
			if (eventType == "trackDownload") {
				eventCategory = "download";
			} else if (eventType == "trackOutbound") {
				eventCategory = "outbound";
			} else {
				eventCategory = "mailto";
			}
		}
		//Otherwise we'll use the URL or filename as the event label.
		else {	
 
			var trackURL = $(this).attr("href"),
				eventLabel;
 
			if (eventType == "trackDownload") {
				eventLabel = trackURL.substr(trackURL.lastIndexOf("/") + 1);
				eventCategory = "download";
			} else if (eventType == "trackOutbound") {
				eventLabel = trackURL;
				eventCategory = "outbound";
			} else {
				eventLabel = trackURL.substr(7);
				eventCategory = "mailto";
			}
		}
 
		//Send the event to Analytics
		pageTracker._trackEvent(eventCategory, 'Download', eventLabel);		
//		pageTracker._trackEvent(eventCategory, 'click', eventLabel);		
	});

//---------------------------------------------------------------------------------------------------------
//	Expandible widgets
//---------------------------------------------------------------------------------------------------------
    $("h2.expand").click(function () {
		$(this).next("div.expandable").slideToggle("fast");
    });    

	//---------------------------------------------------------------------------------------------------------
	//		remove text from the textboxes when one focuses on the textbox
	//---------------------------------------------------------------------------------------------------------
    $('.label_in_textbox').each(function(){
		$(this).attr('label',$(this).val());

		$(this).focus(function(){
			var label = $(this).attr('label');
			var value = $(this).val();
			
			//alert('l='+label +' v='+value);
			if( label == value )
			{
				$(this).val('');
			}
			
		});

		$(this).blur(function(){
			var label = $(this).attr('label');
			var value = $(this).val();

			if( !value )
			{
				$(this).val(label);
			}
		});
    });

	//	CSS vertical align hack
    $(".bannerwidget div").each( function() {
		var	span_height	= $(this).innerHeight();
		var	margin_top	= ( 51 - span_height ) / 2 - 1;

		$(this).css("margin-top",margin_top+"px");
    });

	//---------------------------------------------------------------------------------------------------------
	//	Share Box
	//---------------------------------------------------------------------------------------------------------
    $("#sharebox").click(
		function (event) {
			$("#sharebox").toggleClass("active");
			$("ul#share").slideToggle(75);

			
	});
    $("a#sharebutton").click(
		function (event) {
			event.preventDefault();
	});

	//	External links target new window
	$('#body a[href^="http://"]').attr("target", "_blank");

//---------------------------------------------------------------------------------------------------------
//	Slideshow animation (home page)
//---------------------------------------------------------------------------------------------------------
    //	Init tab animation
	$("ul.tabs").tabs("div.panes > div", { 
		effect: 'fade' 
	});

	// Init scrollbar
	$(".horizontal-scroll").scrollable({ 
		size: 6
	});
	
	
});

function loadMailForm(title, link)
{
	$("#videobox").css('display','block');
	$('#videobox').load("/site/emailpage.php?title="+title+"&link="+link);
	$('#videobox').center(true);
};

function closeMailForm()
{
	$("#videobox").css('display','none');
};


