$(function(){
	var loginVisible = 0;
	$(".loginlink a").click(function(e){
		e.preventDefault();
		//alert(boardurl);
		$("#loginBox").remove();
		$("body").append('<div id="overlay" /><div id="loginBox" />');
		
		$("#loginBox").load(boardurl+'index.php?action=login #frmLogin',function(){
			$("#overlay").fadeTo(500,0.8);
			$(this).slideDown(750);
			$(this).append('<a class="close" href="#">Close</a>');
			loginVisible = 1;
			$("#loginBox .close").click(function(e){
				e.preventDefault();
				$("#overlay").fadeTo(250,0,function(){
					$(this).remove();
				});
				$("#loginBox").slideUp(500,function(){
					$(this).remove();
					loginVisible = 0;
				});
			});
		});
	});
	// detect if clicking outside of popup
	$(document).click(function(e){
		var target = getEventTarget(e);
		if(target.id == "overlay"){
			if(loginVisible==1){
				$("#overlay").fadeTo(250,0,function(){
					$(this).remove();
				});
				$("#loginBox").slideUp(500,function(){
					$(this).remove();
					loginVisible = 0;
				});
			}
		}
	});
	
	
	$("#breadcrumb form#search_form").find("input.button_submit").hide();
	$("#breadcrumb form#search_form").append('<span class="button_submit"><span></span></span>');
	
	$("form#search_form input.input_text").focus(function(){
		if($(this).attr("value")=="Search..."){
			$(this).attr("value","");
		}
	});
	$("form#search_form input.input_text").blur(function(){
		if($(this).attr("value")==""){
			$(this).attr("value","Search...");
		}
	});
	
	$("#breadcrumb span.button_submit").click(function(e){
		e.preventDefault;
		if(
			$("input.input_text").attr("value")==""|
			$("input.input_text").attr("value")=="Search..."){
			return false;
		}else{
			$("input.button_submit").click();
		}
	});
	$(".button_submit").mousedown(function(e){
		if(!$(this).hasClass("grad1")){
			$(this).addClass("grad1");
		}
	});
	$(".button_submit").mouseup(function(e){
		if($(this).hasClass("grad1")){
			$(this).removeClass("grad1");
		}
	});
});



// target id detection from http://jsbin.com/eqeto3/edit
function getEventTarget(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}
