(function(){var d=window,e=document,f=".",g="UTF-8",h="complete",i="head",j="link",k="script",l="stylesheet",m="text/css",n="text/javascript";Math.floor(Math.random()*2147483648).toString(36);function o(b){var a=e.getElementsByTagName(i)[0];a||(a=e.body.parentNode.appendChild(e.createElement(i)));a.appendChild(b)}function _loadJs(b){var a=e.createElement(k);a.type=n;a.charset=g;a.src=b;o(a)}function _loadCss(b){var a=e.createElement(j);a.type=m;a.rel=l;a.charset=g;a.href=b;o(a)}function _isNS(b){for(var b=b.split(f),a=d,c=0;c<b.length;++c)if(!(a=a[b[c]]))return false;return true}function _setupNS(b){for(var b=b.split(f),a=d,c=0;c<b.length;++c)a=a[b[c]]||(a[b[c]]={});return a}
d.addEventListener&&typeof e.readyState=="undefined"&&d.addEventListener("DOMContentLoaded",function(){e.readyState=h},false);
if (_isNS('google.translate.Element')){return}var c=_setupNS('google.translate._const');c._cl='en';c._cuc='googleTranslateElementInit';c._cac='';c._cam='';var h='translate.googleapis.com';var b=(window.location.protocol=='https:'?'https://':'http://')+h;c._pah=h;c._pbi=b+'/translate_static/img/te_bk.gif';c._pci=b+'/translate_static/img/te_ctrl3.gif';c._phf=h+'/translate_static/js/element/hrs.swf';c._pli=b+'/translate_static/img/loading.gif';c._plla=h+'/translate_a/l';c._pmi=b+'/translate_static/img/mini_google.png';c._ps=b+'/translate_static/css/translateelement.css';c._puh='translate.google.com';_loadCss(c._ps);_loadJs(b+'/translate_static/js/element/main.js');})();

$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}


function cleanWhitespace(element) {
 element = $(element);
 for (var i = 0; i < element.childNodes.length; i++) {
   var node = element.childNodes[i];
   if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
     element.remove(node);
 }
}



