function oc(a) {
	var o = {};
	for(var i=0;i<a.length;i++){o[a[i]]='';
	}
	return o;
}

$(function() {

	$(document).keyup(function(event){
	
		if (event.keyCode == 27) {
		
			try{
				$("#overlay").fadeOut("slow", function(){
					$(this).remove();
				});

				$("#contact_overlay").fadeOut("slow", function(){
					$(this).remove();
				});
			}catch(e){}
				
		}
	
	});
	
	$("a.drop").live("click", function(){
	
		if ($(this).next("ul").is(':visible')){
			$(".interior #content.nav ul.nav li ul").hide();		
		}else{
			$(".interior #content.nav ul.nav li ul").hide();	

			$(this).next("ul").show();

			return false;
		}
				
	});
	
	$("a.close").live("click", function(){

			try{
				$("#overlay").fadeOut("slow", function(){
					$(this).remove();
				});

				$("#contact_overlay").fadeOut("slow", function(){
					$(this).remove();
				});
			}catch(e){}
	
	});

	/* CONTACT FORM */
	$("a.contact").live("click", function(){
	
		var url = $(this).attr("href");
		
		$.ajax({
			type: "POST",
			url: url,
			data: "",
			success: function(data){
					
				var winW = $(window).width();
						
				$("body").append(data);
						
				var w = $("#contact_overlay").width();
					
				$("#contact_overlay").css('left', winW/2-w/2).fadeIn("slow");
						
				$("#overlay").fadeIn("slow");
						
				$.scrollTo(0, 400);
			}
		});
			
		return false;
	
	});

	/* MAIN NAV DROPDOWNS */
	$("#header > ul > li").hover(
		function(){
			$(this).removeClass("hide");
			$(this).siblings().addClass("hide");
			$(this).children("ul").show();
		},
		function(){
			if (!$(this).hasClass("active"))
			{
				$(this).children("ul").hide();
			}
		}
	);

	$("#header").mouseleave(function(){
		$("#header li.active").removeClass("hide").children("ul").show();
	});

	// CLEAR SEARCH BOXES
	$('.default').each(function() {
		var default_value = this.value;
		$(this).focus(function() {
			if(this.value == default_value) {
			this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
			this.value = default_value;
			}
		});
	});

	$('a.thickbox').colorbox({transition:'fade', speed:500});

	// OPEN EXTERNAL LINKS IN A NEW WINDOW
	$('a').click(function() {
		try {
			domain = $(this).attr("href").match(/:\/\/(.[^/]+)/)[1];
			exceptions = new Array('techventures.org');
			if(domain in oc(exceptions)){}
			else{ window.open($(this).attr("href"));
				return false;
			}
		}
		catch(e){}
	});
	
	try{
		$('.columns ul').columnize({columns:2, lastNeverTallest: true});
		$('.columns-three ul').columnize({columns:3, lastNeverTallest: true});
	}catch(e){}

});