jQuery(document).ready(
	function(){
		// activate countdown for any appropriately classed divs
		jQuery("div.ehcountdown").each(function(i, elem) {
			var show_seconds = jQuery(this).hasClass("ehcountdown_seconds");
			var ec = new ehcountdown.
				EarthHourCountdown(show_seconds, "fast");
			ec.addTo(jQuery(this));
			ec.start(); // start the auto-update
		});
		
		// if this variable is set, the lightbox will load immediately
		// on loading the page
		if(typeof eh_autoLoadSignupLightbox == "undefined")
			eh_autoLoadSignupLightbox = false;

		minWidthForModal = 800
		signup_ajax="/signup/signup_lightbox.jsp"
		boolUseModal = (jQuery(window).width()>minWidthForModal ? true : false );
		if (boolUseModal)
		jQuery("a").filter(function(){
			if (jQuery(this).attr("href")!=undefined){
				return jQuery(this).attr("href").match(/(signup\/?)($|\?.*)/)
			}
			else {return false;}
			}).each(function(i,elem){
				ajaxURL(i,elem); jQuery(elem).colorbox({
			innerWidth: "780px",
			onComplete: function() {
				// trigger the handling code for whatever form we have just loaded
				eval("signupform_" + jQuery("#form_formChanger").val() + "()");
				// resize after above func has messed around
				jQuery.colorbox.resize();
				// when the form contents change, resize colorbox
				signupform_utils.formChangeCallback = function() { jQuery.colorbox.resize(); };
			},
			title: " ", // always ignore anchor titles
			open: eh_autoLoadSignupLightbox,
			overlayClose: false });
			// only set open for the first colorbox
			eh_autoLoadSignupLightbox = false; })
	}
)

function ajaxURL(i,elem){

    // if there is a query string in the main URL of this page visit, we want to
    // replicate it verbatim to the lightbox, because it might contain
    // prepopulation code.
    var qsindex = window.location.href.indexOf("?");
    if( qsindex >= 0) {
	// remove unsafe characters from the URL because this will go into the HTML
	href=signup_ajax + (window.location.href.substring(qsindex).replace(/#.*$/,"").replace(/[^A-Za-z0-9&?=%@._]/g,""));
    } else {
	href=jQuery(elem).attr("href")
	if (href.indexOf('?')!=-1){
	    qs=href.slice(href.indexOf('?'))
	    href=signup_ajax+qs
	}
	else{href=signup_ajax;}
    }
    jQuery(elem).attr("href",href);
}

