/*=============================================================================================
GLOBAL INITATION FILE FOR WWW.PETINSURANCE.COM

Developer(s):		Zeke F.

Dependencies:		jquery_1_3_2_min.js

Update History:	02-07-11 - Added Jellyvision modal function & commented file - ZF
								03-02-11 - Added global view hours tooltip - ZF
								MM-DD-YY - Change Comments - Intials
								
Notes:					Make sure to change /js/fancybox.pack.js to /js/v3/fancybox.pack.js
								Find the Section labeled REMOVE and delete it prior to placing in sitecore
=============================================================================================*/
$(document).ready(function() {
	//Detect if JavaScript is enabled
	$('html').addClass('js');
	
	//If you selecting something more then twice think about making it a variable	
	var macroNav = $('#macroNav'),
			primaryNav = $('#primaryNav'),
			headerNavs = macroNav.add(primaryNav),
			vpiContent = $('#content');
	
	//Check if fancybox.pack.js is loaded
	if($.isFunction($.fn.fancybox))
	{
		//Fancybox is loaded. Setup the modals
		initModals();
	}
	else //If it isn't then load it
	{
		//loads script and then call the function to setup the modals
		$.getScript('/js/v3/fancybox.pack.js',initModals);
		//Make sure the path is /js/v3/fancybox.pack.js for sitecore
	}
			
	//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
	$('ul li:last-child',primaryNav).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')
	});
	//When you NEED an unsemantic break use this class
	$('.break').before('<br />');
	//Initiate Modals
	function initModals()
	{
		//Image modals
		var modal = vpiContent.find('.modal');
		if (modal.length > 0)
		{
			$(modal).fancybox({
				'overlayColor':'#f2f1f0',
				'overlayOpacity':0.8,
				'speedIn':400,
				'speedOut':550,
				'type':'image',
				'hideOnContentClick':true
			});
		}
		//Video Modals
		var videoModal = vpiContent.find('.videoModal');
		if (videoModal.length > 0)
		{
			$(videoModal).fancybox({
				'overlayColor':'#f2f1f0',
				'overlayOpacity':0.8,
				'speedIn':400,
				'speedOut':550,
				'autoDimensions':false,
				'width':400,
				'height':300
			});
		}
		//Jellyvision Modals
		var jvModal = vpiContent.find('.jvModal');
		if (jvModal.length > 0)
		{
			var vpiPageTitle = $.trim(document.title), //Get, clean up & store the title element
					eVar2Is = 'Context Not Given';
					
			//init Fancybox for JV
			$(jvModal).fancybox({
				'overlayColor':'#f2f1f0',
				'overlayOpacity':0.8,
				'speedIn':400,
				'speedOut':550,
				'type':'iframe',
				'scrolling':'no',
				'titleShow':false,
				'width':720,
				'height':405
			}).click(function()
			{
				//Enable Omniture Tracking for JV
				_scTrackJellyvisionLoad(vpiPageTitle,eVar2Is);
			});
		}
		//AAHA Fancybox Init
		var aahaModal = $('.aahaModal');
		if (aahaModal.length > 0)
		{
			$(aahaModal).fancybox({
				'type':'iframe',
				'scrolling':'no',
				'height':312,
				'width':580,
				'titleShow':false
			});
		}
	}
	//iOS friendly number
	var	isiPad = navigator.userAgent.match(/iPad/i) != null,
			isiPhone = navigator.userAgent.match(/iPhone/i) != null,
			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>');
			}
		}
	}
	//SUBSITES FOR VIEW HOURS TOOLTIP
	var subSite = window.location,
			isGroup=/^http:\/\/eb/i,
			isVets=/^http:\/\/vets/i,
			isConsumer=/^http:\/\/www.petinsurance.com/i,
			isConsumer2=/^http:\/\/petinsurance.com/i,
			isPress=/^http:\/\/press/i,
			isEnroll=/^https:\/\/www.petinsurance.com\/enroll/i,
			isEnroll2=/^https:\/\/petinsurance.com\/enroll/i;
	
	//IF CONSUMER or PRESS (both have the same phone number)
	if( isConsumer.test(subSite) || isConsumer2.test(subSite) || isPress.test(subSite) )
	{
		requestHours('Monday&ndash;Friday 5AM to 7PM PT, Saturday 7AM to 3:30PM PT');
	}
	//IF QUOTE/ENROLL (both have the same phone number)
	else if( isEnroll.test(subSite) || isEnroll2.test(subSite) )
	{
		requestHours('Monday&ndash;Friday 5AM to 7PM PT, Saturday 7AM to 3:30PM PT','noQuote');
	}
	//IF GROUP
	else if (isGroup.test(subSite))
	{
		requestHours('Monday&ndash;Friday 8AM to 5PM PT','noQuote');					
	}
	//IF VETS
	else if (isVets.test(subSite))
	{
		requestHours('Monday&ndash;Friday 7:30AM &ndash; 4:30PM PT','vetsTip');
	}
	//Function to Request Hours and Place Text Into title attr of #phoneHours
	function requestHours(contactData,toolTipClass)
	{
		//Insert Content into document
		$('#wrapper').append('<div id="hoursTooltip"><p>'+contactData+'</p></div>');
		//Behavior of tooltip
		$('#phoneHours').hover(function()
		{
			$('#hoursTooltip').addClass(toolTipClass).stop().css('opacity','1').fadeIn(200);
		},
		function()
		{
			$('#hoursTooltip').fadeOut(300);
		}); 
	}
	//init Plan ratings	
	var ratingText = $('.ratingText');
	if (ratingText.length > 0)
	{
		ratingText.tooltip({delay:0});
	}
	//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;
   	}
	);
});
