jQuery(document).ready(function(){	
		
	//invisalign FAQ page
	jQuery('.accordion h3').click(function() {
		jQuery(this).toggleClass('active').next().toggle('blind', 'normal');
		return false;
	}).next().hide();
	
	//staff layout
	jQuery("#Mappy").children().each(function() {
		var _thisMap = jQuery(this);
		var _id = _thisMap.attr('id');
		//alert(_id);
		_thisMap.click(function() {
			//alert(_id || 'nothing');
			checkStaff(_id);
		});
	});
	
	jQuery("#Mappy").click(function() {
		var _h = jQuery("#left").height();
		
		if (_h < 800) {
			jQuery("#left").animate({height: 950}, 700, "easeOutExpo");
		/*if(jQuery("#staffMembers").find('.currentStaff')) {
			jQuery('#left').height();
			th = jQuery('.currentSlide').height();*/
		} else {
			return null;
		}
	});
	
	function checkStaff(id){
		var _div = jQuery("#staffMembers").find('.'+id);
		jQuery("#staffMembers").find('.currentStaff').fadeOut(450, "easeOutExpo").removeClass('currentStaff');
		_div.fadeIn(650, "easeOutExpo").addClass('currentStaff');
		
		//rewrote the function slightly to not be as bulky. left it commented out below this comment for you to use if you'd like. lots of quick clicks (or just using a slower computer) causes the current script to get really trippy and laggy because each time you click it's looking through every single div and computing the IF statement. you're a bad dude, good work!
		/*jQuery("#staffMembers div").each(function() {
				var _thisDiv = jQuery(this);
				var _class = _thisDiv.attr("class");
				//alert(_class || 'nothing');
				//alert(id);
				if(id === _class) {
					//alert(id + "===" + _class);
					_thisDiv.fadeIn('slow');
				} else {
					_thisDiv.fadeOut('slow');
				}
				
			});*/
	}

	//hide menu on load
	jQuery("p.active").hide();
		
	//add class 'last' to last topper element
	jQuery("#innermenu > .abscontainer").last().addClass('last');
	
	//jQuery("div.sub").fadeTo("0", 0.9);
	/*jQuery("a.active").mouseover(function(){menuShow(this); return(false);});
													
	jQuery(".content").mouseover(function(){
		jQuery(".topsub > p.active").stop().slideUp(800).removeClass("topsub");
 	});*/
	
	jQuery('.empty').mouseover(function() {
		jQuery(".topsub > p.active").stop().hide().removeClass("topsub");
	});

	
	//no boxy outline on clicks
	jQuery("a").focus(function() {
		jQuery(this).blur();
	
	});
	
	jQuery('.abscontainer').hover(
		function() {
			jQuery('a.active', this).next().show();
		},
		function() {
			jQuery('a.active', this).next().hide();
		}
	);

		
	setTimeout(function()
	{
		if(window.location.hash == "#news")
		{
		  jQuery('.selector.news').click();
		}		
	},500);
	

	
	//callout actions/movements
	var ind;
	jQuery("area").hover(
		function() {
			ind = jQuery(this).index();
			jQuery('.oranges').children().eq(ind).stop().animate({left:"18px"},350, "easeOutExpo");
		},
		function() {
			jQuery('.oranges').children().eq(ind).stop().animate({left: "0px"}, 400, "easeOutExpo");
		}
	);
	
	
	//remove border on blank images
	if(jQuery(".sidepic > img").width() == 1) {
		jQuery(".sidepic > img").css({'border-color': "#B0D7E5"});
	}
	
	jQuery('.accordion h3').click(function() {
		jQuery(this).toggleClass('active').next().toggle('blind');
		return false;
	}).next().hide();	
	
	
	/*jQuery("a").filter(function() {
      return this.hostname && this.hostname !== location.hostname;
	 }).attr('target', '_blank');*/

});

//make menu work
function menuShow(menuitem){
	jQuery(".topsub > p.active").stop().slideUp('fast').removeClass("topsub");
	jQuery(menuitem).next().css("height", "auto").stop().slideDown('fast').parent().addClass("topsub");
}



