$(document).ready(function(){

// homepage slideshow
if ( jQuery('#pghome').length > 0 ) {
	$('#slideshow').after('<div id="slideshow-controls"><a href="#" id="pause-play" title="Play/Pause Slideshow"><span>Play/Pause </span></a><a href="#" id="prev" title="Previous"><span>Previous </span></a><a href="#" id="next" title="Next"><span>Next </span></a></div>');	
	jQuery('#prev, #next, #pause-play').click(function(){return false;});	
	jQuery('#slideshow').cycle({
		fx: 'fade',
		prev: '#prev',
		next: '#next',
		delay: 1000,
		timeout: 6500,
		speed: 1000
	});
	jQuery('#pause-play').toggle(
		function() {
			jQuery('#slideshow').cycle('pause');
			jQuery("#pause-play").addClass("play");
		},
		function() {
			jQuery('#slideshow').cycle('resume');
			jQuery("#pause-play").removeClass("play");
	});
}

// Take a Virtual Tour of Dentus
if ( jQuery('#pgtour').length > 0 ) {
	jQuery("#floormap-messages div:gt(0)").hide();
	jQuery("#img_floormap_Map area").hover(
	  function () {
		var link = "#floormap-messages div" + jQuery(this).attr("href");
		jQuery("#floormap-messages div").hide();
		jQuery(link).show();
	  },
	  function () {
		jQuery("#floormap-messages div").hide();
		jQuery("#floormap-messages div#msg-welcome").show();
	  }
	);
	
	jQuery("#floormap-room-nav").hide();
	jQuery("#floormap-rooms .rm").hide();
	jQuery("#img_floormap_Map area").click(function(evt) {
		if ($(this).attr("class") == "active") {
			evt.preventDefault();
		}
		else {
			evt.preventDefault();
			jQuery("#img_floormap_Map area").removeClass("active");
			jQuery(this).addClass("active");
			var link = jQuery(this).attr("href");
			var link = link.replace("#msg-", "#rm-");
			var link = "#floormap-rooms div" + link;
			jQuery("#floormap-rooms .rm").hide();
			jQuery(link).show();
		}	
	});	
}

// Meet the doctors
if ( jQuery('#pgdentists').length > 0 ) {
	jQuery("#pgdentists #nav-dr li a:eq(0)").addClass("active");	
	jQuery("#pgdentists .dr:gt(0)").hide();
	jQuery("#pgdentists #nav-dr li a").click(function(evt) {
		if ($(this).attr("class") == "active") {
			evt.preventDefault();
		}
		else {
			evt.preventDefault();
			jQuery("#pgdentists #nav-dr li a").removeClass("active");
			jQuery(this).addClass("active");
			var link = jQuery(this).attr("href");
			var link = "#pgdentists div" + link;
			jQuery("#pgdentists .dr").hide();
			jQuery(link).show();
			
			
		}	
	});	
} // end

// Meet the Staff
if ( jQuery('#pgstaff').length > 0 ) {


	// jQBrowser v0.2: http://davecardwell.co.uk/javascript/jquery/plugins/jquery-browserdetect/
	eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(c/a))+String.fromCharCode(c%a+161)};while(c--){if(k[c]){p=p.replace(new RegExp(e(c),'g'),k[c])}}return p}('Ö ¡(){® Ø={\'¥\':¡(){¢ £.¥},\'©\':{\'±\':¡(){¢ £.©.±},\'¯\':¡(){¢ £.©.¯}},\'¬\':¡(){¢ £.¬},\'¶\':¡(){¢ £.¶},\'º\':¡(){¢ £.º},\'Á\':¡(){¢ £.Á},\'À\':¡(){¢ £.À},\'½\':¡(){¢ £.½},\'¾\':¡(){¢ £.¾},\'¼\':¡(){¢ £.¼},\'·\':¡(){¢ £.·},\'Â\':¡(){¢ £.Â},\'³\':¡(){¢ £.³},\'Ä\':¡(){¢ £.Ä},\'Ã\':¡(){¢ £.Ã},\'Å\':¡(){¢ £.Å},\'¸\':¡(){¢ £.¸}};$.¥=Ø;® £={\'¥\':\'¿\',\'©\':{\'±\':²,\'¯\':\'¿\'},\'¬\':\'¿\',\'¶\':§,\'º\':§,\'Á\':§,\'À\':§,\'½\':§,\'¾\':§,\'¼\':§,\'·\':§,\'Â\':§,\'³\':§,\'Ä\':§,\'Ã\':§,\'Å\':§,\'¸\':§};Î(® i=0,«=».ì,°=».í,¦=[{\'¤\':\'Ý\',\'¥\':¡(){¢/Ù/.¨(°)}},{\'¤\':\'Ú\',\'¥\':¡(){¢ Û.³!=²}},{\'¤\':\'È\',\'¥\':¡(){¢/È/.¨(°)}},{\'¤\':\'Ü\',\'¥\':¡(){¢/Þ/.¨(°)}},{\'ª\':\'¶\',\'¤\':\'ß Ñ\',\'¥\':¡(){¢/à á â/.¨(«)},\'©\':¡(){¢ «.¹(/ã(\\d+(?:\\.\\d+)+)/)}},{\'¤\':\'Ì\',\'¥\':¡(){¢/Ì/.¨(«)}},{\'¤\':\'Í\',\'¥\':¡(){¢/Í/.¨(°)}},{\'¤\':\'Ï\',\'¥\':¡(){¢/Ï/.¨(«)}},{\'¤\':\'Ð\',\'¥\':¡(){¢/Ð/.¨(«)}},{\'ª\':\'·\',\'¤\':\'å Ñ\',\'¥\':¡(){¢/Ò/.¨(«)},\'©\':¡(){¢ «.¹(/Ò (\\d+(?:\\.\\d+)+(?:b\\d*)?)/)}},{\'¤\':\'Ó\',\'¥\':¡(){¢/æ|Ó/.¨(«)},\'©\':¡(){¢ «.¹(/è:(\\d+(?:\\.\\d+)+)/)}}];i<¦.Ë;i++){µ(¦[i].¥()){® ª=¦[i].ª?¦[i].ª:¦[i].¤.Õ();£[ª]=É;£.¥=¦[i].¤;® ­;µ(¦[i].©!=²&&(­=¦[i].©())){£.©.¯=­[1];£.©.±=Ê(­[1])}ê{® Ç=Ö ë(¦[i].¤+\'(?:\\\\s|\\\\/)(\\\\d+(?:\\\\.\\\\d+)+(?:(?:a|b)\\\\d*)?)\');­=«.¹(Ç);µ(­!=²){£.©.¯=­[1];£.©.±=Ê(­[1])}}×}};Î(® i=0,´=».ä,¦=[{\'ª\':\'¸\',\'¤\':\'ç\',\'¬\':¡(){¢/é/.¨(´)}},{\'¤\':\'Ô\',\'¬\':¡(){¢/Ô/.¨(´)}},{\'¤\':\'Æ\',\'¬\':¡(){¢/Æ/.¨(´)}}];i<¦.Ë;i++){µ(¦[i].¬()){® ª=¦[i].ª?¦[i].ª:¦[i].¤.Õ();£[ª]=É;£.¬=¦[i].¤;×}}}();',77,77,'function|return|Private|name|browser|data|false|test|version|identifier|ua|OS|result|var|string|ve|number|undefined|opera|pl|if|aol|msie|win|match|camino|navigator|mozilla|icab|konqueror|Unknown|flock|firefox|netscape|linux|safari|mac|Linux|re|iCab|true|parseFloat|length|Flock|Camino|for|Firefox|Netscape|Explorer|MSIE|Mozilla|Mac|toLowerCase|new|break|Public|Apple|Opera|window|Konqueror|Safari|KDE|AOL|America|Online|Browser|rev|platform|Internet|Gecko|Windows|rv|Win|else|RegExp|userAgent|vendor'.split('|')))
	
	/* ----------------------------------------------------------------- */
	
	var aol       = $.browser.aol();       // AOL Explorer
	var camino    = $.browser.camino();    // Camino
	var firefox   = $.browser.firefox();   // Firefox
	var flock     = $.browser.flock();     // Flock
	var icab      = $.browser.icab();      // iCab
	var konqueror = $.browser.konqueror(); // Konqueror
	var mozilla   = $.browser.mozilla();   // Mozilla
	var msie      = $.browser.msie();      // Internet Explorer Win / Mac
	var netscape  = $.browser.netscape();  // Netscape
	var opera     = $.browser.opera();     // Opera
	var safari    = $.browser.safari();    // Safari
	
	var userbrowser     = $.browser.browser(); //detected user browser
	
	//operating systems
	
	var linux = $.browser.linux(); // Linux
	var mac   = $.browser.mac();   // Mac OS
	var win   = $.browser.win();   // Microsoft Windows
	
	//version
	
	var userversion    = $.browser.version.number();
	
	/* ----------------------------------------------------------------- */			
	
	if (userbrowser == "Internet Explorer") {
	
		$("html").addClass("ie");
	
	} else {}
	
	$("html").addClass("" + userversion + "");

	// check broswer
	var browser = $("html").attr('class');
	//console.log(browser);
	
	// if ie 7 or lower don't do anything
	if ( browser == "ie 7" ) {
	} else if ( browser == "ie 6") {
	} else if ( browser == "ie 5.5") {
	} else if ( browser == "ie 5") {
	} else {
	

	// create staff thumbnail container html
	var nav = '<div id="staff-listing">'+
				'<div class="twocol">'+
					'<div id="staff-links">'+
					'</div>'+
				'</div>'+
				'<div class="twocol-last">'+
					'<div id="portrait-load">'+
					'</div>'+
				'</div>'+
				'<div class="clear"></div>'+
			'</div><!-- end #staff-listing -->';
	jQuery("#pgstaff #content p:first").after(nav);

	// create staff thumbnail links
	jQuery("#pgstaff .staff .portrait-box img").each( function(){
		var target = $(this);
		var source = target.attr('src');
		var divID = target.parent().parent().attr('id');
		var img = '<a href="#'+divID+'" class="thumbnail-link"><img src="'+source+'" width="41" height="47" alt="staff thumbnail" class="portrait-thumbnail" ></a>'
		jQuery("#pgstaff #staff-listing #staff-links").append(img);
	});
	
	// add data to staff thumbnail links
	jQuery("a.thumbnail-link").each( function() {
		var target = $(this);
		var source = target.attr('href');
		var name = jQuery(source).find(".title h2").text();
		var title = jQuery(source).find(".title p.cms-editable").text();
		$(this).data('name', name).data('title', title);
	});
	
	// staff thumbnail hover meta
	jQuery("a.thumbnail-link").hover( 
	function() {
		//console.log("hovering");
		var name = $(this).data('name');
		var title = $(this).data('title');
		var container = '<div id="thumbnail-link-meta"><h3>'+name+'</h3><p>'+title+'</p><div class="pointer"></div></div>';
		var offset = $(this).offset();
		var left = Math.round( parseInt(offset.left) );
		var top = Math.round( parseInt(offset.top) );
		
		var metaleft = left+'px';
		var metatop = top-68;
		var metatop = metatop+'px';
		
		//console.log(top);
		$("#pgstaff").prepend(container);
		$("#thumbnail-link-meta").css('top', metatop).css('left', metaleft);
		
	},
	function() {
		//console.log("hovering exit");
		$("#pgstaff").find("#thumbnail-link-meta").remove();
	});
	

	
	
	jQuery("#pgstaff .staff .portrait-box").hide();
	jQuery("#pgstaff .staff").hide();
	
	// staff show/hide
	jQuery("#pgstaff #staff-links a").click(function(evt) {
		if ($(this).attr("class") == "active") {
			evt.preventDefault();
		}
		else {
			evt.preventDefault();
			jQuery("#staff-links a").removeClass("active");
			jQuery(this).addClass("active");
			var link = jQuery(this).attr("href");
			jQuery("#pgstaff .staff").hide();
			
			// show staff
			jQuery(link).show();
			
			// load image
			link = link+" .portrait-box";
			var image = jQuery(link).html();
			jQuery("#pgstaff #portrait-load").html(image);
			
		}	
	});	
	jQuery("#pgstaff #staff-links a:first").trigger("click");
	
	
	} // end ie check else statement
	
} // end


