(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.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);
    }
  }
})(jQuery)

jQuery.preLoadImages("../images/nav/company_on.png", "../images/nav/contact_on.png", "../images/nav/home_on.png", "../images/nav/press_on.png", "../images/nav/products_on.png", "../images/nav/resources_on.png", "../images/nav/solutions_on.png", "../images/nav/why_on.png", "../images/subindex/healthcaresystems_green_tab_1.png", "../images/subindex/healthcaresystems_blue_tab_0.png", "../images/subindex/healthcaresystems_red_tab_0.png", "../images/subindex/healthcaresystems_purple_tab_0.png", "../images/index_page/Index_top_left_inside_0.png", "../images/index_page/Index_top_left_inside_1.png", "../images/index_page/Index_top_left_inside_2.png");

$(document).ready(function() {
	file_path = $('#folder_level').text(); 
	if(file_path.indexOf('company') > 0)
	{
		changeBG('company'); 
	}
	else if(file_path.indexOf('products') > 0)
	{
		changeBG('products'); 
	}
	else if(file_path.indexOf('why') > 0)
	{
		changeBG('why'); 
	}
	else if(file_path.indexOf('technology') > 0)
	{
		changeBG('technology'); 
	}
	else if(file_path.indexOf('press') > 0)
	{
		changeBG('press'); 
	}
	else if(file_path.indexOf('support') > 0)
	{
		//NOTE NAMING INCONSISTENCY:
		changeBG('resources'); 
	}
	else if(file_path.indexOf('solutions') > 0)
	{
		changeBG('solutions'); 
	}
	else if(file_path.indexOf('contact') > 0)
	{
		changeBG('contact'); 
	}
	else
	{
		changeBG('home'); 
	}
});

function changeBG(element) {
	var theBG = $('#'+element).css("background-image").split("_off.").join("_on.");
	$('#'+element).css("background-image",theBG); 
	$('#'+element).css("color" , "#F4F4F5"); 
	$('#'+element).parent().attr('class','nav_li_on'); 
}

/*Drop down functions HERE!!!*/
$(document).ready(function(){
	$(".nav_li").hover(function(){
		$(this).find('.nav_link').css('background-image' , $(this).find('.nav_link').css('background-image').split("_off.").join("_on."));
		$(this).find('.nav_link').css('color' , '#F4F4F5');
	},
	function() {
		$(this).find('.nav_link').css('background-image' , $(this).find('.nav_link').css('background-image').split("_on.").join("_off."));
		$(this).find('.nav_link').css('color' , '#49484A');
	});
});

$(document).ready(function() {
	$('.nav_sub_list a').click(function(){
		$(".nav_li ul, .nav_li_on ul").css('display','none'); 
		$(this).parent().css('background-image').split("_on.").join("_off.");
	});
});

$(document).ready(function() {
	$('.nav_link').click(function(){
		$(".nav_li ul, .nav_li_on ul").css('display','none'); 
		$(this).css({'background-image': $(this).css('background-image').split("_on.").join("_off.")}); 
		$(this).css('color','#49484A'); 
	});
});

$(document).ready(function(){
	$(".nav_li, .nav_li_on").hover(function()
	{
		$(this).find('ul:first').css('display','block'); 
	}, 
	function()
	{
		$(this).find('ul:first').css('display','none'); 
	});
});


var loginState; 

$(document).ready(function(){
$('#login').toggle(function() {
	$(this).animate({top : '-5px'}); 
	$(this).css('z-index','999'); 
	$('#login_x').css('display','inline'); 
	$('#login_p').css('display','none'); 
}, function() {
	$(this).animate({top : '-83px'}); 
	$('#login_x').css('display','none'); 
	$('#login_p').css('display','block'); 
	loginState = setTimeout('changeZIndex()', 500); 
});
}); 

function changeZIndex() {
	$('#login').css('z-index','0'); 
}


