function printPage() {
	window.print();
}
$(document).ready(function(){
	if ($(".lnk-more").length > 0){
		$('.lnk-more').each(function(i) {
			var lnkWidth = $(this).width();
			$(this).wrap('<span class="lnk-more-wrapper"></span>');
			$('<span class="lnk-more-shadow"><em></em></span>').insertAfter(this);
			$(this).parent('.lnk-more-wrapper').find('.lnk-more-shadow').width(lnkWidth);
		});
	};
});

$(window).load(function(){
	if ($("#fund-bar").length > 0){
		setTimeout('showFund()', 4000);
	}

});

function showFund(){
	$("#fund-info span em").text(fundValue);

	var fundBarHeight = '361';
        fundValue = fundValue.replace(/[\,\$]/,'');
        maxFundValue = maxFundValue.replace(',','');
	var newfundBarHeightProcent = (fundValue*100)/maxFundValue;
	var newfundBarHeight = (fundBarHeight*newfundBarHeightProcent)/100;
newfundBarHeight = 190; // Setting height to a permanent fixed value
	var arcParamsEnd = (88*newfundBarHeightProcent)/100;

	var arc_params = {
		center: [432,24],
		radius: 557,
		start: 7,
		//end: -76,
		end: endFundBarPos,
		dir: -1
	};

	$('#fund-info').show();
	
	$("#fund-info").animate({path : new $.path.arc(arc_params)},'slow',
		function(){/*alert("all done")*/;}
	);
	$("#fund-bar").animate({ 
		height: newfundBarHeight
	}, 'slow' );
}

/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 