// Contact
if ( jQuery('#pgcontact').length > 0 ) {
	jQuery("#captcha-directions").hide();
	jQuery("a#captcha-info").toggle(
		function() {
			jQuery("#captcha-directions").slideDown(400);
		},
		function() {
			jQuery("#captcha-directions").slideUp(400);
	});
	jQuery("a#captcha-info").click(function(){
		return false;
	});
}	


// Request an Appointment
if ( jQuery('#pgappt').length > 0 ) {

	jQuery("#captcha-directions").hide();
	jQuery("a#captcha-info").toggle(
		function() {
			jQuery("#captcha-directions").slideDown(400);
		},
		function() {
			jQuery("#captcha-directions").slideUp(400);
	});
	jQuery("a#captcha-info").click(function(){
		return false;
	});

}

// Subscribe
if ( jQuery('#pgsubscribe').length > 0 ) {

	$('#excerpt-pgappt').expander({
		slicePoint:       17, 
		expandPrefix:     ' ',
		expandText:         '[more...]', 
		userCollapseText: ' [close]' 
 	 });
}


// Location
if ( jQuery('#pglocation').length > 0 ) {
	jQuery("a[rel='lightbox']").colorbox();
}


// News
if ( jQuery('#pgnews').length > 0 ) {
	jQuery("#subnav a").click(function(evt) {
		if ($(this).attr("class") == "active") {
			evt.preventDefault();
		}
		else {
			evt.preventDefault();
			jQuery("#subnav a").removeClass("active");
			jQuery(this).addClass("active");
			var link = jQuery(this).attr("href");
			var link = "#pgnews div" + link;
			jQuery("#pgnews div.month").hide();
			jQuery(link).show();
		}	
	});	
	
	var path = window.location.hash;
	if ( path == "#post-2009-feb" ) {
		// if coming from childrens dental health link on philanthrophy page
		window.location.hash = "";
		jQuery("#subnav a[href='#post-2009-feb']").trigger("click");
		
	} else {
		jQuery("#subnav a:first").trigger("click");
	}
	
} //end













});