//Functions for the index page slider
$(document).ready(function() {
	$('#slider_buttons').find('img').hover(function() {
		$(this).attr('src',$(this).attr('src').split('_off').join('_on'))},
	function() {
		if ($(this).attr('class') == "slider_button_off")
		{
			$(this).attr('src',$(this).attr('src').split('_on').join('_off'))
		}
	});
});
/*
$(document).ready(function() {
	$('#slider_buttons').find('img').click(function() {
		var theNumber = $(this).attr('id'); 
		var position = theNumber.slice(-1);
		var position1 = Number(position);
		var newPosition = position1*-669+669; 
		$('#index_top_left_img').animate({left:newPosition},1500,'easeInOutQuart'); 
		$(this).siblings().attr('src','../images/index_page/slider_button_off.png').attr('class','slider_button_off');
		$(this).attr('src','../images/index_page/slider_button_on.png').attr('class','slider_button_on');
	});
});
*/

$(document).ready(function() {
	var x = 1; 
	var timer = setInterval(changePosition,10000); 
	
	$('#slider_buttons').find('img').click(function() {
		var theNumber = $(this).attr('id'); 
		var position = theNumber.slice(-1);
		var position1 = Number(position); 
		x = position1; 
		clearInterval(timer); 
		changePosition(); 
		timer = setInterval(changePosition,10000); 
		$(this).siblings().attr('src','../images/index_page/slider_button_off.png').attr('class','slider_button_off');
		$(this).attr('src','../images/index_page/slider_button_on.png').attr('class','slider_button_on');
	});
	
	function changePosition() 
	{
		$('#slider_button_'+x+'').siblings().attr('src','../images/index_page/slider_button_off.png').attr('class','slider_button_off'); 
		$('#slider_button_'+x+'').attr('src','../images/index_page/slider_button_on.png').attr('class','slider_button_on');
		newPosition = x*-669+669; 
		$('#index_top_left_img').animate({left:newPosition},1500,'easeInOutQuart'); 
		x++; 
		if (x == 4)
		{
			x = 1; 
		}
	}
});


/*End index page slider functions*/

function OpenNewWindow(url)
{
	var h = window.screen.height;
	var w = window.screen.width;
	var options = "status=yes,toolbar=no,directories=no,personalbar=no,resizable=no, scrollbars=yes, left=0, top=0, width=" + w +",height=" + h;
	window.open(url,"Doctations", options);
}

$(document).ready(function() {
	var currentYear = (new Date).getFullYear();
    $("#current_year").text(currentYear);

});


$(document).ready(function ()
{
	var url = document.URL.split('?search=')[1];
	$.cookie("urlOrigin",url, {path:'/' , expires: 180 });
	if (document.getElementById('CampCode'))
	{
		document.getElementById('CampCode').value = $.cookie('urlOrigin');
	}
});

$(document).ready(function ()
{
	$(".feature_box, .feature_box_on").hover(function(){
		if ($(this).css('background-image').indexOf('_off') > -1)
		{
			$(this).css('background-image',$(this).css('background-image').split("_off.").join("_on."));
		}
	},
	function() {
		if ($(this).attr('class') == 'feature_box')
		{
			$(this).css('background-image',$(this).css('background-image').split("_on.").join("_off."));
		}
	});
});

$(document).ready(function ()
{
	$(".feature_box, .feature_box_on").click(function(){
		var input = ''+ $(this).attr("id").split("_box")[0] +''; 
		$(this).siblings().css({'background-image': $(this).css('background-image').split("_on.").join("_off.")});
		$(this).siblings().attr('class','feature_box'); 
		$(this).attr('class','feature_box_on'); 
		changeContent(input); 
	});
});

function changeContent(userChoice)
{
	var choice = $('#'+ userChoice +''); 
	$(choice).css('display','block'); 
	$(choice).siblings().css('display','none'); 
}