var isDirectionsOpen = false;
var mapsInit = false;
var adminView = false;
var simpleMode = false;
$(document).ready(function(e) {
	
	
	if($.browser.version.substring(0, 2) == "8." && $.browser.msie) {
		simpleMode = true;
	}
    
	$("#megaMenu .globalMenu").html($(".globalMenu").html().replace(/\n/g,""));
	
	//detect editing Mode
	if($("#lcms_main_menu")){
		adminView = true;
	}

	/*
	$("#directionsButton").click(function(e) {
        if(isDirectionsOpen){
			isDirectionsOpen = false;
			//$("#directionsOverlay").fadeOut();
			$("#directionsContent").animate({height:0, top:-300});
			$("#directionsButton .arrow").addClass("down");
			$("#directionsButton .arrow").removeClass("up");
		}else{
			isDirectionsOpen = true;
			//$("#directionsOverlay").fadeIn();
			$("#directionsContent").animate({height:300, top:0},{duration: 1000, complete:function(){ directionsOpenComplete(); setDirections(0); }});
			$("#directionsButton .arrow").removeClass("down");
			$("#directionsButton .arrow").addClass("up");
			
		}
		
    });
*/


    $("#directionsButton").click(function(e) {
        if(isDirectionsOpen){
			isDirectionsOpen = false;
			$("#directionsContainer").animate({top:-444});
			$("#directionsButton .arrow").addClass("down");
			$("#directionsButton .arrow").removeClass("up");
		}else{
			isDirectionsOpen = true;
			$("#directionsContainer").animate({top:0},{duration: 1000, complete:function(){ directionsOpenComplete(); setDirections(0, true); }});
			$("#directionsButton .arrow").removeClass("down");
			$("#directionsButton .arrow").addClass("up");
			
		}
		
    });
	
	
	var subItems = "";
	//rebuild mega menu
	$("#megaMenu>ul>li").each(function(index, element) {
       // console.log("item : "+$(this).children("ul").html());
		subItems += "<ul class=\"level2\">"+$(this).children("ul").html()+"</ul>";
		$(this).children("ul").html("");
		
    });
	
	$("#mmDropDownItems").append(subItems);
	$("#subItems").css({top:-$("#subItems").height()});
	
	
	$("#megaMenuContainer").mouseenter(function(e) {
			mmOpen = true;
			//setMegaMenuSize();
          openMegaMenuDelayed();
			
     });
	
	 $("#megaMenuContainer").mouseleave(function(e) {
			mmOpen = false;
           closeMegaMenuDelayed();
			
     });
	
	$("#directionsContent .buttonList li").each(function(index, element) {
		$(this).click(function(e) {
			e.preventDefault();
			setDirections(index);
		});
	});
	
	$("#footer .buttonList li").each(function(index, element) {
		$(this).click(function(e) {
			e.preventDefault();
			$('html, body').animate({ scrollTop: 0 }, {duration:500, complete:function(){ openDirectionsSet(index); }});
		});
	});
		
	
	
	$(".globalNav>li").last().addClass("last");
	$("#subItems ul").last().addClass("last");
	$("#mmDropDown .level2").last().addClass("last");
	
	
	
	if($("#mainContentContainer .tabs").length != 0){
		generateTabs();
	}
	
	
	//<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Price+Medical+Building+|+1245+Highland+Avenue,+Suite+404++Abington,+Pennsylvania+19001&amp;aq=&amp;sll=40.047066,-75.160561&amp;sspn=0.20973,0.445976&amp;vpsrc=6&amp;ie=UTF8&amp;hq=Price+Medical+Building+|+1245+Highland+Avenue,+Suite+404++Abington,+Pennsylvania+19001&amp;hnear=&amp;radius=15000&amp;t=m&amp;ll=40.119646,-75.121631&amp;spn=0.003175,0.006968&amp;z=14&amp;iwloc=A&amp;cid=1985586573382399561&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Price+Medical+Building+|+1245+Highland+Avenue,+Suite+404++Abington,+Pennsylvania+19001&amp;aq=&amp;sll=40.047066,-75.160561&amp;sspn=0.20973,0.445976&amp;vpsrc=6&amp;ie=UTF8&amp;hq=Price+Medical+Building+|+1245+Highland+Avenue,+Suite+404++Abington,+Pennsylvania+19001&amp;hnear=&amp;radius=15000&amp;t=m&amp;ll=40.119646,-75.121631&amp;spn=0.003175,0.006968&amp;z=14&amp;iwloc=A&amp;cid=1985586573382399561" style="color:#0000FF;text-align:left">View Larger Map</a></small>
	
	
	
});
function directionsOpenComplete(){
	if(mapsInit ==false){
		mapsInit = true;
		initialize();
	}
	
}
function openDirectionsSet(index){
	
	isDirectionsOpen = true;
	$("#directionsContainer").stop(true,false).animate({top:0},{duration: 1000, complete:function(){  setDirections(index, true);
	
	
	 }});
	$("#directionsButton .arrow").removeClass("down");
	$("#directionsButton .arrow").addClass("up");
}

$(window).ready(function(e) {
   if($("#google_translate_element").length != 0){
		new google.translate.TranslateElement({pageLanguage: 'en', autoDisplay: false}, 'google_translate_element');
	}
});
var mmOpen = false;
var isOver = false;
function openMegaMenuDelayed(){
	isOver = true;
	$("#megaMenu").delay(1000, function(){
		if(isOver){
			openMegaMenu();	
		}
	});
	
}
function closeMegaMenuDelayed(){
	isOver = false;
	$("#megaMenu").delay(500, function(){
		if(mmOpen == false){
			closeMegaMenu();
		}
	});
	
}
function openMegaMenu(){
	
	if(sizeSet == false){
		setMegaMenuSize();
	}
	if(simpleMode){
		$("#mmDropDownItems").height(250);
		$("#mmDropDown").show();

	}else{
		$("#mmDropDownItems").animate({height:250}, {duration:500});
		$("#mmDropDown").fadeIn(500);
	}
	if(simpleMode){
		$("#mmShadowB").width($("#mmDropDownItems").innerWidth());
	}
}
function closeMegaMenu(){
	if(simpleMode){
		$("#mmDropDownItems").height(40);
		$("#mmDropDown").hide();
	}else{
		$("#mmDropDownItems").animate({height:40}, {duration:500});
		$("#mmDropDown").delay(200).fadeOut(250);
	}
	
}
function openSubMenuContainerComplete(){
	
}
function hideSubMenuContainer(){
	$("#subItemsContainer").height(0);
}
var sizeSet = false;
var subHeight = 0;
function setMegaMenuSize(){
	
	
	sizeSet = true;
	
	$("#mmDropDownItems ul").each(function(index, element) {
        
		$(this).width(( $("#megaMenu>ul>li:nth-child("+(index+1)+")").width())+"px");
		
		$(this).height(250);

		// if($(this).height() > subHeight){
		// 	subHeight = $(this).height();
		// }
		
    });
	$("#mmDropDownItems ul").each(function(index, element) {
        
		$(this).height(250);
		
    });
	
	 $("#mmDropDown").css("top","84px");
	 $("#mmDropDown").fadeOut(0);
	 
	 
}