function hovery(dv) {
	var hov = jQuery(dv).children('div.hovery');
	var pos = jQuery(dv).children('div.hovery').children('.imghovery').position().top;
	jQuery(dv).hover(
					 
		function() {
			jQuery(hov).children('img.hovery').stop().animate({
				top: '-=5'
			}, 300, 'easeOutExpo');
		},
		function() {
			jQuery(hov).children('img.hovery').stop().animate({
				top: pos
			}, 250, 'easeOutExpo');
		}
	);
}

function hovery2(dv) {
	var hov = jQuery(dv).children('div.hovery');
	var pos = jQuery(dv).children('div.hovery').children('.imghovery').position().top;
	jQuery(dv).hover(
					 
		function() {
			jQuery(hov).children('.imghovery').stop().animate({
				top: '-=5'
			}, 450, 'easeOutExpo');
		},
		function() {
			jQuery(hov).children('.imghovery').stop().animate({
				top: pos
			}, 250, 'easeOutExpo');
		}
	);
}


function overlayClick() {
	jQuery('.thumb a').each(function() {
		jQuery(this).append("<img src='/portals/0/library/images/click-to-view.png' class='thumb-over' />");
	});
	jQuery('.thumb').hover(
		function() {
			jQuery(this).children().children('.thumb-over').stop().fadeIn(350, 'easeOutExpo');
		},
		function() {
			jQuery(this).children().children('.thumb-over').stop().fadeOut(250, 'easeOutExpo');
		}
	);
}

function scrollQuotes() {
	jQuery('.quotes > .rotate').cycle({
		fx: 'scrollDown',
		easing: 'easeoutexpo',
		sync: 0,
		timeout: 8000,
		delay: 5000
	});
}

function doTour() {
	//get first and last labeled w/ class; use later to remove appropriate arrow
	jQuery('.slides').children(":first").addClass('first');
	jQuery('.slides').children(":last").addClass('last');
	
	//fade the first image in
	jQuery('.slides .first').fadeIn(450, 'easeOutExpo').addClass('currentSlide');
	checkArrows();
	
	//get forward motion functional
	jQuery('.arrows .next a').bind('click', function() {
	jQuery('.currentSlide').stop().fadeOut(400, 'easeOutExpo').removeClass('currentSlide').next().stop().fadeIn(500, 'easeOutExpo').addClass('currentSlide');
	growTourArea();
	checkArrows();
	});
	
	//get backward motion functional
	jQuery('.arrows .prev a').bind('click', function() {
	jQuery('.currentSlide').stop().fadeOut(400, 'easeOutExpo').removeClass('currentSlide').prev().stop().fadeIn(500, 'easeOutExpo').addClass('currentSlide');
	growTourArea();
	checkArrows();
	
	});
}



function checkArrows() {
    //remove arrows as needed
    if(jQuery('.currentSlide').hasClass('first')) {
        jQuery('.arrows .prev').hide();
    } else {
        jQuery('.arrows .prev').show();
    }
    
    if(jQuery('.currentSlide').hasClass('last')) {
        jQuery('.arrows .next').hide();
    } else {
        jQuery('.arrows .next').show();
    }    
}


function growTourArea() {
	//height of #left area (contains .tour)
//	var lh = jQuery("#left").height();
	//get height of tour area
	var th;
	th = jQuery('.currentSlide').height();
	//get new height by finding difference btwn the two vars and adding the padded height (160px)
	var nh;
	nh = th + 80;

	//make #left area grow to show the overflowing information
	jQuery("#left div.tour").stop().animate({height: nh}, 400, "easeOutExpo");
}


function kill() {
	jQuery('#avatar').remove();
};	

function avatarListen() {
	jQuery("#avatar .close").click(function() { 
		jQuery("#avatar").fadeOut(500, kill);

	});
	
	if(jQuery("#avatar").length) {
		setTimeout(function() {
			jQuery("#avatar .close").fadeIn(450);
		}, 3000);
		setTimeout(function() {
			jQuery("#avatar").fadeOut(500, kill)
		}, 38000);
	}
}