/*Here is the image rotator for the subpages*/
$(document).ready(function ()
{
	$(".subrotate_box, .subrotate_box_on").hover(function(){
		if ($(this).css('background-image').indexOf('_off') > -1)
		{
			$(this).css('background-image',$(this).css('background-image').split("_off.").join("_on."));
		}
	},
	function() {
		if ($(this).attr('class') == 'subrotate_box')
		{
			$(this).css('background-image',$(this).css('background-image').split("_on.").join("_off."));
		}
	});
});

$(document).ready(function ()
{
	$(".subrotate_box, .subrotate_box_on").click(function(){
		var input = ''+ $(this).attr("id").split("_box")[0] +''; 
		$(this).siblings().css({'background-image': $(this).css('background-image').split("_on.").join("_off.")});
		$(this).siblings().attr('class','subrotate_box'); 
		$(this).attr('class','subrotate_box_on'); 
		changeSubContent(input); 
	});
});

function changeSubContent(userChoice)
{
	var choice = $('#'+ userChoice +''); 
	$(choice).css('display','block'); 
	$(choice).siblings().css('display','none'); 
}


/*The following is the code for the tabs on the healthcare systems page*/
$(document).ready(function() {
	$(".subindex_tab").click(function(){
		var num = $(this).attr('id').split('tab_')[1]; 
		for (i=0; i<4; i++)
		{
			var tab = $(".subindex_tab")[i]
			$(tab).css({'background-image': $(tab).css('background-image').split("_0.").join("_1.")});
			$('#subindex_tab_body_section_'+i).hide(); 
			$('#subindex_tab_body_section_'+num).show(); 
		}
		$(this).css({'background-image': $(this).css('background-image').split("_1.").join("_0.")});
	});
});

//The following 2 functions toggle the terms and conditions on terms.asp
$(document).ready(function() {
	$('#doc_button_terms').click(function() {
		$('#patient_terms').fadeOut(700); 
		setTimeout("$('#doctor_terms').fadeIn(700)" , 700); 
		$('#pat_button_terms').css('background-color','#f3f5f6' ); 
		$('#pat_button_terms p').css('color','#49484A' ); 
		$('#doc_button_terms').css('background-color','#B3251A' ); 
		$('#doc_button_terms p').css('color','white' ); 
	});
});

$(document).ready(function() {
	$('#pat_button_terms').click(function() {
		$('#doctor_terms').fadeOut(700); 
		setTimeout("$('#patient_terms').fadeIn(700)", 700); 
		$('#doc_button_terms').css('background-color','#f3f5f6' ); 
		$('#doc_button_terms p').css('color','#49484A' ); 
		$('#pat_button_terms').css('background-color','#B3251A' ); 
		$('#pat_button_terms p').css('color','white' ); 
	});
});

//Following is the function that handles the blowing up, and shrinking down, of the icons on the partners page:
$(document).ready(
	function partners(){
	$("ul.thumb li").hover(function() {
		$(this).css({'z-index' : '10'});
		$(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-110px', 
				marginLeft: '-110px', 
				top: '50%', 
				left: '50%', 
				width: '174px', 
				height: '174px',
				padding: '0px' 
			}, 200);
		
		} , function() {
		$(this).css({'z-index' : '0'});
		$(this).find('img').removeClass("hover").stop()
			.animate({
				marginTop: '0', 
				marginLeft: '0',
				top: '0', 
				left: '0', 
				width: '100px', 
				height: '100px', 
				padding: '5px'
			}, 400);
	});
});


//////////////////////////////////////These are the functions for the did you know page///////////////

function toggleDidYouKnow(thumb) {
	full = document.getElementById(thumb.id + "_full");
	hideAllDivs(); 
	$(full).fadeIn(500);
}

function hideAllDivs() {
	$('#did_you_know_container').find("div").hide(); 
}

function showFirstDiv() {
	$("#did_you_know_container div:first-child").fadeIn(3000); 
}