var delayInt;
var delayIndex;
function setDirections(index,delay){
	
	if(delay == true){
		delayIndex = index;
      delayInt = setInterval("setLocation(delayIndex)", 1000);
		
		
	}else{
		setLocation(index);
	}
}



var map;
var markers = [];
var infoWindows = [];

var locations = [
	{latLong:new google.maps.LatLng(40.11965, -75.12163), text:"<div id=\"infoContainer\" style=\"width:350px; height:165px;\"><img src=\"/Websites/abington/images/office-abington.jpg\" height=\"113px\" style=\"float:left; padding-right:10px; padding-bottom:10px;\"/><strong>Abington office:</strong><br/>1245 Highland Ave., Suite 404<br/>Price Medical Building at Abington Memorial Hospital<br/>Abington, PA 19001<br/>215-887-2010 phone<br/>215-887-3291 fax <div id='getDirectionsContainer' style=\"clear:left; padding:5px; text-align:right;\"><a  class='button' href='javascript:getDirections(\"1245 Highland Ave., Suite 406 Price Medical Building at Abington Memorial Hospital Abington, PA 19001\")'>Get Directions</a></div></div>"},
	{latLong:new google.maps.LatLng(40.30644, -75.14708), text:"<div id=\"infoContainer\" style=\"width:350px; height:165px;\"><img src=\"/Websites/abington/images/office-doylestown.jpg\" style=\"float:left; padding-right:10px; padding-bottom:10px;\"/><strong>Doylestown office:</strong><br/>599 W. State St., Suite 211<br/>The Pavilion at Doylestown<br/>Hospital - north entrance <br/>Doylestown, PA 18901<br/>215-345-8707 fax <div id='getDirectionsContainer' style=\"clear:left; padding:5px; text-align:right;\"><a class='button' href='javascript:getDirections(\"599 W. State St., Suite 211 The Pavilion at Doylestown Hospital Doylestown, PA 18901\");'>Get Directions</a></div></div>"},
	{latLong:new google.maps.LatLng(40.17455, -74.92267), text:"<div id=\"infoContainer\" style=\"width:350px; height:165px;\"><strong>Langhorne office:</strong><br/>360 Middletown Blvd., Suite 400<br/>Oxford Square Complex<br/>Langhorne, PA 19047<br/>267-572-1924 fax <div id='getDirectionsContainer' style=\"clear:left; padding:5px; text-align:right;\"><a class='button' href='javascript:getDirections(\"360 Middletown Blvd., Suite 400 Oxford Square Complex Langhorne, PA 19047\");'>Get Directions</a></div></div>"},
	{latLong:new google.maps.LatLng(40.24398, -75.33930), text:"<div id=\"infoContainer\" style=\"width:350px; height:165px;\"><img src=\"/Websites/abington/images/office-landsdale.jpg\" style=\"float:left; padding-right:10px; padding-bottom:10px;\"/><strong>Lansdale office:</strong><br/>1690 Sumneytown Pike, Suite 190<br/>Lansdale, PA 19446<br/>215-855-7611 fax <div id='getDirectionsContainer' style=\"clear:left; padding:5px; text-align:right;\"><a class='button' href='javascript:getDirections(\"1690 Sumneytown Pike, Suite 190 Lansdale, PA 19446\")'>Get Directions</a></div></div>"},
	{latLong:new google.maps.LatLng(40.04194, -75.49927), text:"<div id=\"infoContainer\" style=\"width:350px; height:165px;\"><img src=\"/Websites/abington/images/office-paoli.jpg\" style=\"float:left; padding-right:10px; padding-bottom:10px;\"/><strong>Paoli office:</strong><br/>250 West Lancaster Pike, Suite 260<br/>Paoli, PA 19301<br/>610-993-1243 fax <div id='getDirectionsContainer' style=\"clear:left; padding:5px; text-align:right;\"><a class='button' href='javascript:getDirections(\"250 West Lancaster Pike, Suite 260 Paoli, PA 19301\")'>Get Directions</a></div></div>"}
];








