
jQuery(document).ready(function($){	
								
	//hide menu on load
	jQuery("p.active").hide();
	
	//add class 'last' to last topper element
	jQuery("#innermenu > .abscontainer").last().addClass('last');
	
	/*jQuery("p.active > a").each(function() {
		jQuery(this).append("<div class='flasher'></div>");
	});*/
	
	//jQuery("div.sub").fadeTo("0", 0.9);
	jQuery("a.active").mouseover(function(){menuShow(this); return(false);});
													
	jQuery("#content, #home-content, #splash").mouseover(function(){
		jQuery(".topsub > p.active").stop().removeClass("topsub").hide();
 	});
	
	$('.topper.active').click(function(){
		return false;
	});
	
	//no boxy outline on clicks
	jQuery("a").focus(function() {
		jQuery(this).blur();
	});
	
	//remove border on blank images
	if(jQuery(".sidepic > img").width() <= 40) {
		jQuery(".sidepic > img").remove();
	}
	
	//accordion for INVISALIGN FAQ page
	jQuery('.accordion h3').click(function() {
		jQuery(this).toggleClass('active').next().toggle('blind', 'normal');
		return false;
	}).next().hide();
	
	if($('.sidepic').length) {
		addShadow();
	}	
	
	if($('.rotate').length) {
		$('.rotate').cycle();
	}
	
	//open external links in new window
	$("a[href^='http']").not("a[href*='" + window.location.host + "']").attr("target", "_blank");
	// for pdfs
	$("a[href$='.pdf']").attr("target","_blank");
	
	//get rid of the first and last menu dividers that take up extra space and jack up menu positioning
	DestroyDividers();
	
	$('#dnn_search').find('.NormalTextBox').val("Search the site").click(function() {
		$(this).val("");
	});
	$('#dnn_search').find('.StandardButton').val("");
	
	
	//on huge page w/ links not yet read, kill linkage
	jQuery('.deads > a').click(function(e) {
		alert('yo');
		return false;
		e.preventDefault();
	});

});

//make menu work
function menuShow(menuitem){
	jQuery(".topsub > p.active").stop().removeClass("topsub").hide();
	jQuery(menuitem).next().css("height", "auto").stop().slideDown(500).parent().addClass("topsub");
}

//sifr script
function pageScripts(){
var AkzidenzGroteskBE = {  src: DNN_skinPath + 'AkzidenzGroteskBE.swf' };
sIFR.activate(AkzidenzGroteskBE);
	sIFR.replace(AkzidenzGroteskBE, {
	  selector: 'h1', 
	  wmode: 'transparent', 
	  src:  DNN_skinPath +  'AkzidenzGroteskBE.swf', 
	  css: [ '.sIFR-root {color:#006cb6;}']
	});
}


/*script to flash menu item on hover

//add the brackets around submenu hover //<div class="flasher" style="filter: alpha(opacity=0); ZOOM: 1;"></div>
	var txt;
	jQuery("p.active > a").hover(
		function() {
			txt = jQuery(this).html();
			jQuery(this).prepend("[&nbsp;&nbsp;").append("&nbsp;&nbsp;]").append("<div class='flasher' style='filter: alpha(opacity=0); ZOOM: 1;'></div>");
			jQuery(this).find('.flasher').stop().animate({opacity: .65}, 175, "easeOutSine", function(){
				jQuery(this).fadeOut(100, "easeOutExpo");
			});
		}, 
		function() {
			jQuery(this).find('.flasher').hide().parent().css({'background-position':'0 0'}).css({'font-weight':'normal'}).html(txt);
		}
	);
	*/
	
function DestroyDividers() {
	jQuery('.menu-div:first').remove();
	jQuery('#innermenu').children(":last").remove();
}

function addBullets(el) {
	jQuery(el).each(function() {
		jQuery("<span class='bullety'></span>").insertBefore(jQuery(this));
	});
}


/*jQuery.extend(
	jQuery.expr[':'], 
	{
		port : (
		)
	}
);*/


function popups(bunch, trigs) {
	jQuery(bunch).children().hide();
	jQuery(trigs + " a").each(function() {
		if($(this).hasClass('nontrig')) {
			return;
		} else {
			$(this).addClass('trigger');
		}
	});
	jQuery(".trigger").click(function(e){
		e.preventDefault();
		var _pop = jQuery(this).attr("href");
		var _html = jQuery("#info").find(_pop).html();
		var wid = $(this).attr('width');
		var hei = $(this).attr('hei');
		startOverlay(_html, _pop, wid, hei);
	});	
}

//basic overlay function
//will be used for both the portraits() function (AAOF Awards Program Page)
//and the custom lightbox used on home page
function startOverlay(_html, _pop, wid, hei) {
	var _w = (wid='undefined') ? _w = "750px" : _w = wid+"px";
	var _h = (hei='undefined') ? _h = "600px" : _h = ($("#info").find(_pop).height());	
	jQuery("form")
		.prepend('<div class="overlay"></div><div class="container"></div>');
	jQuery(".overlay").animate({"opacity":"0.6"}, 200, "linear").css({"height" : ($(document).height())});
	jQuery(".container").html(_html);
	var wH = ($(window).height())/2;
	var wW = ($(window).width())/2;
	var mT = wH - (parseInt(_h, 10)/2);
	var mL =  wW - (parseInt(_w, 10)/2);
//	alert("container top: " + $('.container').css('top') + "window height: "+ wH);
	jQuery(".container")
			.css({
				"top":	mT+"px",
				"left":	mL + "px",
				"width": _w,
				"height": _h
/*				"marginTop": mT,
				"marginLeft": mL
*/			})
			.animate({"opacity":"1"}, 200, "linear");
	closePopUp();
}

function closePopUp() {
	jQuery(".closepop, .overlay").click(function(e){
		  e.preventDefault();
		jQuery(".container, .overlay")
		.animate({"opacity":"0"}, 200, "linear", function(){
			//get rid of the lightbox content holders
			jQuery(".container, .overlay").remove();

			//make main content area scrollable again
			jQuery("form").css({"overflow-y":"visible"});
		})
	});
}



function homeAccordion() {
	/*$('.home-accordion .accordion div').each(function() {
		$(this).hide();
	});*/

	$('.accordion h5').click(function() {
		$('.fliparrow').removeClass('fliparrow');
		$(this).children(0).addClass('fliparrow');
		if($('.revealed').length) {
			$('.revealed').slideUp().removeClass('revealed');
			$(this).next().slideDown().addClass('revealed');
		}else {
			$(this).next().slideDown().addClass('revealed');
		}
	});
}

function showExtraBoxes() {
	if($('.currentpage').length) {
	var _title = $('.currentpage').parent().prev().attr("title").toLowerCase();
	_title = _title.split(" ");
	$('#related .box').each(function() {
		//if($(this).hasClass(
		if($(this).hasClass(_title[0])) { 
			$(this).css("display", "block");
		}
	});
	}
}


function addShadow() {
	var _src = $('.stock').attr("src");
	$('.stock').remove();
	$('.sidepic').prepend("<img src='/portals/0/side/shadow.png' class='stock-shadow' /><img src='"+_src+"' class='stock' />");
	$('.stock').show();
	$('.sidepic').fadeIn(400);
}