//////////////////////////////////////////////////scrolling nav\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
$(document).ready(function() {makeScrollable("div.sc_menu_wrapper", "div.sc_menu")});

	function makeScrollable(wrapper, scrollable){
	// Get jQuery elements
	var wrapper = $(wrapper), scrollable = $(scrollable);
	
	// Hide images until they are not loaded
	scrollable.hide();
	var loading = $('<div class="loading">Loading...</div>').appendTo(wrapper);
	
	// Set function that will check if all images are loaded
	var interval = setInterval(function(){
		var images = scrollable.find('img');
		var completed = 0;
		images.animate({opacity: "0.4"},500);
		images.hover(
			function()
			{
				$(this).stop().animate({opacity: "1.0"},500);
			},
			function()
			{
				$(this).stop().animate({opacity: "0.4"},500);
			});
		
		// Counts number of images that are succesfully loaded
		images.each(function(){
			if (this.complete) completed++;	
		});
		
		if (completed == images.length){
			clearInterval(interval);
			// Timeout added to fix problem with Chrome
			setTimeout(function(){
				
				loading.hide();
				// Remove scrollbars	
				wrapper.css({overflow: 'hidden'});						
				
				scrollable.slideDown('slow', function(){
					enable();	
				});					
			}, 1000);	
		}
	}, 100);


	function enable(){			
		// height of area at the top at bottom, that don't respond to mousemove
		var inactiveMargin = 100;
		// Cache for performance
		var wrapperWidth = wrapper.width();
		var wrapperHeight = wrapper.height();
		// Using outer height to include padding too
		var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
		// Do not cache wrapperOffset, because it can change when user resizes window
		// We could use onresize event, but it's just not worth doing that 
		// var wrapperOffset = wrapper.offset();
		
		//When user move mouse over menu			
		wrapper.mousemove(function(e){
			var wrapperOffset = wrapper.offset();
			// Scroll menu
			var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;	
			
			if (top < 0){
				top = 0;
			}
			
			wrapper.scrollTop(top);
		});		
	}
}

function toggleDidYouKnow(thumb) {
	full = document.getElementById(thumb.id + "_full");
	hideAllDivs(); 
	$(full).fadeIn(500);
}

function hideAllDivs() {
	$('#did_you_know_container').find("div").hide(); 
}

$(document).ready(function() {
	$("#did_you_know_container div:first-child").fadeIn(3000); 
}); 
//////////////////////////////////////////////////END of scrolling nav\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//roll-overs for submit buttons: 

$(document).ready(function(){
	$('.submit,#btnSubmit').hover(function(){
		$(this).css({'background-image': $(this).css('background-image').split("_off.").join("_on.")}); 
	}, 
	function(){
		$(this).css({'background-image': $(this).css('background-image').split("_on.").join("_off.")}); 
	}); 
}); 

//Here are the functions for the snipe on the index page
$(document).ready(function ()
{
	$("#snipe, #snipe_close").click(function(){
		$.cookie("dpn_snipe",true, {path:'/' , expires: 180 });
	});
});

$(document).ready(function(){
	if (!$.cookie("dpn_snipe"))
	{
		$('#snipe').show(2000);
	}
});

$(document).ready(function(){
	$('#snipe_close').click(function(){
		$('#snipe').css('display','none'); 
		return false; 
		});
	$('#snipe').click(function(){window.location = "contact/registration.aspx"});
});

/*And for my next trick, watch me pull an accordian style list out of my hat... for the DPN University page*/
$(document).ready(function(){
	$('#training_menu').find('li').click(function(){
		$('#training_menu li').attr('class','training_menu_off'); 
		$(this).attr('class','training_menu_on'); 
		$('#training_right div').hide(); 
		var showThis = $(this).attr('id').split('_menu').join('_section'); 
		$('#'+showThis).slideDown(1000); 
	});
});


$(document).ready(function(){
	$("[name=AppointmentRadioButtons]").filter("[value=Demo]").attr("checked","checked");
	$('#AppointmentRadioButtons').change(function(){
		if ($("input[@name=AppointmentRadioButtons]:checked").attr('id') == "AppointmentRadioButtons_1")
		{
			$('#webinar_drop, #webinar_training_schedule').show('slow'); 
			$('#demo_drop').hide('slow'); 
		}
		if ($("input[@name=AppointmentRadioButtons]:checked").attr('id') == "AppointmentRadioButtons_0")
		{
			$('#webinar_drop, #webinar_training_schedule').hide('slow'); 
			$('#demo_drop').show('slow'); 
		}
	});
});


