// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


addthis_pub  			= 'cooltheearth';
addthis_logo_background = 'E3E1E8';
addthis_logo_color      = '858B6F';
addthis_brand           = 'Cool The Earth';
addthis_options         = 'favorites, email, digg, delicious, myspace, facebook, google, live, more';
addthis_offset_top 		= -15;
addthis_offset_left		= -120;

jQuery(document).ready(function() {
	jQuery("#sign_in.loggedout h3").bind("click", function(e){
		jQuery("#sign_in").addClass("open")
		jQuery("#sign_in div.form").stop().animate({top: "0"}, 125, function(){
			jQuery("#login").focus();
		})
	})
	jQuery("#sign_in").bind("click", function(e){
		if (!e) var e = window.event;
		e.cancelBubble = true;
		e.stopPropagation();
	});
	jQuery("div#sign_in ul").css("visibility", "visible");
	jQuery("#close_sign_in a").bind("click", function(){
		if(jQuery("#sign_in").hasClass("open"))
		jQuery("body").triggerHandler("click");
		else
		jQuery("#sign_in h3").triggerHandler("click");
		return false;
	})
	jQuery("body").bind("click", function(){
		jQuery("#sign_in.loggedout").removeClass("open")
		jQuery("#sign_in.loggedout div.form").stop().animate({top: "-61px"}, 125)
	})

	shadeForm();
	shadeTable();
	
	jQuery("#ftr_info a").attr("target", "_blank");
	jQuery("#donate_today").bind("click", function(){
		var donatewin = window.open(jQuery(this).attr("href"),"donatewindow","height=800,width=780,scrollbars=1,location=1,toolbar=1,resizable=1");
		return false;
	})
	
	// disabling ajax call, and doing this via rails now - EAB
	//rand = Math.floor(Math.random()*20);
	//jQuery("#top_featured-action .pad").load("/action-coupons/featuredactions ul.dotted:eq("+rand+")")
	
    // jQuery("#hdr_nav li").hover(
    //     function(){ jQuery("ul", this).fadeIn("fast"); }, 
    //     function() { } 
    // );
	if(jQuery("#faqlist").length > 0){
		if(document.location.href.split("#").length > 1)
		jumpLocation(document.location.href.split("#")[1]);
		jQuery("#faqlist a").bind("click", function(){
			jQuery("h3.highlighted").removeClass("highlighted")
			return jumpLocation(jQuery(this).attr("href").split("#")[1]);
		})
		jQuery("h3 span a").bind("click", function(){
			return jumpLocation("faqlist");
		})
	}
	var t = setTimeout("jQuery('#bg_opt').height(jQuery(document).height())", 1000); 
	
});
function jumpLocation(itemid){
	jQuery("#"+itemid).addClass("highlighted")
	newtop = jQuery("#"+itemid).offset();
	jQuery('html,body').animate({scrollTop: newtop.top+"px"});
	return false;
}


function shadeForm(){
	jQuery("ul.form_2_col li:odd").addClass("shade");
}
function shadeTable(){
	jQuery("table.listing tr:odd").addClass("shade");
}

// jQuery.fn.hoverClass = function(c) {
//     return this.each(function(){
//         jQuery(this).hover( 
//             function() { jQuery(this).addClass(c);  },
//             function() { jQuery(this).removeClass(c); }
//         );
//     });
// }; 


try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

/*
sfHover = function() {
	var sfEls = document.getElementById("hdr_nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
	   sfEls[i].onmouseover=function() {
	       this.className+=" sfhover";
	   }
	   sfEls[i].onmouseout=function() {
	       this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
	   }
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
*/

function toggle_state(id) {
	$("statelist").hide();
	$("provincelist").hide();
	$("other").hide();
	$(id).show();
}

function get_id_from_country(country,default_id) {
	if (default_id > 0) {
		country_id = default_id;
	} else {
		country_id = document.getElementById('user_country_id').value;
	}
	if (country_id == country['USA']) {
	 return "statelist";
	} else if (country_id == country['CANADA']) {
	 return "provincelist";
	} else {
	 return "other";
	}
}