/*
	add accesskey, z-index
*/
this.tooltip = function(){	
	/* CONFIG */
		//xOffset = -23;
		//yOffset = 0;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$("a[title], button[title]").hover(function(e){
		this.t = this.title;
		this.title = "";
		if($(this).attr("accesskey")){
			this.a = 'accesskey: <strong>'+ $(this).attr("accesskey")+'</strong>';
			$("body").append("<span class='tooltip'>"+ this.t + "<em>"+this.a +"</em></span>");
		}
		else {
			$("body").append("<span class='tooltip'>"+ this.t +"</span>");
		}
		var footer = $(this).parents("#footer").text();
		if (footer) {
			xOffset = 23;
			yOffset = 0;
		}
		else {
			xOffset = -23;
			yOffset = 0;
		}
		$(".tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css("opacity","0.9")
			.css("z-index","999999999")
			.fadeIn("slow");
	},
	function(){
		this.title = this.t;
		$(".tooltip").remove();
	});
	$("a[title], button[title]").mousemove(function(e){
		
		var footer = $(this).parents("#footer").text();
		if (footer) {
			xOffset = 23;
			yOffset = 0;
		}
		else {
			xOffset = -23;
			yOffset = 0;
		}
		$(".tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});
$(document).ready(function(){
	$("a[title] img").title = "";
});

//$(document).ready(function(){
//	$(".tv .bookmarks li a").click(function(){
//		$(".tv .bookmarks .active").removeClass("active");
//		$(this).parent().addClass("active");
//
//		var element_index = $(".tv .bookmarks a").index(this);
//
//		$(".tv .tv-content div.video:visible").fadeOut('200',
//		function(){
//			$(".tv .tv-content div.video").eq(element_index).fadeIn('200');
//		});
//		return false;
//	});
//});
$(function() {
	$(".list-1 li:last-child").addClass("last");
	$(".list-2 li:last-child").addClass("last");
	$(".list-3 li:last-child").addClass("last");
	$(".list-5 li:last-child").addClass("last");
	$(".quotes-list .content-row:last-child").addClass("last");
	$(".foundation-contact dd:last-child").addClass("last");
	$(".lifeboat-fund .lifeboat-fund-list li:last-child").addClass("last");
	$(".lifeboat-fund-list-1 li:last-child").addClass("last");
});

//jQuery Plugin: Drop Shadow Text
(function($) {
$.fn.textDropShadow = function(){
	$(this).html('<span class="jq-shadow">'+$(this).html()+'</span><span>'+$(this).html()+'</span>');
	return $(this);
}
})(jQuery);

// drop shadow
$(function() {
	$('.alphabetical-order ul li a').each(function(){$(this).textDropShadow();});
	$('#wrapper-content .lifeboat-fund-value h4 strong em').each(function(){$(this).textDropShadow();});
});

$(document).ready(function(){
	$('.box').each(function(i) {
		var boxHeight = ($(this).height())/2;
		var boxContent = $('.box-body');
		$('<div class="box-footer"></div>').insertBefore(boxContent);
		$(this).find('.box-footer').height(boxHeight);
	});
});

$(document).ready(function(){
	$('.box2').each(function(i) {
		var boxHeight = ($(this).height())/2;
		var boxContent = $('.box-body');
		$('<div class="box-footer"></div>').insertBefore(boxContent);
		$(this).find('.box-footer').height(boxHeight);
	});
});

function changeLocation(){ 
	window.location.href = $('#archival-issues-select').jcSelected();
}

function changed_pay_period_innerHTML(){
txt = document.getElementById("membership_type").innerHTML;

if (document.OrderForm.pay_period.value == "Pay monthly")
{
 txt = txt.replace(/Economy[^"<]+/g,'Economy - $10/month');
 txt = txt.replace(/Executive[^"<]+/g,'Executive - $25/month');
 txt = txt.replace(/First Class[^"<]+/g,'First Class - $50/month');
 txt = txt.replace(/LF 500[^"<]+/g,'LF 500 - $85/month');
 txt = txt.replace(/Patron[^"<]+/g,'Patron - $200/month');
}

if (document.OrderForm.pay_period.value == "Pay quarterly")
{
 txt = txt.replace(/Economy[^"<]+/g,'Economy - $30/quarter');
 txt = txt.replace(/Executive[^"<]+/g,'Executive - $75/quarter');
 txt = txt.replace(/First Class[^"<]+/g,'First Class - $150/quarter');
 txt = txt.replace(/LF 500[^"<]+/g,'LF 500 - $255/quarter');
 txt = txt.replace(/Patron[^"<]+/g,'Patron - $600/quarter');
}

if (document.OrderForm.pay_period.value == "Pay yearly")
{
 txt = txt.replace(/Economy[^"<]+/g,'Economy - $120/year');
 txt = txt.replace(/Executive[^"<]+/g,'Executive - $300/year');
 txt = txt.replace(/First Class[^"<]+/g,'First Class - $600/year');
 txt = txt.replace(/LF 500[^"<]+/g,'LF 500 - $1,000/year');
 txt = txt.replace(/Patron[^"<]+/g,'Patron - $2,400/year');
}

if (document.OrderForm.pay_period.value == "Pay 2 years")
{
 txt = txt.replace(/Economy[^"<]+/g,'Economy - $240/2 years');
 txt = txt.replace(/Executive[^"<]+/g,'Executive - $600/2 years');
 txt = txt.replace(/First Class[^"<]+/g,'First Class - $1,200/2 years');
 txt = txt.replace(/LF 500[^"<]+/g,'LF 500 - $2,000/2 years');
 txt = txt.replace(/Patron[^"<]+/g,'Patron - $4,800/2 years');
}

if (document.OrderForm.pay_period.value == "Pay 5 years")
{
 txt = txt.replace(/Economy[^"<]+/g,'Economy - $600/5 years');
 txt = txt.replace(/Executive[^"<]+/g,'Executive - $1,500/5 years');
 txt = txt.replace(/First Class[^"<]+/g,'First Class - $3,000/5 years');
 txt = txt.replace(/LF 500[^"<]+/g,'LF 500 - $5,000/5 years');
 txt = txt.replace(/Patron[^"<]+/g,'Patron - $12,000/5 years');
}

if (document.OrderForm.pay_period.value == "Pay 10 years")
{
 txt = txt.replace(/Economy[^"<]+/g,'Economy - $1,200/10 years');
 txt = txt.replace(/Executive[^"<]+/g,'Executive - $3,000/10 years');
 txt = txt.replace(/First Class[^"<]+/g,'First Class - $6,000/10 years');
 txt = txt.replace(/LF 500[^"<]+/g,'LF 500 - $10,000/10 years');
 txt = txt.replace(/Patron[^"<]+/g,'Patron - $24,000/10 years');
}

document.getElementById("membership_type").innerHTML = txt;
selected_txt = txt.match(/class=['"]?current['"]?[^>]+rel=["'][^"']+/)
//if (selected_txt == null) {alert('problem with '+txt)}
selected = selected_txt[0];
selected = selected.replace(/.*["']/,'');
$('#membership_type').jcEdit(selected,selected);

}

function replaceSelectImage(){
	
	var documentBody = $("body");
	
	if (documentBody.hasClass('black')){
		$('.opera, .opera span').css('background-image', 'url(/images/themes/black/opera.black.gif)');
		$('.opera-hover, .opera-hover span').css('background-image', 'url(/images/themes/black/opera_hover.black.gif)');
	}
	else if (documentBody.hasClass('white')){
		$('.opera, .opera span').css('background-image', 'url(/images/themes/white/opera.white.gif)');
		$('.opera-hover, .opera-hover span').css('background-image', 'url(/images/themes/white/opera_hover.white.gif)');

	}
	
}
function replaceInputFileImage(){
	
	var documentBody = $("body");
	
	if (documentBody.hasClass('black')){
		$(".file-wrapper div").css('background-image', 'url(/images/themes/black/button_browse.png)');
		$(".file-wrapper .hover").css('background-image', 'url(/images/themes/black/button_browse_hover.png)');
	}
	else if (documentBody.hasClass('white')){
		$(".file-wrapper div").css('background-image', 'url(/images/themes/white/button_browse.png)');
		$(".file-wrapper .hover").css('background-image', 'url(/images/themes/white/button_browse_hover.png)');
	}
	
}

$(document).ready(function(){
	if ($("select").length > 0){
		$('#donation_purpose').jcombox({ theme: 'opera', set: true});
		$('#membership_type').jcombox({ theme: 'opera', set: true});
//		$('#pay_period').jcombox({ theme: 'opera', set: true, fn: changed_pay_period });
		$('#pay_period').jcombox({ theme: 'opera', set: true, fn: changed_pay_period_innerHTML });
		$('#country').jcombox({ theme: 'opera', set: true});
		$('#type_of_support').jcombox({ theme: 'opera', set: true});
a = document.getElementById('cc_type');
if (typeof a !="undefined" && a !=null)
{$('#cc_type').jcombox({ theme: 'opera', set: true, fn: display_credit_card_info });}
//		$('#cc_type').jcombox({ theme: 'opera', set: true});
		$('#cc_expiration_date_month').jcombox({ theme: 'opera', set: true});
		$('#cc_expiration_date_year').jcombox({ theme: 'opera', set: true});
		$('#archival-issues-select').jcombox({ theme: 'opera', set: true, /*fx: 'slide',*/ fn: changeLocation});
		$('#membership-type-select').jcombox({ theme: 'opera', set: true});
		$('#membership-type-pay-select').jcombox({ theme: 'opera', set: true});
		$('#one-time-extra-gift-select').jcombox({ theme: 'opera', set: true});
		$('#country-select').jcombox({ theme: 'opera', set: true});
		$('#payment-type-select').jcombox({ theme: 'opera', set: true});
		$('#exp-date-month-select').jcombox({ theme: 'opera', set: true});
		$('#exp-date-year-select').jcombox({ theme: 'opera', set: true});
	}
});
$(function() {
	//if(!($.browser.ie)) {
		var zIndexNumber = 1000000;
		$(".opera").each(function() {
				$(this).css('zIndex', zIndexNumber);
				zIndexNumber -= 10;;
		});
	//}
});
$(function() {
	if(!($.browser.ie)) {
		if ($("input.file").length > 0){
			var imgSrc = '/images/themes/black/button_browse.png';
			var documentBody = $("body");
			if (documentBody.hasClass('white')){
				var imgSrc = '/images/themes/white/button_browse.png';
			}
// Following two lines get rid of errors on secure pages with IE
var str = window.location.href; str = str.replace(/\.com\/.*/,'.com');
imgSrc = str + imgSrc;
			$("input.file").filestyle({ 
				image: imgSrc,
				imageheight : 28,
				imagewidth : 68,
				width : 178
			});
			$('.file-wrapper div').mouseover(function() {
				$(this).addClass('hover');
			});
			$('.file-wrapper div').mouseout(function() {
				$(this).removeClass('hover');
			});
		}
	}
});
$(window).load(function(){
	var img = $('.img-box');
	$.each(img, function() {
		var classname = $(this).attr("class");
		$(this).wrap('<div class="photo-img-box '+classname+'">'+ '</div>');
	});
	replaceImgBox();


});

function replaceBWImages(){
// First code to fix specific situations, then all links, then code to 
// replace images with class bw

	var links = $('.whitehover a');
	$.each(links, function() {
		var documentBody = $("body");
		if (documentBody.hasClass('black')){
$(this).attr("style","color: #ffffff;");
		}
		else if (documentBody.hasClass('white')){
$(this).attr("style","color: #000000;");
	}
        });

a = document.getElementById('amazon_paybox');
if (typeof a !="undefined" && a !=null)
{
 var documentBody = $("body");
 if (documentBody.hasClass('white'))
 {a.style.backgroundImage='url(/images/themes/white/amazon.white.png)';}
 else
 {a.style.backgroundImage='url(/images/themes/black/amazon.black.png)';}
}

a = document.getElementById('amazon_paybox2');
if (typeof a !="undefined" && a !=null)
{
 var documentBody = $("body");
 if (documentBody.hasClass('white'))
 {a.style.backgroundImage='url(/images/themes/white/amazon2.white.png)';}
 else
 {a.style.backgroundImage='url(/images/themes/black/amazon2.black.png)';}
}

a = document.getElementById('paypal_paybox');
if (typeof a !="undefined" && a !=null)
{
 var documentBody = $("body");
 if (documentBody.hasClass('white'))
 {a.style.backgroundImage='url(/images/themes/white/paypal.white.png)';}
 else
 {a.style.backgroundImage='url(/images/themes/black/paypal.black.png)';}
}

if (typeof lastpage!="undefined" && lastpage !=null)
{
 var documentBody = $("body");
 if (documentBody.hasClass('white'))
 {lastpage.style.backgroundColor='#EAEAEA';}
 else
 {lastpage.style.backgroundColor='#4A4A4A';}
}
	var string = "";

	var img = $('a');
	$.each(img, function() {
		var documentBody = $("body");
		if (documentBody.hasClass('black')){
string = $(this).attr("href");
if (string && string.indexOf("background") >= 0)
 {
  string = string.replace("?background=white&", "?"); 
  string = string.replace("?background=white", ""); 
  $(this).attr("href", string);
 }
}
});

	var img = $('.bw');
	$.each(img, function() {
		var documentBody = $("body");
		if (documentBody.hasClass('black')){
string = $(this).attr("src");
string = string.replace("/white/", "/black/"); 
string = string.replace("white.png", "black.png"); 
string = string.replace("white.jpg", "black.jpg"); 
$(this).attr("src", string);
		}
		else if (documentBody.hasClass('white')){
string = $(this).attr("src");
string = string.replace("/black/", "/white/"); 
string = string.replace("black.png", "white.png"); 
string = string.replace("black.jpg", "white.jpg"); 
$(this).attr("src", string);
	}
        });
}

function replaceImgBox(){
	
	var img = $('.img-box');
	$.each(img, function() {
		//var imgWidth = $(this).width()+2;
		
		var documentBody = $("body");
		if (documentBody.hasClass('black')){
			var imgWidth = $(this).width()+2;
		}
		else if (documentBody.hasClass('white')){
			var imgWidth = $(this).width();
	}
		
		if($(this).parents().hasClass('aligncenter')){
			$(this).parents('.aligncenter').attr('style','width:'+imgWidth+'px');
		}
		else if($(this).parents().hasClass('alignright')){
			$(this).parents('.alignright').attr('style','width:'+imgWidth+'px');
		}
		else if($(this).parents().hasClass('alignleft')){
			$(this).parents('.alignleft').attr('style','width:'+imgWidth+'px');
		}
	});
	
}

// jQuery Simple Drop-Down Menu Plugin
// http://javascript-array.com/scripts/jquery_simple_drop_down_menu/
$(function() {
	
	var timeout         = 800;
	var closetimer		= 50;
	var ddmenuitem      = 0;

	function jsddm_open(){
		jsddm_canceltimer();
		jsddm_close();
		ddmenuitem = $('#sitemap-menu').css('visibility', 'visible');
		$('.sitemap-lnk').parent('li').addClass('hover2');
	}

	function jsddm_close(){
		if(ddmenuitem){
			ddmenuitem.css('visibility', 'hidden');
			$('.sitemap-lnk').parent('li').removeClass('hover2');
		}
	}

	function jsddm_timer()
	{	closetimer = window.setTimeout(jsddm_close, timeout);}

	function jsddm_canceltimer()
	{	if(closetimer)
		{	window.clearTimeout(closetimer);
			closetimer = null;}}

	$(document).ready(function()
	{	$('.sitemap-lnk, #sitemap-menu').bind('mouseover', jsddm_open);
		$('.sitemap-lnk, #sitemap-menu').bind('mouseout',  jsddm_timer);});

	document.onclick = jsddm_close;

});

jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
};
$(function() {
	$.preloadImages("/images/themes/white/button_browse.png", "/images/themes/white/button_browse_hover.png","/images/themes/white/opera.white.gif","/images/themes/white/opera_hover.white.gif");
	$.preloadImages("/images/themes/black/button_browse.png", "/images/themes/black/button_browse_hover.png","/images/themes/black/opera.black.gif","/images/themes/black/opera_hover.black.gif");
});