/*
//I commented this out so that the phone number will remain up on the home page.  
$(document).ready(function(){
	var path = $('#folder_level').text(); 
	if(path.indexOf('company') < 1 & path.indexOf('products') < 1 & path.indexOf('why') < 1 & path.indexOf('technology') < 1 & path.indexOf('press') < 1 & path.indexOf('support') < 1 & path.indexOf('solutions') < 1 & path.indexOf('contact') < 1)
	{
		$('#header_message').html('<p>Doctations Version 2.0 Just released.  <a href="technology/our_platform.asp">See details...</a></p>'); 
	}
});*/

$(document).ready(function() {
	if (document.getElementById("comparison_slideshow"))
	{
		$("a.comparison_slideshow_visible").fancybox(); 
	}
}); 

$(document).ready(function() {
	if (document.getElementById("e_pre_infographic"))
	{
		$("#e_pre_infographic").fancybox();
	}
}); 

$(document).ready(function() {
	if (document.getElementById("iphone_video"))
	{
		$("#iphone_video").fancybox();
	}
}); 

$(document).ready(function() {
	if ($.support.opacity == false) {
		var newHeight = $('#wrapper').height(); 
		$('#IE_wrapper_shadow').attr({'style':'filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius="7", MakeShadow="false", ShadowOpacity="0.40");'}); 
		$('#IE_wrapper_shadow').height(newHeight); 
		$('#IE_wrapper_shadow').css('display','block'); 
	}
}); 

$(document).ready(function(){
	var t; 
	var u; 
	var v; 
	var mouseStatus = 'off'; 
	var redStatus = 'off'; 
	$('#patients_red_li').hover(function(){
		clearTimeout(t); 
		clearTimeout(v); 
		$('#patients_full_list').show(500); 
		u = setTimeout("$('#patients_closer').css('display','block');",500); 
		mouseStatus = 'on'; 
	}, 
	function(){
		clearTimeout(u); 
		t = setTimeout("$('#patients_full_list').hide();",500);  
		v = setTimeout("$('#patients_closer').css('display','none');",500); 
		mouseStatus = 'off'; 
	});
	$('#patients_closer_top, #patients_closer_bottom').hover(function(){
		t = setTimeout("$('#patients_full_list').hide();",500);  
		v = setTimeout("$('#patients_closer').css('display','none');",500); 
		redStatus = 'on'; 
	}, function(){
		redStatus = 'off'; 
		if (mouseStatus == 'on' && redStatus == 'off')
		{
			clearTimeout(t); 
			clearTimeout(v); 
		}
	}); 
}); 

$(document).ready(function(){
	var t; 
	var u; 
	var v; 
	var mouseStatus = 'off'; 
	var redStatus = 'off'; 
	$('#doctors_red_li').hover(function(){
		clearTimeout(t); 
		clearTimeout(v); 
		$('#doctors_full_list').show(500); 
		u = setTimeout("$('#doctors_closer').css('display','block');",500); 
		mouseStatus = 'on'; 
	}, 
	function(){
		clearTimeout(u); 
		t = setTimeout("$('#doctors_full_list').hide();",500);  
		v = setTimeout("$('#doctors_closer').css('display','none');",500); 
		mouseStatus = 'off'; 
	});
	$('#doctors_closer').hover(function(){
		t = setTimeout("$('#doctors_full_list').hide();",500);  
		v = setTimeout("$('#doctors_closer').css('display','none');",500); 
		redStatus = 'on'; 
	}, function(){
		redStatus = 'off'; 
		if (mouseStatus == 'on' && redStatus == 'off')
		{
			clearTimeout(t); 
			clearTimeout(v); 
		}
	}); 
}); 

