/*=============================================================================================
HOMEPAGE JAVASCRIPT INITIATION

Developer(s):		Zeke F.

Dependencies:		jquery_1_3_2_min.js
								fancybox.pack.js
								xLazyLoader.js

Update History:	02-07-11 - Added Jellyvision support & commented entire file - ZF
								02-08-11 - Performance tweaks on selectors - ZF
								02-28-11 - Removed slider. Changed up jellyvision slide - ZF
								
								MM-DD-YY - Change Comments - Intials

Notes:					Notes
=============================================================================================*/
$(document).ready(function() {
	//Detect if JavaScript is enabled
	$('html').addClass('js');
	
	// If you selecting something more then twice think about making it a variable - ZF	
	var macroNav = $('#macroNav'),
			primaryNav = $('#primaryNav'),
			headerNavs = macroNav.add(primaryNav),
			featuredContent = $('#featuredContent'),
			featuredContentUl = featuredContent.find('ul');
	
	//Add in unsemantic span for icon placement within macroNav items
	macroNav.find('a').not('#VPIHeader_portalLink a').prepend('<span class="siteIcon" />').wrapInner('<span />');
	//Since ie6-7 don't support :last-child
	primaryNav.find('ul li:last-child').addClass('last');
	//Add in unsemantic span for divider between primaryNav items
	$('> li > a',primaryNav).not(':first').before('<span />');
	//Add a hover class to header nav list items (used by ie6)
	$(headerNavs).find('li').hover(function()
	{
		$(this).addClass('hover');
	},function()
	{
		$(this).removeClass('hover')
	});

	//Jellyvision Slide Support
	var vpiPageTitle = 'Homepage',
			eVar2Is = 'Context Not Given';
	$('.jvModal').fancybox(
	{
		//JV Modal Options
		'overlayOpacity':.9,
		'overlayColor':'#660018',
		'type':'iframe',
		'scrolling':'no',
		'height':405,
		'width':720,
		'titleShow':false
	}).click(function()
	{
		//Enable Omniture Tracking for JV
		var eVar2Is = $(this).attr('id');
		_scTrackJellyvisionLoad(vpiPageTitle,eVar2Is);
	});
	//iOS friendly number
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
	var isiPod = navigator.userAgent.match(/iPod/i) != null;
	if(isiPod || isiPhone || isiPad)
	{
		if (document.cookie.indexOf("iphone_redirect=false") == -1) 
		{
			var easyDial = $('#header .tel').attr('title');
			if (easyDial != "")
			{
				$('#header .tel').html('<a href="tel:'+easyDial+'">'+easyDial+'</a>');
			}
		}
	}
	//view hours tooltip
	var contactData = 'Monday&ndash;Friday 5AM to 7PM PT, Saturday 7AM to 3:30PM PT';
	//Insert Content into document
	$('#wrapper').append('<div id="hoursTooltip"><p>'+contactData+'</p></div>');
	//Behavior of tooltip
	$('#phoneHours').hover(function()
	{
		$('#hoursTooltip').stop().css('opacity','1').fadeIn(200);
	},
	function()
	{
		$('#hoursTooltip').fadeOut(300);
	}); 
	//Image Preloader (requires xLazyLoader.js)
	$.xLazyLoader({
		img:['/~/media/img/graphics/icon_umbrella_glow.ashx', '/~/media/img/graphics/planicon_glow.ashx', '/~/media/img/graphics/dollaricon_glow.ashx']
	});
	//Enables heading to be underlined when the associated img is hovered over
	$('.grid_10 img').hover(
		function()
		{
			$(this).parent().prev().addClass('siblingHover');
		},
		function()
		{
			$(this).parent().prev().removeClass('siblingHover');
		}
	);
	//Allows the entire section to become clickable 
	$('#sectionedCTA li').not('#sectionedCTA li li').click(function()
	{
		window.location = $('a',this).attr('href');
	});
	//If NOT IE6 then enable img icons to toggle when it's parent container is hovered over
	if (!$.browser.msie && !$.browser.version.substr(0,1)<7)
	{
		$('#sectionedCTA li').not('#sectionedCTA li li').hover(
		  function()
		  {
		  	var imgPath = $('img',this);
		    imgPath.attr('src',imgPath.attr('src').replace(/([^.]*)\.(.*)/, "$1_glow.$2"));
			},
		  function()
		  {
		  	var imgPath = $('img',this);
		    imgPath.attr('src',imgPath.attr('src').replace('_glow',''));
			}
		);
	}
	//When you NEED an unsemantic break use this class
	$('.break').before('<br />');
	//Initiate AAHA Fancybox Modal
	var aahaModal = $('#footer').find('.aahaModal');
	if (aahaModal.length > 0)
	{
		$(aahaModal).fancybox({
			'type':'iframe',
			'scrolling':'no',
			'height':312,
			'width':580,
			'titleShow':false
		});
	}
	//Add a class of extLink to open any anchor in a new window/tab (Say no to target="_blank")
	$('.extLink').click(
		function()
		{
    	open($(this).attr('href'));
			this.blur();
    	return false;
   	}
	);
});
