function oc(a)
{
	var o = {};
	
	for(var i=0;i<a.length;i++){o[a[i]]='';}
	return o;
}

function buildExternal(){

	$('a').each(function(){
		try{
			domain = $(this).attr("href").match(/:\/\/(.[^/]+)/)[1];
			
			exceptions = new Array('www.angelesarrien.com','angelesarrien.com');
			
			/* OPEN PDFS AND EXTERNAL LINKS IN NEW WINDOW */
			if((domain in oc(exceptions)) || ($(this).attr("href").indexOf('.pdf') !== -1)){}else{
				$(this).addClass('extlink').attr("title","opens in external window");		

				$(this).unbind('click').bind('click',function(){
					window.open($(this).attr("href"));
					
					return false;		
				});
			}
		}catch(e){}		
	});
	
	$("a[href*=.pdf]").prepend('<img src="http://www.angelesarrien.com/new_temp/images/pdf_icon.gif" class="pdf" />');
}

$(function() {

	// BULD EXTERNAL LINKS
	buildExternal();

	// MAIN NAV DROPDOWNS
	var config = {    
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		interval: 90, // number = milliseconds for onMouseOver polling interval
		over: makeTall, // function = onMouseOver callback (REQUIRED)
		timeout: 200, // number = milliseconds delay before onMouseOut
		out: makeShort // function = onMouseOut callback (REQUIRED)
	};
	$("#nav > li").hoverIntent(config);
	$("ul#nav li ul li").hoverIntent(config);

	// NEW WINDOW(S) FOR ON-SITE FILES
	$("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});
	$("a[href*=.gif]").click(function(){
		window.open(this.href);
		return false;
	});
	$("a[href*=.jpg]").click(function(){
		window.open(this.href);
		return false;
	});
	$("a[href*=.png]").click(function(){
		window.open(this.href);
		return false;
	});

	// TABLE SORT
	$("#tableSort").tablesorter({
		sortList: [[1,1]], 
		widthFixed: true,
		widgets: ['zebra']
	}).tablesorterPager({container: $("#pager")});

	// ALTERNATE TABLE ROW COLORS
	$('table.gray tr:odd').addClass('odd');
	$('table.gray tr:even').addClass('even');

	// AJAX CALENDAR
	loadcal();
	
	$("ul#sitemap").columnize({columns:2}); 
	
	$("#toTop").click(function(){
		$.scrollTo(0, 400);
		return false;
	});

});

function loadcal() {
	$("#prevcal, #nextcal").unbind("click").bind("click", function() {
	$("#calendarWrap").load($(this).attr("href"), function() {loadcal();});
	return false;
	});
}

function makeTall(){ 
	$(this).addClass('over');
}
function makeShort(){
	$(this).removeClass('over');
}
