function toggleTRNav( el, obj ) {
	if ( jQuery(el).css('background-image') == 'url("../images/rfl12/rcol/rfl_rcol_closed.jpg")' ) {
		jQuery('#btn-my-relay, #btn-more-event-info').css('background-image', 'url("../images/rfl12/rcol/rfl_rcol_closed.jpg")');
		jQuery(el).css('background-image', 'url("../images/rfl12/rcol/rfl_rcol_open.jpg")');
		jQuery('#trnav2, #trnav1').hide();
		jQuery(obj).show();
	} else {
		jQuery('#btn-my-relay, #btn-more-event-info').css('background-image', 'url("../images/rfl12/rcol/rfl_rcol_open.jpg")');
		jQuery(el).css('background-image', 'url("../images/rfl12/rcol/rfl_rcol_closed.jpg")');
		jQuery('#trnav2, #trnav1').show();
		jQuery(obj).hide();
	}
}

/* BEGIN DONATE SCRIPT */
function setTeamSearch ( checked ) { setParticipantSearch(checked == false); };
function setParticipantSearch ( checked ) { setSearchMode(jQuery('#s_tr_part_finder_search_mode').val()); };

function setSearchMode ( mode ) {
	if ( jQuery('#fr_search_type_team').get(0) && jQuery('#fr_search_type_team').get(0).checked ) {
		if ( !jQuery('#searchTeam').val() ) {
			jQuery('#searchTeam').val(jQuery('#searchTeam').defaultValue);
		}
		jQuery('#fnameSearchRow, #lnameSearchRow').hide();
		jQuery('#teamSearchRow').show();
		if ( jQuery('#searchFirstName').get(0) ) {
			if ( !jQuery('#searchLastName').val() ) { jQuery('#searchLastName').val(jQuery('#searchLastName').defaultValue); }
		}
		if ( jQuery('#searchLastName').get(0) ) {
			if ( !jQuery('#searchLastName').val() ) { jQuery('#searchLastName').val(jQuery('#searchLastName').defaultValue); }
		}
	} else {
		jQuery('#fnameSearchRow, #lnameSearchRow').show();
		jQuery('#teamSearchRow').hide();
		if ( !jQuery('#searchFirstName').val() ) { jQuery('#searchFirstName').val(jQuery('#searchFirstName').defaultValue); }
		if ( !jQuery('#searchLastName').val() ) { jQuery('#searchLastName').val(jQuery('#searchLastName').defaultValue); }
		if ( jQuery('#searchTeam').get(0) ) {
			if ( !jQuery('#searchTeam').val() ) { jQuery('#searchTeam').val(jQuery('#searchTeam').defaultValue); }
		}
	}
};

function checkForGoodSearchCriteria () {
	if ( jQuery('input[name="fr_search_type"]').get(0).checked ) {
		jQuery('#searchTeam').val('');
	} else {
		jQuery('#searchFirstName').val('');
		jQuery('#searchLastName').val('');
	}
	//check if the search form has any default values, and if so, clear them before submitting
	if (jQuery('#searchTeam').val() == jQuery('#searchTeam').get(0).defaultValue) jQuery('#searchTeam').val('');
	if (jQuery('#searchFirstName').val() == jQuery('#searchFirstName').get(0).defaultValue) jQuery('#searchFirstName').val('');
	if (jQuery('#searchLastName').val() == jQuery('#searchLastName').get(0).defaultValue) jQuery('#searchLastName').val('');
	return true;
};

function checkForGoodMobileSearchCriteria () {
	//check if the search form has any default values, and if so, clear them before submitting
	if (jQuery('#searchTeam').val() == jQuery('#searchTeam').get(0).defaultValue) jQuery('#searchTeam').val('');
	if (jQuery('#searchFirstName').val() == jQuery('#searchFirstName').get(0).defaultValue) jQuery('#searchFirstName').val('');
	if (jQuery('#searchLastName').val() == jQuery('#searchLastName').get(0).defaultValue) jQuery('#searchLastName').val('');
	return true;
};

