$(document).ready
(
	function() 
	{		
		$('a[href*=.pdf]').each
		(
			function(i)
			{
				var a = $(this);

				a.click
				(
					function()
					{
						trackPageView(a.attr('href')); 
					}
				);
			}
		);
		
		$('a').click
		(
			function()
			{
				$(this).blur();
			}
		);
		
		// activate fancy zoom
		$('.video_link').fancyZoom({width:500, height:375});
		
		var strNoFlashHTML = $('#video1').innerHTML;
		
		//save the url to the swf and video
		// use hash to video1 panel for fancy zoom to work
		$('.video_link').each
		(
			function(i)
			{
				$(this).data('url', $(this).attr('href'));
				$(this).attr('href', '#video1');
			}
		);
		
		// create swf object on video link click
		$('.video_link').click
		(
			function()
			{	
				var pnlVideo1 = $('#video1');
				pnlVideo1.html("");
				doVideoSwfObject(strNoFlashHTML, $(this).data('url'));
				var strHtml = pnlVideo1.html().toLowerCase();
				
				// log flv in google analytics, only if flash is installed
				if(strHtml.indexOf('embed') > -1 || strHtml.indexOf('object') > -1)
				{
					// get the xml file's path
					var strXmlPath = "";
					var aryMatch = /xmlfile=.+\.xml/.exec($(this).data('url'));
					
					if(aryMatch)
					{
						var aryNameVal = aryMatch[0].split("=");
						strXmlPath = aryNameVal[1];
					}
					
					// track the flv 
					$.ajax
					(
						{
							type: "GET",
							url: strXmlPath,
							dataType: "xml",
							success: function(xml) 
								    {
									var strDir = "";
									
									$(xml).find('album').each
									(
										function()
										{
											strDir = $(this).attr('lgPath');
										}
									);
									
									var strVidUrl = "";
									
									$(xml).find('img').each
									(
										function()
										{
											strVidSrc = $(this).attr("src");
										}
									);
									
									trackPageView(strDir + strVidSrc);
								     }
						}
					);
				}
			}
		);
		
		// remove swf object html when closing
		$('#zoom_close').click
		(
			function()
			{
				var pnlVideo = $('#video1');
				
				if(pnlVideo.html().indexOf('embed') > -1 || pnlVideo.html().indexOf('object') > -1)
					pnlVideo.html("");
			}
		);
		
	}
);

function doVideoSwfObject(strNoFlashHTML, strSwfUrl)
{
	var so = new SWFObject(strSwfUrl, "so", "500", "375", "9");
	so.addParam("quality", "best");
	so.addParam("wmode", "opaque");
	so.write("video1");        
			
	var pnlVideo = $('#video1'); 

	if(pnlVideo.html().indexOf('embed') < 0 || pnlVideo.html().indexOf('object') < 0)
		pnlVideo.html(strNoFlashHTML);
}

/*== Lightbox for the Dist. Locator form on every Page ==*/
$(document).ready( function() {
	$('#distLocator_link').fancyZoom({width:400, height:310});
	$('#distLocator_link').click
		(
			function()
			{	
				trackPageView('/distributor_locator')
			}
		);
		$('.product_compare_faq').fancyZoom({width:600, height:450});
});



function trackPageView(strUrl)
{
	if(typeof(strUrl) == "string" && pageTracker)
		pageTracker._trackPageview(strUrl);
}