	var _setOrangeCategoryButtonExecuted = false;

    $(document).ready(function()
    {
			//init scroll buttons display (if needed)
			initScrollButtons();
		
			setLanguageHover('DE');

			setOrangeCategoryButton();

			setSlideToggleMrolBox();
	
    	    setHoverRegularButtons('divTopSection');
	
    	    setHoverAllChildButtonsByClass('BottomButton');

			setSideBarMenuItemsHover();

			setGlossaryLexiconItemsHover();

			setSidebarMenuItemsBackgroundPosition();

			setLexiconSearchBoxMiddleBacgkroundPosition();

   			setTextInputWatermarkText();

			setGlossaryToggle();

			SetIncreaseDecreaseButtons();

			ClearMrolInputsOnClick();

			//function to display a popup 'contact us' form after 2 minutes (120000 miliseconds) on the site:
			initContactUsPopup(120000);

			//function to change the look of all links which are directed to certain file types:
			StyleLinks();
	});

	function StyleLinks()
	{
		//style links which are directed to a PDF file:
		$("a[href$='.pdf']").attr('target', '_blank').css('background', 'url(images/pdf.gif) no-repeat left top').css('padding', '0 0 0 20px');

		//style links which are directed to a Word document (.doc, .docx, .rtf):
		$("a[href$='.doc'], a[href$='.docx'], a[href$='.rtf']").attr('target', '_blank').css('background', 'url(images/wordoc.gif) no-repeat left top').css('padding', '0 0 0 20px');
	}

	function setLanguageHover(className )
      {
            $("." + className ).hover(
	    function()
            {
                    	$(this).css("color", "white");
            },
            function()
            {
                    	$(this).css("color", "grey");
            });
        }

	function initContactUsPopup(ms)
	{
		//make sure the popup is active for this user. if not, just return:
		if($('#divContactPopUp').attr('active') == 'false') return;		

		//check if there already is a cookie with the time the user the site. if not, create one:
		var cookieVal = getCookieValue('popupContactUsCookie');
		if(cookieVal == null || cookieVal == '')
		{
			//there is no cookie, so set a cookie:
			cookieVal = new Date().toString();
			setCookie('popupContactUsCookie', cookieVal, 1);
		}
		else if(cookieVal == '-1')
		{
			//we don't need to do this procees until the cookie will expire, so just return:
			return;
		}

		//check every 5 seconds if the given time already ellapsed:
		window.setTimeout(function()
		{
			var cookieDate = new Date(cookieVal);
			
			//check whether the given time (in miliseconds) ellapsed:
			if(new Date().getTime() - cookieDate.getTime() >= ms)
			{
				/* set a special value (-1) in the cookie so we'll know not to do this procees again
				 * until the cookie expires: */
				setCookie('popupContactUsCookie', '-1', 1);
				
				//show the popup:
				showPopup();
			}
			else
			{
				//recursively call this function:
				initContactUsPopup(ms);
			}
		
		}, 5000);
	}

	function showPopup()
	{
		var winSize = getWindowSize();

		//show the contact us popup div:
		var popupDiv = $('#divContactPopUp');
		popupDiv.css('position', 'absolute');
		popupDiv.css('left', ((winSize.width -  popupDiv.width()) / 2) + 'px');
		popupDiv.css('top', (((winSize.height -  popupDiv.height()) / 2) + $(window).scrollTop()) + 'px');
		popupDiv.css('zIndex', '10');
		
		//position, size and show the background div of the popup:
		var popupDivBg = $('#divPopUpBg');
		popupDivBg.css('position', 'absolute');
		popupDivBg.css('width', (winSize.width) + 'px');
		popupDivBg.css('height', '5000px');
		popupDivBg.css('left', '0px');
		popupDivBg.css('top', '0px');
		popupDivBg.css('zIndex', '5');

		//make sure there will be no horizontal scrollbar caused by the bg div:
   		$(document.body).css('overflow-x', 'hidden');
		
		popupDiv.show();
		popupDivBg.show();

		//Google analytics code:
		var PopUppageTracker = _gat._getTracker("UA-3997138-4");
		PopUppageTracker._setAllowLinker(true); 
		PopUppageTracker._setAllowAnchor(true);
		PopUppageTracker._setAllowHash(false);
		PopUppageTracker._trackPageview('/event/popform/load');

		//add a 'click' event handler to the 'close' button of the popup div which will hide the popup div:
		$('#divContactPopUpClose').bind('click', function()
		{
			popupDiv.hide();
			popupDivBg.hide();
			$(document.body).css('overflow-x', 'auto');

			//Google analytics code:
			var PopUppageTracker = _gat._getTracker("UA-3997138-4");
			PopUppageTracker._setAllowLinker(true); 
			PopUppageTracker._setAllowAnchor(true);
			PopUppageTracker._setAllowHash(false);
			PopUppageTracker._trackPageview('/event/popform/close');
		});
	}

	function getWindowSize()
    {
       	var w;
       	var h;
       
       	if(window.innerWidth) //FF
       	{
           		w = window.innerWidth;
 	          	h = window.innerHeight;
       	}
       	else //IE
       	{
           		w = document.documentElement.clientWidth > 0 ? document.documentElement.clientWidth : document.documentElement.offsetWidth;
           		h = document.documentElement.clientHeight > 0 ? document.documentElement.clientHeight : document.documentElement.offsetHeight;		
       	}
       
       	return { width : w, height : h };
    }

	function setCookie(cookieName, value, expireDays)
	{
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expireDays);
		document.cookie = cookieName + '=' + escape(value) + ((expireDays== null) ? '' : ';expires=' + exdate.toGMTString()) + ';path=/';
	}

	function getCookieValue(cookieName)
	{
		if (document.cookie.length > 0)
  		{
  			var start = document.cookie.indexOf(cookieName + '=');
  			if (start != -1)
    			{
    				start = start + cookieName.length + 1;
    				var end = document.cookie.indexOf(';', start);
    				if (end == -1) 
				{
					end = document.cookie.length;
				}
			
    				return unescape(document.cookie.substring(start, end));
    			}
  		}

		return '';
	}

	function setOrangeCategoryButton(button)
	{

		var CurrentButton = '';

		if(button)
		{
			CurrentButton = button;
		}
		else
		{
			//if no specific button class was passed, continue only if the function was'nt executed yet:
			if(_setOrangeCategoryButtonExecuted)
			{
				return;
			}

			switch (true)
			{
				case (location.href.indexOf('our-services/') !=-1):
					CurrentButton = '.Button1';
					break;
				case (location.href.indexOf('telemedicine/') !=-1):
					CurrentButton = '.Button2';
					break;
				case (location.href.indexOf('heart-health/') !=-1):
					CurrentButton = '.Button3';
					break;
				case (location.href.indexOf('how-does-it-work/') !=-1):
					CurrentButton = '.Button4';
					break;
				case (location.href.indexOf('faq/') !=-1):
					CurrentButton = '.Button5';
					break;
			}
		}		

		if (CurrentButton!='')
		{
			// 1. Remove Hover
			$(CurrentButton).removeClass('BottomButton');
			// 2. Change Background
	       	$(CurrentButton).find("div").each(function()
              	{
				var lastDotIndex = $(this).css("background-image").lastIndexOf('.');
		  		if(lastDotIndex > 0)
		  		{
		  			var sNewImageUrl = $(this).css("background-image").substring(0, lastDotIndex)  +  '_hover' + $(this).css("background-image").substring(lastDotIndex );
                    			$(this).css("background-image", sNewImageUrl);
		  		}

				$(this).css('color','black');
               	});
		}

		//mark that the function was already executed:
		_setOrangeCategoryButtonExecuted = true;
							     
    }

	function setSlideToggleMrolBox()
	{
		$('.MrolTopButton').click(function() 
		{
			$('#MrolBox').slideToggle(400);
		});
	}
       
	function ClearMrolInputsOnClick()
	{
		$('.MrolInput').click(function() 
		{
			$(this).val('');
		});
	}

	function SetIncreaseDecreaseButtons()
	{
		// Increase Font Size
  		$(".IncreaseFontButton").click(function()
		{
                	if ($(".DecreaseFontButton").css("background-image").indexOf('_hover') !=-1) 
			{
                     	//$(this).css("background-image", $(this).css("background-image").replace(".png", "_hover.png"));

				var bgImage =  $(this).css("background-image");
				var lastDotIndex = bgImage.lastIndexOf('.');

		  		if(lastDotIndex > 0)
		  		{
					$(this).css("background-image", bgImage.substring(0, lastDotIndex)  +  '_hover' + bgImage.substring(lastDotIndex));
				}		     

                     	$(".DecreaseFontButton").css("background-image", $(".DecreaseFontButton").css("background-image").replace("_hover", ""));

    				$('html').css('font-size', 18);
					$('.ButtonsAndPhone div').css('font-size', 12);
			
    				return false;
			}
  		});

  		// Decrease Font Size
  		$(".DecreaseFontButton").click(function()
		{
			if ($(".IncreaseFontButton").css("background-image").indexOf('_hover') !=-1) 
			{
                    		//$(this).css("background-image", $(this).css("background-image").replace(".png", "_hover.png"));

				var bgImage =  $(this).css("background-image");
				var lastDotIndex = bgImage.lastIndexOf('.');

		  		if(lastDotIndex > 0)
		  		{
					$(this).css("background-image", bgImage.substring(0, lastDotIndex)  +  '_hover' + bgImage.substring(lastDotIndex));
				}
           
                    		$(".IncreaseFontButton").css("background-image", $(".IncreaseFontButton").css("background-image").replace("_hover", ""));
		
    				$('html').css('font-size', 16);

    				return false;
			}
  		});     
	}


	function initScrollButtons()
	{
		//get the class name passed as parameter to the doScroll() function:
		$('#divScrollDown').each(function()
		{
			var onClick = $(this).attr('onclick').toString();
  			var startIndex = onClick.indexOf('scrollDown(', onClick.indexOf('{')) + ('scrollDown(').length + 1;
			var length = onClick.indexOf(')', startIndex ) - (startIndex + 1);
			var className = onClick.substr(startIndex, length);

			doScroll(className);
		});
	}

	function setGlossaryToggle()
	{
		$('[class$=_toggle]').each(function()
		{
			var item = $(this);
			item.css('cursor', 'pointer');
			var toggleAllClass = item.attr('class');
			toggleAllClass = toggleAllClass.replace("_toggle", "");
			var slideAllClass = toggleAllClass + "_slide";
			var slideAll = $('.' + slideAllClass);
                	
			if(item.attr("id") == "active")
			{
				slideAll.show();
			}
			else
			{
				slideAll.hide();
			}
                    
			$(item).click(function(el)
			{
				if(slideAll.css('display') == 'none')
				{
					slideAll.slideDown(); 
				}
				else
				{
					slideAll.slideUp();
				}

				return false;
			});
		});
	}

	function setTextInputWatermarkText()
	{
		$('.withWatermark').watermark( { cssClass: 'watermark' } );
	}

	function setGlossaryLexiconItemsHover()
	{
		$('.lexicon ul li').hover(function()
		{
			$(this).addClass('hover');
		},
		function()
		{
			$(this).removeClass('hover');
		});
	}

	function setLexiconSearchBoxMiddleBacgkroundPosition()
	{
		if($.browser.msie)
		{
			//Due to a IE issue, set each sidebar menu item background-position-y css property to '1px':
			$('.lexiconSearchBoxMiddle').css('background-position','left 1px');
		}

	}

	function setSidebarMenuItemsBackgroundPosition()
	{
		if($.browser.mozilla)
		{
			//Due to a FF issue, set each sidebar menu item background-position-y css property to '0.5px':
			$('.sidebarMenuItem').css('background-position','left 0.5px');
		}
		
	}

	function setSideBarMenuItemsHover()
	{
		$('.sidebarMenuItem').hover(function()
        	{
            		if ($(this).attr('class').indexOf('Current') < 0)
            		{
                		$(this).addClass('Current');
            		}
            		else
            		{
                		$(this).attr('currentListItem', 'true');
            		}
        	},
        	function()
        	{
            		if(!$(this).attr('currentListItem'))
            		{
                		$(this).removeClass('Current');
            		}
        	});
	}

        function setHoverRegularButtons(className)
        {
            $("." + className + " div.button").hover(function()
            {
                //var sNewImageUrl = $(this).css("background-image").replace(".png", "_hover.png");

		  var lastDotIndex = $(this).css("background-image").lastIndexOf('.');
		  if(lastDotIndex > 0)
		  {
		  	var sNewImageUrl = $(this).css("background-image").substring(0, lastDotIndex)  +  '_hover' + $(this).css("background-image").substring(lastDotIndex );
                    	$(this).css("background-image", sNewImageUrl);
		  }
            },
            function()
            {
                var sNewImageUrl = $(this).css("background-image").replace("_hover", "");

                $(this).css("background-image", sNewImageUrl);

            });
        }

        function setHoverAllChildButtonsByClass(className)
        {

            $("." + className).hover(function()
            {
                $(this).find("div").each(function()
                {
                    //var sNewImageUrl = $(this).css("background-image").replace(".png", "_hover.png");

					var lastDotIndex = $(this).css("background-image").lastIndexOf('.');
					if(lastDotIndex > 0 && $(this).css("background-image").indexOf("_hover") < 0)
					{
						var sNewImageUrl = $(this).css("background-image").substring(0, lastDotIndex)  +  '_hover' + $(this).css("background-image").substring(lastDotIndex );
                		$(this).css("background-image", sNewImageUrl);
						$(this).attr("hovered","true");
						$(this).css('color','black');
					}
              	});

            },
            function()
            {
                $(this).find("div").each(function()
                {
					if($(this).attr("hovered") == "true")
					{
						var sNewImageUrl = $(this).css("background-image").replace("_hover", "");
                    	$(this).css("background-image", sNewImageUrl);
						$(this).attr("hovered","false");
		      			$(this).css('color','white');
					}
                });
            });
        }


	/* functions for inner_newDesign template */
	var _currentScrollTop = 0;
       
      	function scrollDown(className)
      	{
		var scrolledElement = $('.' + className)._scrollable()[0];
          	if(scrolledElement)
          	{
              	_currentScrollTop += 200;
              	if (_currentScrollTop > getMaxScrollTop(scrolledElement))
              	{
                  		_currentScrollTop = getMaxScrollTop(scrolledElement);
              	}

			doScroll(className);
          	}
       }

       function getMaxScrollTop(elm)
       {
           	return elm.scrollHeight - $(elm).height();
       }

       function scrollUp(className)
       {
		_currentScrollTop -= 200;
           	if (_currentScrollTop < 0)
           	{
              	 _currentScrollTop = 0;
           	}
           
           	doScroll(className);
       }

	function doScroll(className)
    {
		var scrolledElm= $('.' + className);

		scrolledElm.scrollTo({ top: _currentScrollTop, left: 0 }, 1000);
		
		//check if we need to 'disable' one of the scrolling buttons:
		if(_currentScrollTop == 0)
		{
			//hide the scroll up button:
			$('#divScrollUp').fadeOut('slow', function()
			{
				//fix margin issue in IE:
				if(jQuery.browser.msie)
				{
					$('#divScrollDown').css('margin', '265px 0 0 0');
				}
			});
		}
		else
		{
			//show the scroll up button:
			$('#divScrollUp').fadeIn('slow');
			
			//fix margin issue in IE:
			if(jQuery.browser.msie)
			{
				$('#divScrollDown').css('margin', '240px 0 0 0');
			}
		}
			
		var maxScrollTop = getMaxScrollTop(scrolledElm._scrollable()[0]);
		if(_currentScrollTop == maxScrollTop || maxScrollTop < 0)
		{
			//hide the scroll down button:
			$('#divScrollDown').fadeOut('slow');
		}
		else
		{
			//show the scroll down button:
			$('#divScrollDown').fadeIn('slow');
		}
       }

	function checkLeedForm(frm)
	{
		var fname=document.getElementById('name_frm');
		var lname=document.getElementById('lname_frm');
		var mail=document.getElementById('email_frm');
		var ph1=document.getElementById('pref_frm');
		var ph=document.getElementById('phone_frm');
                
              var mailexp=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
		var textexp=/^[a-zA-Z]+$/;
		var numexp=/^\d+$/;
                
		if(mail.value=='')
		{
			alert('Geben Sie bitte eine e-Mail-Adresse ein.');
			mail.focus();
			return false;
		}
		else if(!textexp.test(fname.value.replace(/-/g,"")))
		{
			alert('Bitte geben Sie Ihren Vornamen ein.');
			fname.focus();
			return false;
		}
		else if(!textexp.test(lname.value.replace(/-/g,"")))
		{
			alert('Bitte geben Sie Ihren Nachnamen ein.');
			lname.focus();
			return false;
		}
		else if(!mailexp.test(mail.value))
		{
			alert('Diese E-Mail-Adresse ist nicht g?ltig.');
			mail.focus();
			return false;
		}
		else if(!numexp.test(ph1.value))
		{
			alert('Bitte geben Sie die Vorwahl ein.');
			ph1.focus();
			return false;
		}
		else if(!numexp.test(ph.value))
		{
			alert('Bitte geben Sie Ihre Telefonnummer ein.');
			ph.focus();
			return false;
		}
		return true;
	}

	function printDiv(selector)
	{
		//Create a hidden iframe which will contain a document we will create out of only the elements
		//we want to print:
		var ifrm = document.createElement('iframe');
		
		$(ifrm).css('width','0px');
		$(ifrm).css('height','0px');
		ifrm.id = ifrm.name = 'printFrame';		
		document.body.appendChild(ifrm);

		var printDoc = ifrm.contentWindow.document;

		//Get the css elements from the page and add it:
		$('link').each(function()
		{
			printDoc.write(getOuterHTML(this));
		});

		//Get the printed div html:
		$(selector).each(function()
		{
			printDoc.write(getOuterHTML(this));
		});

		setPrintStyle(printDoc);
		
		//Close the document before print:
		printDoc.close();

		$(ifrm).bind('load',function()
		{
			//print the document:
			window.frames['printFrame'].focus();
			window.frames['printFrame'].print();		

			//hide the print iframe:
			$(ifrm).hide();
		});
	}

	function setPrintStyle(doc)
	{
		//hide the background image if any:
		$(doc.body).css('background-image', 'none');

		//remove the centered text-algin:
		$(doc.body).css('text-align', 'left');

		//remove the background of the divInnerPageContent div:
		$('.divInnerPageContent', doc).css('background-image','none');

		//remove the height limit of the divContent div:
		$('.divContent', doc).css('height','auto');

		//increase the font size of the divContentDiv:
		$('.divInnerPageContent', doc).css('font-size','2em');

		//hide the scroll buttons:
		$('.divContentScroll', doc).css('visibility','hidden');

		//make sure all images 'src' attribute is absolute url and not relative:
		$('img', doc).each(function()
		{
			var src = $(this).attr('src');

			//if the src url does'nt start with 'http://' we can assume it is relative, so make it absolute:
			if(src.indexOf('http://') != 0)
			{
				src = window.location.protocol + '//' + window.location.host + '/' + src;
				$(this).attr('src', src);
			}
		});

	}

	function getOuterHTML(elm)
  	{
		if(elm.outerHTML) //IE
		{
			return elm.outerHTML;
		}
		else //FF
		{
			var parent = elm.parentNode;
			var el = document.createElement(parent.tagName);
			el.appendChild(elm);
			var shtml = el.innerHTML;
			parent.appendChild(elm);
			return shtml;
		}
	}

	function getQueryStringVar(name) 
	{
		//get the query string part of the address:
		var queryString = window.location.search.substring(1);

		//split it into the different name/value pairs:
		var vars = queryString .split("&");

		//run on each pair and search for the requested var:
		for (var i=0; i<vars.length; i++) 
		{
			var nameValuePair = vars[i].split("=");
			if (nameValuePair[0] == name) 
			{
				return nameValuePair[1];
			}
		}

		return null;
	}



