// JavaScript Document
var vidPath = 'http://www.hunter.com/videos/';
//var vidPath = 'http://clerner-vista/www/hunter/videos/';
var videoTitle = '';
var d1 = "";
$(function()
	{
		initLoader();
		$('.videoItemLink').click(function(e)
					{
						e.preventDefault();
						var href = $(this).attr('href');
						if(href.toLowerCase().indexOf('index.cfm') > -1)
						{
							window.location.href = href;
						}
						else if(isIphone())
						{
							var id = $(this).attr('id');
							
							window.location.href = vidPath + $('#' + id + '_iphone').val() + '.mp4';
						}
						else
						{
							showLoader();
							
							href = href.substr(href.lastIndexOf('?') + 1);
							
							$.get(vidPath + 'videoLoader.cfm?' + href, function(data)
							{
							data = eval("(" + data + ")");
							d1 = data;
							$('<div>' + data.CONTENTS + '</div>')
								.dialog({
											width: 850,
											height: 605,
											modal:true,
											position : 'center',
											buttons : {'Close': function(){$(this).dialog('destroy'); $(this).remove();}},
											title : data.VIDEOTITLE,
											zIndex : 2000,
											close :
												function()
												{
													$(this).dialog('destroy'); $(this).remove()
												}
										});
							populateVideo(data)
							hideLoader();
							
							});
						}
					});
				
				
 	});

	function initLoader()
	{
		//check if loading layer is created if nor create one
		if($('#loadingLayer').length == 0)
		{
			$('body').append('<div id="loadingLayer" style="width:100%; height:100%; position:fixed; z-index:2000;' + 
			 'text-align:center;vertical-align:middle; display:none" class="ui-widget-overlay">' + 
			'<table style="width:50px; height:50px; position:fixed; z-index:2001; background-color:#FFF"' + 
			' class="ui-corner-all ui-dialog" id="loadingLayer_loader">' +
			'<tr><td align="center" valign="middle">' + 
			'<img src="http://www.hunter.com/images/ajax-loader.gif"/>' +
			'</td></tr></table></div>');
		}
	}
	function isIphone()
	{
		var iPhone = false;
		
		if(navigator.userAgent.toLowerCase().indexOf('iphone') > -1)
		{
			iPhone = true;
		}
		if(navigator.userAgent.toLowerCase().indexOf('ipad') > -1)
		{
			iPhone = true;
		}
		if(navigator.userAgent.toLowerCase().indexOf('android') > -1)
		{
			iPhone = true;
		}
		return iPhone;
	}
	
function showLoader()
{
	$('#loadingLayer_loader').css('left', ($('#loadingLayer').width() / 2) - ($('#loadingLayer_loader').width() / 2));
	$('#loadingLayer_loader').css('top', ($('#loadingLayer').height() / 2) - ($('#loadingLayer_loader').height() / 2));
	$('#loadingLayer').show();
}
function hideLoader()
{
	$('#loadingLayer').hide();
}
function populateVideo(data)
{
	// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
	var hasProductInstall = DetectFlashVer(8, 0, 0);
	
	// Version check based upon the values entered above in "Globals"
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	// Location visited after installation is complete if installation is required
	var MMredirectURL = "http://www.hunter.com/";
	
	// Stored value of document title used by the installation process to close the window that started the installation process
	// This is necessary to remove browser windows that will still be utilizing the older version of the player after installation is complete
	// DO NOT MODIFY THE FOLLOWING TWO LINES
	document.title = document.title.slice(0, 47) + " - Flash Player Installation";
	var MMdoctitle = document.title;
	
	// Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
	if ( hasProductInstall && !hasReqestedVersion ) {
		alert('You have an older version of Flash. Please upgrade.');

	} else if (hasReqestedVersion) {  // if we've detected an acceptable version
	
		var so = new SWFObject(vidPath + 'player.swf', 'ply', data.VIDWIDTH, data.VIDHEIGHT, '9', '#ffffff');
			so.addParam('allowfullscreen', 'true');
			so.addParam('allowscriptaccess', 'always');
			so.addParam('wmode', 'opaque');
			so.addVariable('file', data.HIRES);
			so.addVariable('stretching', 'uniform');
			so.addVariable('autostart', 'true');
			so.write('videoPlayer');
								
											
		} else {
			$('#videoPlayer').html('<br /><p><strong>Error! Flash player 8 or higher is required to view the video pictured below.</strong><br />Please install the new Flash player now to view this video.</p> <ul><li><a href="http://www.macromedia.com/go/getflash/">I want to install Flash player 8</a>.  The Flash Player is not available on smart phones, such as the iPhone or Blackberry.</li>');
		}
}
