$(document).ready(function(){

  $('a[href^=http://dmsonline.fitnesscarnisselande.nl], input#inschrijven').click(openSubscribeForm);
  $('a.subscribe_close').live('click', closeSubscribeForm);

	//in jQuery of in CSS???
	$('ul#inschrijvingen li:not(:#submitList)').hover(function(){
		$(this).css('background-position','-460px bottom');
		$(this).css('cursor','pointer');
	}, function(){
		$(this).css('background-position','-460px top');
	});
	$('ul#inschrijvingen li#firstItem').hover(function(){
		$(this).css('background-position','left bottom');
		$(this).css('cursor','pointer');
	}, function(){
		$(this).css('background-position','left top');
	});
				
	$('ul#inschrijvingen li:not(:last-child)').click(function(){
		$(this).find('input:radio').attr('checked','checked');
	});
	
	// muah!!! als javascript uit staat geef ie dit ook niet weer
	$('ul#inschrijvingen li#submitList').append('<span id="total">Totaal: <strong>&nbsp;<\/strong><\/span> ');
	
	// http://stackoverflow.com/questions/1324703/how-might-i-calculate-the-sum-of-radio-button-values-using-jquery

var total = 0;
var extra = 0;        

  $("#inschrijvingen li").click(function() {

    var $abbo = $('#inschrijvingen input[type=radio]:checked');
    var $maand = $('#inschrijvingen input[type=checkbox]');

    if ($abbo.attr('data-month') == 'no') {
      $maand.attr('disabled', true);
      total = parseFloat($abbo.val());
    } else {
      $maand.removeAttr('disabled');
      total = parseFloat($abbo.val());
      
      if ($maand.is(':checked')) {
        total += parseFloat($maand.val())
      }
    }
    
    total = total.toString().replace('.', ',');

    $("span#total strong").html(total);      
    
    extra = total = 0;

	});
	
  $("#inschrijvingen li:first").click();
			
	$('input#inschrijven').hover(function(){ $(this).css('background-position','bottom')}, function(){ $(this).css('background-position','top')});
	$('input#versturen').hover(function(){ $(this).css('background-position','bottom')}, function(){ $(this).css('background-position','top')});
});

function closeSubscribeForm(evt)
{
  evt.preventDefault();
  $('#programma-overlay').fadeOut(50);
  $('#subscribe_lb').remove();
}

function openSubscribeForm(evt)
{
    evt.preventDefault();
    
    $('#programma-overlay').fadeIn(50, function(e) { $(this).css('opacity', .75); }).height($('body').innerHeight()).width($('body').innerWidth());
    
    $('body').append('<div class="programma" id="subscribe_lb"><iframe src="http://dmsonline.fitnesscarnisselande.nl/signup.php"></iframe><a class="subscribe_close">x</a></div>');
    
}