function initOneSubNav(nav) {
	var navTimer = null;
	var navDelay = 500;
	jQuery(nav + ' ul li').hover(function (e) {
		var li = jQuery(this);
		clearTimeout(navTimer);
		navTimer = null;
		if (li.hasClass("on")) { return; }
		if ( li.hasClass('nav') ) {
			li.find('a').eq(0).css({
				'height': '52px',
				'background-color': '#790D47'
			});
		}
		li.siblings("li").find('div').hide();
		li.find('div').show();
		li.siblings("li").removeClass("on");
		li.siblings("li").find('a').css('background-color', 'transparent');
		li.addClass("on");
	}, function (e) {
		var li = jQuery(this);
		clearTimeout(navTimer);
		navTimer = null;
		navTimer = setTimeout(function () {
			li.removeClass("on");
			li.find('div').hide();
			if ( li.hasClass('nav') ) {
				li.find('a').eq(0).css({
					'height': '45px',
					'background-color': 'transparent'
				});
			}
		}, navDelay);
	});
	return;
};

/**
 * @author Alexander Farkas
 * v. 1.21
 */
(function($){if(!document.defaultView||!document.defaultView.getComputedStyle){var oldCurCSS=jQuery.curCSS;jQuery.curCSS=function(elem,name,force){if(name==='background-position'){name='backgroundPosition';}
if(name!=='backgroundPosition'||!elem.currentStyle||elem.currentStyle[name]){return oldCurCSS.apply(this,arguments);}
var style=elem.style;if(!force&&style&&style[name]){return style[name];}
return oldCurCSS(elem,'backgroundPositionX',force)+' '+oldCurCSS(elem,'backgroundPositionY',force);};}
var oldAnim=$.fn.animate;$.fn.animate=function(prop){if('background-position'in prop){prop.backgroundPosition=prop['background-position'];delete prop['background-position'];}
if('backgroundPosition'in prop){prop.backgroundPosition='('+prop.backgroundPosition;}
return oldAnim.apply(this,arguments);};function toArray(strg){strg=strg.replace(/left|top/g,'0px');strg=strg.replace(/right|bottom/g,'100%');strg=strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");var res=strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);return[parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];}
$.fx.step.backgroundPosition=function(fx){if(!fx.bgPosReady){var start=$.curCSS(fx.elem,'backgroundPosition');if(!start){start='0px 0px';}
start=toArray(start);fx.start=[start[0],start[2]];var end=toArray(fx.options.curAnim.backgroundPosition);fx.end=[end[0],end[2]];fx.unit=[end[1],end[3]];fx.bgPosReady=true;}
var nowPosX=[];nowPosX[0]=((fx.end[0]-fx.start[0])*fx.pos)+fx.start[0]+fx.unit[0];nowPosX[1]=((fx.end[1]-fx.start[1])*fx.pos)+fx.start[1]+fx.unit[1];fx.elem.style.backgroundPosition=nowPosX[0]+' '+nowPosX[1];};})(jQuery);

/*(function($){
	$.fn.progress = function( options ) {  
		var defaults = {
			type		: 'vert',
			goal		: null,
			achieved	: null,
			percent		: null,
			pxLength	: 0,
			speed		: 2000,
			background	: false,
			complete	: function() {}
		};
		var options = $.extend(defaults, options);
		return this.each(function() {
			var percent;
			var px = options.pxLength / 100;
			var pr = (options.achieved / options.goal) * 100;
			if ( !options.percent ) {
				percent = (options.pxLength / 100) * ((options.achieved / options.goal) * 100);
				percent = percent < (options.pxLength + 1) ? percent : options.pxLength;
			} else {
				percent = (options.pxLength / 100) * options.percent;
			}
			switch ( options.type ) {
				case 'vert':
				case 'vertical': {
					if ( !options.background ) {
						$(this)
							.stop()
							.animate({
									height: percent + 'px',
									top: (options.pxLength - percent) + 'px'
								}, options.speed, 'linear', function() { options.complete(); })
							.css({ height: percent + 'px', top: '0px' });
					} else {
						$(this)
							.css('background-position', '0px ' + options.pxLength + 'px')
							.stop()
							.animate({
									backgroundPosition: '(0 ' + (options.pxLength - percent) + ')',
								}, options.speed, 'linear', function() { options.complete(); })
							.css('background-position', '0px 0px');
					}
					break;
				}
				case 'horz':
				case 'horizontal': {
					if ( !options.background ) {
						$(this).stop().animate({
							width: percent + 'px'
						}, options.speed, 'linear', function() { options.complete(); });
					} else {
						$(this)
							.css('background-position', '-' + options.pxLength + 'px 0px')
							.stop()
							.animate({
									backgroundPosition: '(' + (-options.pxLength + percent) + ' 0)',
								}, options.speed, 'linear', function() { options.complete(); })
							.css('background-position', '0px 0px');
					}
					break;
				}
			}
		});
	};
})(jQuery);*/

/* on DOM ready */
jQuery(function() {

	initOneSubNav('#nav-bar');

	/* if event landing page */
	/*
	if ( jQuery('#fund-prog-wrap').get(0) ) {
		if ( jQuery('#greetingThermPersonal .goalVal').get(0) ) { jQuery('#my-goal-val').html(jQuery('#greetingThermPersonal .goalVal').html().replace(/\.\d\d/, '')); }
		if ( jQuery('#greetingThermPersonal .achievedValPersonal').get(0) ) { jQuery('#my-goal-raised').html(jQuery('#greetingThermPersonal .achievedValPersonal').html().replace(/\.\d\d/, '')); }
		if ( jQuery('#greetingThermTeam .goalVal').get(0) ) { jQuery('#team-goal-val').html(jQuery('#greetingThermTeam .goalVal').html().replace(/\.\d\d/, '')); }
		if ( jQuery('#greetingThermTeam .achievedValTeam').get(0) ) { jQuery('#team-goal-raised').html(jQuery('#greetingThermTeam .achievedValTeam').html().replace(/\.\d\d/, '')); }
		if ( jQuery('#greetingThermEvent .goalVal').get(0) ) { jQuery('#event-goal-val').html(jQuery('#greetingThermEvent .goalVal').html().replace(/\.\d\d/, '')); }
		if ( jQuery('#greetingThermEvent .achievedValEvent').get(0) ) { jQuery('#event-goal-raised').html(jQuery('#greetingThermEvent .achievedValEvent').html().replace(/\.\d\d/, '')); }
		
		if ( jQuery('#greetingThermPersonal .goalVal').get(0) || jQuery('#greetingThermPersonal .achievedValPersonal').get(0) ) {
			pGoal = jQuery('#greetingThermPersonal .goalVal').html() != null ? parseInt(jQuery('#greetingThermPersonal .goalVal').html().replace(/\$|\,|\.\d+/g, ''), 10) : parseInt(jQuery('#greetingThermPersonal .achievedValPersonal').html().replace(/\$|\,|\.\d+/g, ''), 10) + 1;
			pAchieved = parseInt(jQuery('#greetingThermPersonal .achievedValPersonal').html().replace(/\$|\,|\.\d+/g, ''), 10);
			jQuery('#personal-goal-wrap .progress-fill').progress({
				goal		: pGoal,
				achieved	: pAchieved,
				pxLength	: 224
			});
		}
		if ( jQuery('#greetingThermTeam .goalVal').get(0) || jQuery('#greetingThermTeam .achievedValTeam').get(0) ) {
			tGoal = jQuery('#greetingThermTeam .goalVal').html() != null ? parseInt(jQuery('#greetingThermTeam .goalVal').html().replace(/\$|\,|\.\d+/g, ''), 10) : parseInt(jQuery('#greetingThermTeam .achievedValTeam').html().replace(/\$|\,|\.\d+/g, ''), 10) + 1;
			tAchieved = parseInt(jQuery('#greetingThermTeam .achievedValTeam').html().replace(/\$|\,|\.\d+/g, ''), 10);
			jQuery('#team-goal-wrap .progress-fill').progress({
				goal		: tGoal,
				achieved	: tAchieved,
				pxLength	: 224
			});
		}
		if ( jQuery('#greetingThermEvent .goalVal').get(0) || jQuery('#greetingThermEvent .achievedValEvent').get(0) ) {
			eGoal = jQuery('#greetingThermEvent .goalVal').html() != null ? parseInt(jQuery('#greetingThermEvent .goalVal').html().replace(/\$|\,|\.\d+/g, ''), 10) : parseInt(jQuery('#greetingThermEvent .achievedValEvent').html().replace(/\$|\,|\.\d+/g, ''), 10) + 1;
			eAchieved = parseInt(jQuery('#greetingThermEvent .achievedValEvent').html().replace(/\$|\,|\.\d+/g, ''), 10);
			jQuery('#event-goal-wrap .progress-fill').progress({
				goal		: eGoal,
				achieved	: eAchieved,
				pxLength	: 224,
			});
		}
	}
	*/

});



(function($) {
$.fn.formatTops = function() {  
	return this.each(function() {
		/* remove all BR tags within 'this' section */
		$.each($('br', this), function() { $(this).remove(); });
		/* add class[clrfix] to each span with class[TopRow] so we can float the spans inside */
		$.each($('.TopRow', this), function(i, el) { $(el).addClass('clrfix'); });
		/* do some formatting on the spans inside */
		$.each($('.TopRow', this).find('span'), function(i, el) {
			if ( !$(el).hasClass('TopSpanToBlock') ) { $(el).addClass('TopSpanToBlock'); }
			$(el).html($(el).hasClass('TopNumber') ? $(el).html().replace('-','').replace(/&nbsp;/g,'') : $(el).hasClass('TopAmount') ? $(el).html().replace('(','').replace(')','').replace(/&nbsp;/g,'') : $(el).html());
			if ( $(el).hasClass('TopBadge') ) { $(el).parent().append(el); }
		});
	});
};

$(function() {

	/* Helper for donate modul */
	$('input:text', '.frm-wrap')
		.blur(function() {
			if ( !$(this).val() ) {
				this.val = $(this).val($(this).get(0).defaultValue);
			}
		}).focus(function() {
			if ( $(this).val() == $(this).get(0).defaultValue ) {
				this.val = $(this).val('');
			} else {
				this.select();
			}
		});;

	var mode = $('#s_tr_part_finder_search_mode').val();
	setSearchMode(mode);
	var search_for = $('#fr_search_type_participant').get(0);
	if ( search_for ) {
		setParticipantSearch (search_for.checked);
	}
	
	$('li:first-child', '#fr_navbar').css('border-top', 'none');
	
//	$.each($('#top-nav').children(), function() {
//		$(this).mouseover(function() {
//			$(this).addClass('sfhover');
//			if ( document.all ) { $(this).children(0).css('left', 'auto'); }
//		}).mouseout(function() {
//			$(this).removeClass('sfhover');
//			if ( document.all ) { $(this).children(0).css('left', '-999px'); }
//		});
//	});

	var currentSlide = 0;
	$.fn.showPrevCycle = function( min, max ) {
		currentSlide == min ? currentSlide = max : currentSlide = (currentSlide - 1);
		cycleText(currentSlide + 1);
	};
	$.fn.showNextCycle = function( min, max ) {
		currentSlide == max ? currentSlide = min : currentSlide = (currentSlide + 1);
		cycleText(currentSlide + 1);
	};
	cycleText = function( pos ) { $('.msg-wrap', '#main-carosel-wrap').cycle(pos - 1); };

	$('.img-wrap', '#main-carosel-wrap').cycle({
        fx		: 'scrollHorz',
        pager	: '#carosel-nav',
        prev	: '#nav-arrow-left',
        next	: '#nav-arrow-right',
        after	: function( curr ,next, opts ) {
			currentSlide = opts.currSlide;
		},
		timeout	: 0,
		speed	: 250,
        pagerAnchorBuilder: function(idx, slide) {
			return $('<a>').attr('href', 'javascript:void(0);').html(idx + 1).bind('click', function()  { cycleText(idx + 1); });
        }
    });
	
    $('.msg-wrap', '#main-carosel-wrap').cycle({ fx: 'fade', timeout: 0, startingSlide: 0 });
	$('#nav-arrow-left').click(function() { $.fn.showPrevCycle(0, 5) });
	$('#nav-arrow-right').click(function() { $.fn.showNextCycle(0, 5) });
	$.each($('.msg-wrap', '#main-carosel-wrap').find('a'), function(i) {
		$(this).css('background', 'transparent');
		var href = $(this).attr('href');
		$($('.img-wrap', '#main-carosel-wrap').find('img').get(i)).click(function() {
			window.location.href = href;
		});
	});

	$('#fundProgTopParts, #fundProgTopTeams, #fundProgTopComps').formatTops();
	
});
})(jQuery);
