//functions for interval delay
jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);  
};
jQuery.fn.fadeToggle = function(speed, easing, callback) {
 return this.animate({opacity: 'toggle'}, speed, easing, callback);  
};
jQuery.fn.slideDownFade = function(speed, easing) {
	return this.animate({opacity:'.9', height: 'show'}, speed, easing);	
};
jQuery.fn.slideUpFade = function(speed, easing) {
	return this.animate({opacity:'0', height: 'hide'}, speed, easing);		
};

jQuery.fn.clearHiddenFields = function() {
	return this.each(function(){
		$("input[type='hidden']", this).each(function(){
			this.value = '';
		});
	});		
};
	
	
$(document).ready(function() {
	// Turn off current link
	var noClick = 'a.pageCurrent, a.detailsLnk, a.serviceLnk, a.exceptLnk';
	$(noClick).live("click", function() {
		return false;														 
	});	
	
	// create a fade/slide toggle switch
	
	// hide dynamic elements
	$('.detailsWrap, .nextDef').hide();
	
	// Show Case Details
	$('a.detailsLnk').live("click", function(){
		$(this).toggleClass('collapse');
		$(this).next().slideFadeToggle(500);
		$(this).blur();																	
	});
	
	// Show minor details
	$('a.serviceLnk').live("click", function(){
		$(this).next().slideFadeToggle(500);
		$(this).blur();																			
	});
	
	
	//Exceptions
	$('.exceptLnk').live("click", function(){
		var $parentTest = $(this).parents('.locWrap');
		if($parentTest != 0){
			var $dropDwn = $(this).closest('.locWrap').children('.insLnk').next('.detailsWrap');
			$(this).closest('.locWrap').children('.insLnk').addClass('collapse');
			$dropDwn.slideDownFade(500);
		}
		$(this).blur();
		return false;
	});
	
	//For provider search
	$('.pSrch .altForm ul li, .pSrch .altForm ul li span').hover(function() {
		$(this).css('cursor', 'pointer');
	}, function () {
		$(this).css('cursor', 'default');
	});
	$('.pSrch .altForm ul li.liOpen').css('cursor','default');
	$('.pSrch .altForm ul li').click(function() {
		$(this).addClass('liOpen');
		$(this).children('.fset-invisible').slideDown(250);
	});
			
		
		
	//AJAX Call for Definitions
	$('.nextDef').addClass('addDef');
	$('.copayp').live("click", function() {
		$(this).next().load($('base').attr("href") + 'definitions.html #primaryCare span');
		$(this).next().slideToggle(200);		
		$(this).next('.addDef').removeClass('.addDef');
		$(this).blur();
		return false;
	});
	$('.copays').live("click", function() {
		$(this).next().slideToggle(200);
		$(this).next('.addDef').load($('base').attr("href") + 'definitions.html #specialtyCare span'); //This is the ajax load call - turned off for demo
		$(this).next('.addDef').removeClass('.addDef');
		$(this).blur();
		return false;
	});
	$('.copayr').live("click", function() {
		$(this).next().slideToggle(200);
		$(this).next('.addDef').load($('base').attr("href") + 'definitions.html #rehabCare span'); //This is the ajax load call - turned off for demo
		$(this).next('.addDef').removeClass('.addDef');
		$(this).blur();
		return false;
	});
	$('.copaym').live("click", function() {
		$(this).next().slideToggle(200);
		$(this).next('.addDef').load($('base').attr("href") + 'definitions.html #mentalHealth span'); //This is the ajax load call - turned off for demo
		$(this).next('.addDef').removeClass('.addDef');
		$(this).blur();
		return false;
	});
	
	//Tooltip
	$('.lrnMoreLnk').tooltip({
		track:false,
		showBody:'_',
		delay:0,
		fade:250,
		showURL: false 
	});
	//Rewrite for footer
	$('.appFooterCont li:visible:first').addClass('firstLI');
	
	// When the print link is clicked then show the print dialog
	$("#printLink").live("click", function(){
		window.print();
		return false;
	});
	
	
	//Email this page
	function mailpage() {
		var docTitle = escape(document.title);
		mail_str = "mailto:?subject=Please read: " + docTitle;
		mail_str += "&body=I thought you might be interested in learning about " + docTitle;
		mail_str += ". Click on the link below: " + document.location.href; 
		location.href = mail_str;
	};
	if($('.menuEmail').length>0){
		$('.menuEmail a').click(function(){
			mailpage();	
			return false;											
		});
	}
	
	// When links are clicked show popup
	var popupLinks = 'a#verifyInfLink, a#specialtyLink, a#helpLink, a#aboutLink';
	
	$(popupLinks).click(function() {
		showPopup($(this).attr("href"), 1000, 700);
		return false;
	});
	
	//Feedback
	$('#feedbackLnk').click(function(){
		feedBack();
		$(this).blur();
		return false;
	});
		
	function feedBack() {
		//IE
		if($.browser.msie){
			var browserType = 'Internet Explorer';	
			var browserVersion = $.browser.version;
		}
		//Safari
		if($.browser.safari){
			var browserType = 'Safari';	
			var browserVersion = $.browser.version;
		}
		//Mozilla
		if($.browser.mozilla){
			var browserType = 'Firefox';
			if($.browser.version.substr(0,3)=='1.9'){
			var browserVersion = '3'
			} else {
			var browserVersion = $.browser.version;
			}
		}
		var screenHeight = $(document).height();
		var screenWidth = $(document).width();
		var docTitle = escape(document.title);
		if($('body').attr('id').indexOf('hm')>=0){
			var brandType = 'Huntsman Cancer';
		}
		if($('body').attr('id').indexOf('ih')>=0){
			var brandType = 'Intermountain Healthcare';
		}
		if($('body').attr('id').indexOf('mg')>=0){
			var brandType = 'Intermountain Medical Group';
		}
		if($('body').attr('id').indexOf('sh')>=0){
			var brandType = 'SelectHealth';
		}
		var nLine = escape('\r');
		mail_str = "mailto:gene.smith@imail.org?subject=Comments and Feedback on " + brandType + " Provider Search";
		mail_str += "&body=" + nLine + nLine + nLine + "Browser: " + browserType +" " + browserVersion + nLine + 'Screen: ' + screenWidth + ' x ' + screenHeight;
		location.href = mail_str;
	};
	
	//back to top links
	$('.backToTop').live("click", function(){
			window.scrollTo(0,0);
			$(this).blur();
			return false;
		});
	
	//End functions
});
