the_selected_id = "none";
var already_clicked = false;

function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
	var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
	var int_windowTop = (screen.height - a_int_windowHeight) / 2;
	var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
	var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties);
	if (parseInt(navigator.appVersion) >= 4) {
		obj_window.window.focus();
	}
}
		
//checks for a valid zip code
function CheckValidZip(thefield) {
	var filter = /^([0-9]{5})+$/;
	if (!filter.test(thefield)) {
		$("#signupalert").html("Please enter a valid zip code"); 
		return false; }
	else if (thefield==null || thefield==""){
		$("#signupalert").html("Please enter a zip code");
		return false;
	}
	return true;					
}

//checks for a valid email address   
function CheckEmailAddr(thefield) {
	var filter  = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(thefield)) {
		$("#signupalert").html("Please enter a valid email address");
		return false; }
	else if (thefield==null||thefield==""){
		$("#signupalert").html("Please enter an email address!");
		return false;
	}
	return true;		
}

function calcage(secs, num1, num2) {
	s = ((Math.floor(secs/num1))%num2).toString();
	//if (s.length < 2) s = "0" + s;
  return s;
}

jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}


function SBM_CountDown(){

	Deadline = "12/18/2007 10:30 AM EST"; //midnight is considered to occur the following day
	then = new Date(Deadline);
	now = new Date();
	secondsleft = (new Date(then-now)) / 1000;
	//$('#SBMdays').html( calcage(secondsleft,86400,100000) );
	$('#SBMhours').html( calcage(secondsleft,3600,24) );
	$('#SBMminutes').html( calcage(secondsleft,60,60) );
	$('#SBMseconds').html( calcage(secondsleft,1,60) );
	
	setTimeout("SBM_CountDown()",1000);

}


$(document).ready(function() {

	$.preloadImages("http://www.stopbigmedia.com/graphics/n_whatsatstake_h.gif",
					"http://www.stopbigmedia.com/graphics/n_getinvolved_h.gif",
					"http://www.stopbigmedia.com/graphics/n_policy_h.gif",
					"http://www.stopbigmedia.com/graphics/n_whoowns_h.gif",
					"http://www.stopbigmedia.com/graphics/n_donate_h.gif",
					"http://www.stopbigmedia.com/graphics/wall_add_o.gif",
					"http://www.stopbigmedia.com/graphics/wall_tell_o.gif",
					"http://www.stopbigmedia.com/graphics/wall_sign_o.gif");

	$("#sectionnav a").prepend("&raquo;&nbsp;");

	$("#signupsubmit").hover( function() {
		$(this).addClass("submithover");
	}, function() {
		$(this).removeClass("submithover");
	});

	$("#signup form input").focus(function() {
 		if ($(this).val() == "email address" || $(this).val() == "zip") $(this).val("");
 	});

 	$("#addme").submit(function() {
 		
 		$("#homelink").hide();
 		
		if (!CheckEmailAddr($("#email").val()) || !CheckValidZip($("#zipcode").val())) {
			$("#signup #mesg").fadeOut("fast", function(){
				$("#signup #mesg").html("Please enter a valid email address and/or zip code!");
				$("#signup #mesg").fadeIn("normal");
			});

			
		} else {
	
		//else, do ajax thing
		$.post("/ajax/signup.php", { email:$("#email").val(), zipcode:$("#zipcode").val(), submitted:"yes", set_sbm:"t", set_ea:"t" }, function(data) {
			if (data == "1") {
				$("#signup #mesg").fadeOut("fast", function(){
					$("#addme").fadeOut("fast");
					$("#signup").css("background-color","#eee");
					$("#signup #mesg").html("<b>Thanks for signing up for updates from StopBigMedia.com!</b> We've added you to our email list. (Don't forget to review <a href=\"http://www.freepress.net\">our privacy policy</a>)");
					$("#signup #mesg").fadeIn("normal");
				});	
			} else {
				$("#signup #mesg").fadeOut("fast", function(){
					$("#signup #mesg").html("Sorry, an error occurred. Please try again!");
					$("#signup #mesg").fadeIn("normal");
				});
			}}	
		);
		} //end else
		
	});
	
	$(".actbox").hover(function(){
		$(this).addClass("acthover");
	},function(){
		$(this).removeClass("acthover");
	});
	
	$(".actbox").click(function(){
		window.location = $(this).children("a:first").attr("href");
	});
	
	$("#sbm_logo").click(function(){
		window.location = "http://www.stopbigmedia.com/";
	});
	
	$('#navbar img').hover(function(){
		if ($(this).attr('id') != the_selected_id) $(this).attr('src','http://www.stopbigmedia.com/graphics/n_'+$(this).attr('id')+"_h.gif");
 	}, function() {
		if ($(this).attr('id') != the_selected_id) $(this).attr('src','http://www.stopbigmedia.com/graphics/n_'+$(this).attr('id')+".gif");
 	});	

	$('#threelinks img').hover(function(){
		$(this).attr('src','http://www.stopbigmedia.com/graphics/'+$(this).attr('id')+"_o.gif");
 	}, function() {
		$(this).attr('src','http://www.stopbigmedia.com/graphics/'+$(this).attr('id')+".gif");
 	});	

	$("a#minoritydetails").click(function() {
		$("#explanation").fadeIn("normal");
	});

	$("#explanation").click(function() {
		$("#explanation").fadeOut("fast");
	});
	
	$("#tracklist a:even").addClass("dark");
	
	//SBM_CountDown();
});

/*
$(window).load(function() {
	setTimeout('$("#sectionnav table").fadeIn("slow")',1000);
});
*/