function initialize() {
		
	var myOptions = {
	  zoom: 10,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	map = new google.maps.Map(document.getElementById("mapContainer"), myOptions);
	var bounds = new google.maps.LatLngBounds;
	
	for(var i = 0; i < locations.length; i++){
		bounds.extend(locations[i].latLong);
		var marker = new google.maps.Marker({position: locations[i].latLong, map: map});

		markers.push(marker);

		
		var infoWindow = new google.maps.InfoWindow({size: new google.maps.Size(150,50), maxWidth:360, disableAutoPan:false, content:locations[i].text});
		infoWindows.push(infoWindow);
		
		//map.addOverlay(marker);
		
	}

	google.maps.event.addListener(markers[0], 'click', function() {
 		 setLocation(0);
	});
	google.maps.event.addListener(markers[1], 'click', function() {
 		 setLocation(1);
	});
	google.maps.event.addListener(markers[2], 'click', function() {
 		 setLocation(2);
	});
	google.maps.event.addListener(markers[3], 'click', function() {
 		 setLocation(3);
	});
	google.maps.event.addListener(markers[4], 'click', function() {
 		 setLocation(4);
	});
	
	
}

function setLocation(index){
	if (delayInt) {
        clearInterval(delayInt);
        delayInt = null;
    } 
	if(mapsInit ==false){
		mapsInit = true;
		initialize();
	}
	
	
	
	//marker = new google.maps.Marker({position: locations[index].latLong, map: map, zIndex: Math.round(locations[index].latLong.lat()*-100000)<<5});
	map.setCenter(locations[index].latLong);
	
	
	
	$("#directionsContent .buttonList li").each(function(i, element) {
		if(i == index){
			$(this).addClass("active");
			infoWindows[i].open(map, markers[i]);
		}else{
			$(this).removeClass("active");
			infoWindows[i].close();	
		}
	});
	//infowindow.setContent(""); 
	infoWindows[index].open(map, markers[index]);
	
	map.setZoom(10); 
	//infowindow.open(map,markers[index]);

	
}

var numbContentTabs = 0;
function generateTabs(){
	
		$("#mainContentContainer .tabs").html($("#mainContentContainer .tabs").html().replace(/\n/g,""));
		$("#mainContentContainer .tabs").html($("#mainContentContainer .tabs").html().replace(/\s\s\s\s/g,""));
		$("#mainContentContainer .tabs").addClass("init");
		$("#mainContentContainer .tabs li").each(function(i, element) {
			$(this).click(function(e){
				e.preventDefault();
				setContentTab(i);
			});
			$(this).html("<span>"+$(this).children("a").text()+"</span>");
		});
		$("#mainContentContainer .tabsContentContainer").addClass("init");
		setContentTab(0);
}
function setContentTab(index){
	
	$("#mainContentContainer .tabsContentContainer .tabsContent").each(function(i, element) {
		if(index == i){
			$($("#mainContentContainer .tabs li")[i]).addClass("active");
			$(this).addClass("active");
		}else{
			$($("#mainContentContainer .tabs li")[i]).removeClass("active");
			$(this).removeClass("active");
		}
	});
	
	$(".tabsContentContainer").height($($("#mainContentContainer .tabsContentContainer .tabsContent").get(index)).height());

}

var toLocation = "";
function getDirections(location){
	toLocation = location;
	$("#getDirectionsContainer").html("Get Directions from:&nbsp;<input type='text' name='mapQuery' id='mapQuery'/><input type='button' id=\"mapButton\" value='Go'/>");
	$("#mapQuery").keypress(function(e){
		
		if(e.which == 13){
			e.preventDefault();
			submitDirections();
		}
    });
	$("#mapButton").click(function(e) {
        submitDirections();
    });
}

function submitDirections(){
	window.location.href = "http://maps.google.com/maps?q="+$("#mapQuery").val()+" to "+toLocation;
}






