﻿/*::::::::::::::::::::::::::::::::::::::::::::
		Base JS
		Copyright © 2010 McMurry
::::::::::::::::::::::::::::::::::::::::::::*/

(function ($) {
	// Image Preloader
	var cache = [];
	$.preLoadImages = function () {
		var args_len = arguments.length;
		for (var i = args_len; i--; ) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
	$(function () {
		// Global jQuery
		$.preLoadImages('/ClientResources/Images/ddn-physicians.png', '/ClientResources/Images/ddn-specialties.png', '/ClientResources/Images/ddn-patients.png', '/ClientResources/Images/ddn-about.png');

		// Phone Replacement
		updatePhone();

		// Site Search
		$('#header .site-search input').val('Search OrlandoOrtho.com...');
		$('#header .site-search input').focus(function () {
			$(this).filter(function () {
				return $(this).val() == '' || $(this).val() == 'Search OrlandoOrtho.com...';
			}).val('').addClass('focus');
		}).blur(function () {
			$(this).filter(function () {
				return $(this).val() == '';
			}).val('Search OrlandOrtho.com...').removeClass('focus');
		});

		// Dropdowns
		$('#header div.navigation ul li #nav_our_physicians').after($('#sitemap-wrap .subnav-physicians'));
		$('#header div.navigation ul li #nav_orthopaedic_specialties').after($('#sitemap-wrap .subnav-specialties'));
		$('#header div.navigation ul li #nav_patient_resources').after($('#sitemap-wrap .subnav-patients'));
		$('#header div.navigation ul li #nav_about_us').after($('#sitemap-wrap .subnav-about'));
		$('#header div.navigation ul li').hoverIntent(dPanel);

		// CTAs
		if ($('#cta-wrap ul li').length > 3) {
			$('#cta-wrap').prepend('<a href="javascript:void(0);" class="tab tab-prev" title="Previous">Previous</a><a href="javascript:void(0);" class="tab tab-next" title="Next">Next</a>');
			$('#cta-wrap').scrollable({ clickable: false, items: 'ul', keyboard: false, prev: '.tab-prev', next: '.tab-next', size: 3, speed: 500 }).circular().mousewheel();
		}

		// Quick Form
//		$('#marquee-wrap .quick-form-wrap .field input[type="text"], #column-right .quick-form-wrap .field input[type="text"]').each(function () {
//			$(this).val($(this).parent('div').children('label').text() + '...');
//			$(this).parent('div').children('label, br').remove();
//			var tV = $(this).val();
//			$(this).focus(function () {
//				$(this).filter(function () {
//					return $(this).val() == '' || $(this).val() == tV;
//				}).val('').addClass('focus');
//			}).blur(function () {
//				$(this).filter(function () {
//					return $(this).val() == '';
//				}).val(tV).removeClass('focus');
//			});
//		});
	});
})(jQuery);
var dPanel = { interval: 100, sensitivity: 10, over: addPanel, timeout: 100, out: removePanel };
function addPanel() { $($(this).find('div.subnav')).fadeIn('fast'); $(this).addClass('hover'); }
function removePanel() { $($(this).find('div.subnav')).fadeOut('fast'); $(this).removeClass('hover'); }

// DD Roundies



/*
	Update Phone Numbers
	--------------------
	Check for cookie and get value of referral_source and set to variable 's'.
	If cookie is not present, check for value of 'source' parameter and set variable 's' if not undefined.
	Check for variable 's' to see if anything matches and set variable 'n' to the correct number.
	If variable 'n' is not an empty string (default), use the replaceText function to replace phone numbers to variable 'n'.
	Set a cookie
*/
function updatePhone() {
	var c = $.cookie('referral_source');
	var q = jQuery.url.param('source');
	var s = ''
	var n = '';
	if (c != undefined) {
		s = c;
	} else {
		if (q != undefined) {
			s = q;
		}
	}
	switch (s) {
		case 'google-cpc':
			n = '877-544-2039';
			break;
	}
	if (n.length > 0) {
		$.cookie('referral_source', s, { expires: 30 });
		$('#wrap *').replaceText(/^(\([2-9]|[2-9])(\d{2}|\d{2}\))(-|.|\s)?\d{3}(-|.|\s)?\d{4}$/gi, n);
		$('.quick-form input[id$=hdnReferrer]').val(s);
	}
}
