	
	/* GLOBAL FONT REPLACEMENTS */
	Cufon.replace('.f-condensed', { fontFamily: 'Condensed' });
	Cufon.replace('.f-bold', { fontFamily: 'Bold' });
	
	$(function() {
	
		/*============================================================*/
		/* SLIDERS
		/*------------------------------------------------------------*/

		$('div.slider a.previous').bind('click',empty);
		$('div.slider a.next').bind('click',empty);
		$('div.slider').each(function() {
			if($(this).find('li').length>1) {
				$(this).data('width',$(this).find('div.frame').width());
				$(this).data('total',$(this).find('li').length);
				$(this).data('current',0);
				$(this).find('li').css({display:'none'});
				slider_position(this,'index');
				slider_enable(this);
			}
		});
	
		/*============================================================*/
		/* SLIDER ROTATION
		/*------------------------------------------------------------*/
	
		slider_interval=setInterval(slider_rotate,5000);
		$('div.slider').hover(function() {
			clearInterval(slider_interval);
			slider_interval=null;
		},function() {
			slider_interval=setInterval(slider_rotate,5000);
		});
	
		/*============================================================*/
		/* CAPTION
		/*------------------------------------------------------------*/

		$('div.image span').css({opacity:0.9});

  
	});
	
	/*============================================================*/
	/* DONATE
	/*------------------------------------------------------------*/
	
	
  function changePaymentType(type) {

    var target_div = '#'+type+'_div';

    $('.card_type').removeClass('cc_active');
    $('.card_type').addClass('cc_inactive');
    $(target_div).removeClass('cc_inactive');
    $(target_div).addClass('cc_active');
    $('#cc_type').val(type);

  }
  
  function submitDonateForm() {
       
    var first_name=$('#first_name').val()
    var last_name=$('#last_name').val()
    var address1=$('#address1').val()
    var city=$('#city').val()
    var state=$('#contact_state').val()
    var zip=$('#zip').val()
    var email=$('#email').val()
    var amount=$('#amount').val()

    var cc_type=$('#cc_type').val()
    var cc_num=$('#cc_num').val()
    var cc_month=$('#cc_month').val()
    var cc_year=$('#cc_year').val()
    var cvv2=$('#cvv2').val()

    if (first_name.length<1) {
      showErrorMessage('You must enter a first name');
      $('#first_name').focus()
      smoothScroll('header')
      return false
    }
  
    if (last_name.length<1) {
      showErrorMessage('You must enter a last name');
      $('#last_name').focus()
      smoothScroll('header')
      return false
    }
  
    if (address1.length<1) {
      showErrorMessage('You must enter at least one address line.');
      $('#address1').focus()
      smoothScroll('header')
      return false
    }
  
    if (city.length<1) {
      showErrorMessage('You must enter a city');
      $('#city').focus()
      smoothScroll('header')
      return false
    }
  
    if (state=='--') {
      showErrorMessage('You must choose a state');
      $('#state').focus()
      smoothScroll('header')
      return false
    }
  
    if (zip.length<5) {
      showErrorMessage('You must enter a valid zip code.');
      $('#zip').focus()
      smoothScroll('header')
      return false
    }
  
    if (amount.length<3) {
      showErrorMessage('You must enter a valid donation amount.');
      $('#amount').focus()
      smoothScroll('header')
      return false
    }
    
    $('.donate_button').css('display', 'none');
    $('.wait_for_payment').css('display', 'block');

    var ajax_data = {first_name: first_name, last_name : last_name, address1 : address1, city : city, state : state, zip : zip, email : email, amount : amount, cc_num : cc_num, cc_type : cc_type, cc_month : cc_month, cc_year : cc_year, cvv2 : cvv2}

    $.post('/ajax/process_donation_form.php', ajax_data, function(data) {
      var result = data.split('|')
  		if (result[2]=='Success') {
  		  alert('Your donation was successful and a receipt will be sent to your email address. Thank you for supporting AFL!')
  		} else {
  		  	$('.donate_button').css('display', 'block');
    		$('.wait_for_payment').css('display', 'none');
		  alert(data)
		  
  		}
    });
  
  
  }
  
  /* VIDEO */
  
  function showSlideshowVideo(slide_id, video_file, poster_file) {
    
    $('#slideshow_container').cycle('pause');
    
    var element = '#slide_'+slide_id

      $(element).flash(
  			{
  				// test_flashvars.swf is the flash document
  				swf: '/swf/media_player/media_player.swf',
  				// these arguments will be passed into the flash document
  				width: '500',
  				height: '300',
  				flashvars: {

  					mediaURL: '/attachments/home_slideshow/'+video_file,
  					posterURL: '/attachments/home_slideshow/'+poster_file,

  				}
  			}
  		);
				
    
  }

  
	
	/*============================================================*/
	/* HELPERS
	/*------------------------------------------------------------*/

  /* SUPPORTING FUNCTIONS */
  
  function showSuccessMessage(big_message, small_message) {

    clearMessage();

    if (small_message === undefined) {
      small_message = ''
    }
    
    var new_html = '<div class="messages">'+big_message+'</div>';


    $('#donation_form').prepend(new_html);


  }

  function showErrorMessage(big_message, small_message) {

    clearMessage();


    if (small_message === undefined) {
      small_message = ''
    }
    
    var new_html = '<div class="errors">'+big_message+'</div>';


    $('#donation_form').prepend(new_html);


  }
  
  function clearMessage() {

    $('.messages').css('display', 'none');
    $('.errors').css('display', 'none');


  }
  
  function currentYPosition() {
  	if (self.pageYOffset) return self.pageYOffset;

  	if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;

  	if (document.body.scrollTop) return document.body.scrollTop;

  	return 0;
  }
  function elmYPosition(eID) {
  	var elm  = document.getElementById(eID);
  	var y    = elm.offsetTop;
  	var node = elm;
  	while (node.offsetParent && node.offsetParent != document.body) {
  		node = node.offsetParent;
  		y   += node.offsetTop;
  	} return y;
  }
  function smoothScroll(eID) {
  	var startY   = currentYPosition();
  	var stopY    = elmYPosition(eID);
  	var distance = stopY > startY ? stopY - startY : startY - stopY;
  	if (distance < 100) {
  		scrollTo(0, stopY); return;
  	}
  	var speed = Math.round(distance / 100);
  	var step  = Math.round(distance / 25);
  	var leapY = stopY > startY ? startY + step : startY - step;
  	var timer = 0;
  	if (stopY > startY) {
  		for ( var i=startY; i<stopY; i+=step ) {
  			setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
  			leapY += step;
  			if (leapY > stopY) leapY = stopY;
  			timer++;
  		} return;
  	}
  	for ( var i=startY; i>stopY; i-=step ) {
  		setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
  		leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
  	}
  }
  

	var slider_interval=null;

	function slider_rotate() {
		$('div.slider a.next').click();	
	}
	function slider_position(el,action) {
		$(el).data('next',$(el).data('current')+1);
		$(el).data('previous',$(el).data('current')-1);
		if($(el).data('next')>=$(el).data('total')) $(el).data('next',0);
		if($(el).data('previous')<0) $(el).data('previous',$(el).data('total')-1);
		var li=$(el).find('li');
		$(li).css({display:'none'});
		if(action=='previous') $(li[$(el).data('previous')]).css({display:'block',left:'-'+$(el).data('width')+'px'});
		$(li[$(el).data('current')]).css({display:'block',left:0});
		if(action=='next') $(li[$(el).data('next')]).css({display:'block',left:$(el).data('width')+'px'});
		$(el).find('ul').css({left:0});
	}
	function slider_disable(el) {
		$(el).find('a.previous').unbind('click',slider_previous).bind('click',empty);
		$(el).find('a.next').unbind('click',slider_next).bind('click',empty);
	}
	function slider_enable(el) {
		$(el).find('a.previous').unbind('click',empty).bind('click',slider_previous);
		$(el).find('a.next').unbind('click',empty).bind('click',slider_next);
	}
	function slider_previous() {
		var parent=$(this).parent('.slider');
		slider_disable(parent);
		slider_position(parent,'previous');
		$(parent).find('ul').animate({left:$(parent).data('width')+'px'},500,function() {
			$(parent).data('current',$(parent).data('previous'));
			slider_enable(parent);
		});
		return false;
	}
	function slider_next() {
		var parent=$(this).parent('.slider');
		slider_disable(parent);
		slider_position(parent,'next');
		$(parent).find('ul').animate({left:'-'+$(parent).data('width')+'px'},500,function() {
			$(parent).data('current',$(parent).data('next'));
			slider_enable(parent);
		});
		return false;
	}
	
