	//GLOBALS
	//Diciplines
	var disciplines = new Array();
	disciplines['swim'] = {
		name: 'Swimming',
		km: 4,
		milestones:0,
		goal:80000,
		stepsize: 0.5,
		bar_width: 280
	}
	disciplines['water'] = {
		name: 'Swimming',
		km: 4,
		milestones:0,
		goal:80000,
		stepsize: 0.5,
		bar_width: 280
	}
	disciplines['run'] = {
		name: 'Running',
		km: 42,
		milestones:0,
		goal:80000,
		stepsize: 0.05,
		bar_width: 280
	}
	disciplines['cycle'] = {
		name: 'Cycling',
		km: 180,
		milestones:7,
		goal:180000,
		stepsize: 0.5,
		bar_width: 280
	}
	disciplines['water_total'] = {
		name: 'water_total',
		km: 180,
		milestones:0,
		goal:80000,
		stepsize: 0.5,
		bar_width: 750
	}

	
	var chosen_discipline = disciplines['swim'];
	var slider_value = 0;
	
	//Show a sign is the ajax call failed after 10sec
	function donationFailed(){
			$.fancybox.hideActivity();
			alert('Something went wrong. Please reload the page and try again.');
	}
	
	//Wordt uitgevoerd als de DOM geladen is
	$(document).ready(function(){
	
		$('#step2').hide();
		$('.tooltip').tooltip();
		
		//Donation wizzard step 1 harmonica
		$('#donation_choise_bank_text').hide();
		$('#donation_choise_invoice_text').hide();
		//$('#donate_type_text_custom').hide();		
		
		$('.radio_donation_choise_button').click(function(){
			
			$('.donation_type_text').slideUp('fast');
			$('#'+$(this).attr('alt')).slideDown('slow');
			
			if(this.id === 'radio_donation_choice_bank' || this.id == 'radio_donation_choice_invoice'){
				$('#button_step2').attr({'disabled':'disabled'});
			}else{
				$('#button_step2').removeAttr('disabled');
			}
			
		});
		
		//Fix scroll balk in IE
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) {			
			$('#donation_form').css({'overflow':'scroll'});
		}
		
		//Donation wizard
		var input_custum_donation = '';
		//$('#donate_type_text_custom').css({'opacity': 0.30});
		$('#donate_type_text_custom').click(function(){
			hideDistance();
			$('#radio_custom').attr({'checked':'checked'});
			
		});
		$('#input_custum_donation').keydown(function(e){
			/*
			if(e.keyCode > 47 && e.keyCode < 57){
				//input_custum_donation += String.fromCharCode(e.keyCode);
				//$('#input_custum_donation').val(input_custum_donation);
				var calculated_km = (chosen_discipline.km/chosen_discipline.goal)*$('#input_custum_donation').val();
				$('#calculated_km').html(calculated_km);
			}else{
				//alert('Please enter a valid number.');
				var temp1234 = $('#input_custum_donation').val();					
				$('#input_custum_donation').val(temp1234.substr(temp1234.lenght,1));
				
			}
			*/
			//var calculated_km = (chosen_discipline.km/chosen_discipline.goal)*(parseInt($('#input_custum_donation').val()));
			//$('#calculated_km').html(calculated_km);
			
		});	
	$('#input_custum_donation').change(function(){
		$('#input_final_donated_amount').val($('#input_custum_donation').val());
	});
	
	//Geef de formbackground ronde randjes
	//$('.form_background').prepend('<div class="form_background_top"></div>');
	//$('.form_background').append('<div class="form_background_bottom"></div>');	
	
		//Maak een fancy box van het donate formulier
		var donate_link_rel = '';
		$(".donation_form_link").click(function(){
			donate_link_rel = $(this).attr("rel");			
		});
		$(".donation_form_link").fancybox({
				'titlePosition'		: 'outside',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'none',
				'showNavArrows'		: false,
				'margin'			: 0,
				'titleShow'			: false,
				'onClosed'		: function(){
						//Return to the first step of the wizzard
						showStep1();
						$('#container_swf').css({'visibility':'visible'});
						slider_value = 0;
						$('#slider').slider('option', 'value', 0);
						update_slidervalue();
					},
				'onStart'			: function(){	
					$('#container_swf').css({'visibility':'hidden'});
					var number_of_km = 0;
					var temp_title = donate_link_rel.split('_');
					//Set global var to chosen dicipline
					chosen_discipline = disciplines[temp_title[0]];
					$('#input_discipline').val(chosen_discipline.name.toLowerCase());
					$('#show_discipline').html(chosen_discipline.name);
					
					//$('#donate_type_text_custom').html('I would like to donate an amount to my own choosing. Please type your amount in the text field below to see how many kilometers of '+chosen_discipline.name.toLowerCase()+' you will be sponsoring.<br />Donation amount: <span class="currency_sign">R</span><input type="text" id="input_custum_donation" name="input_custom_donation" /><br />');
					$('#donate_type_text_custom_discipline').html(chosen_discipline.name.toLowerCase());
										
					//Slidebar 					
					$("#slider").slider({
						min: 0,
						max: (chosen_discipline.km),
						step: chosen_discipline.stepsize,
						slide: function(event, ui) {
							var km = (ui.value);				
							slider_value = Math.round(km*100)/100;
							update_slidervalue();
							
							
						}
					});

					//Put the focus on the slider
					//$('.ui-slider-handle').focus();
				}
			});
		
		//Milestone texten
		var milestone_txt = new Array();
		milestone_txt['water_milestone1'] = "Help me raise <b>R15,000</b> and win a limited edition personal gift!";
		milestone_txt['water_milestone2'] = "Help me raise <b>R30,000</b> and win a limited edition personal gift!";
		milestone_txt['water_milestone3'] = "Help me raise <b>R45,000</b> and win a limited edition personal gift!";
		milestone_txt['water_milestone4'] = "Help me raise <b>R60,000</b> and win a pair of tickets to the 2010 Fifa World Cup&#0153;!";
		
		milestone_txt['run_milestone1'] = "Studio88 have helped me raise <b>R12,000</b> and have won a limited edition personal gift!";
		milestone_txt['run_milestone2'] = "Help me raise <b>R24,000</b> and win a limited edition personal gift!";
		milestone_txt['run_milestone3'] = "Help me raise <b>R36,000</b> and win a limited edition personal gift!";
		milestone_txt['run_milestone4'] = "Help me raise <b>R48,000</b> and win a limited edition personal gift!";
		milestone_txt['run_milestone5'] = "Help me raise <b>R60,000</b> and win a limited edition personal gift!";
		milestone_txt['run_milestone6'] = "Help me raise <b>R72,000</b> and win a limited edition personal gift!";
		milestone_txt['run_milestone7'] = "Help me raise <b>R84,000</b> and win a pair of tickets to the 2010 Fifa World Cup&#0153;!";
		
		milestone_txt['cycle_milestone1'] = "Help me raise <b>R18,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone2'] = "Help me raise <b>R36,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone3'] = "Help me raise <b>R54,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone4'] = "Help me raise <b>R72,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone5'] = "Help me raise <b>R90,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone6'] = "Help me raise <b>R108,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone7'] = "Help me raise <b>R126,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone8'] = "Help me raise <b>R144,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone9'] = "Help me raise <b>R162,000</b> and win a limited edition personal gift!";
		milestone_txt['cycle_milestone10'] = "Help me raise <b>R180,000</b> and win a pair of tickets to the 2010 Fifa World Cup&#0153;!";
		
		
		milestone_txt['main_milestone1'] = "Help me raise <b>R20250</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone2'] = "Help me raise <b>R40500</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone3'] = "Help me raise <b>R60750</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone4'] = "Help me raise <b>R81000</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone5'] = "Help me raise <b>R101250</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone6'] = "Help me raise <b>R121500</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone7'] = "Help me raise <b>R141750</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone8'] = "Help me raise <b>R162000</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone9'] = "Help me raise <b>R182250</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone10'] = "Help me raise <b>R202500</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone11'] = "Help me raise <b>R222750</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone12'] = "Help me raise <b>R243000</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone13'] = "Help me raise <b>R263250</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone14'] = "Help me raise <b>R283500</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone15'] = "Help me raise <b>R303750</b> and win a limited edition personal gift!";
		milestone_txt['main_milestone16'] = "Help me raise <b>R324000</b> and win a limited edition personal gift!";

		
		
		
		//Vul het milestone ballonetje met de juiste data
		/*
		$('.milestones').mouseover(function(){
			var classes_array = $(this).attr('class').split(' ');
			
			$('.popup_milestone_text').html(milestone_txt[classes_array[1]]);
		});
		
		//Vul het milestone ballonetje met de juiste data	
		$('.main_milestone').mouseover(function(){
			var classes_array = $(this).attr('class').split(' ');
			
			$('.popup_milestone_text').html(milestone_txt[classes_array[1]]);
		});
		*/
				
		//Verberg de popup	
		// $('.popup_milestone').hide();
		
		//-------------------
		//Donation formulier
		//-------------------
		
		//Change the opacity of a form element
		function hideCustom(){
			$('#donate_type_text_custom').css({'opacity': 0.3});
			$('#donate_type_text_distance').css({'opacity': 1});
		}
		
		function hideDistance(){
				$('#donate_type_text_custom').css({'opacity': 1});
				$('#donate_type_text_distance').css({'opacity': 0.3});
		}
		
		//Donation choice
		$('input[name|=donation_choice]').click(function(){
				
			if($(this).val() == 'custom'){
				hideDistance();
			}else{
				hideCustom();
			}
		});

		//Slidebar 
		/*
		var slider_value = 0;
		$("#slider").slider({
			min: 0,
			max: 40,
			slide: function(event, ui) {
				var km = (ui.value/100);				
				slider_value = km;
				update_slidervalue();
			}
		});
		*/
		
		//Update slidervalue
		function update_slidervalue(){
			var money = slider_value * (chosen_discipline.goal/chosen_discipline.km);

			//$("#selected_number_of_km").html('km: ' +  slider_value + ' = '+currency_exange[currency].sign+convert(money,currency));
			$(".slider_value").html('<b>'+slider_value+'km</b>');
			$("#selected_number_money").html(currency_exange[currency].sign+convert(money,currency));
			$('#input_final_donated_amount').val(convert(money,currency));
			$('#input_kilomters').val(slider_value);
			
		}
		//Update the currency
		$('#choose_currency').change(function(){
			currency = $(this).val();
			$('.currency_sign').html(currency_exange[currency].sign);
			update_slidervalue();
		});
		
		//Currency
		var currency = "ZAR";
		var currency_exange = new Array();
		currency_exange['ZAR'] = {rate:1,sign:'R'};
		currency_exange['EUR'] = {rate:10.1274,sign:'&euro;'};
		currency_exange['USD'] = {rate:7.45649,sign:'$'};

		
		
		//Covert a amount to a different currency
		function convert(amount, input_currency){			
			return Math.round((amount / currency_exange[input_currency].rate)*100)/100;
		}
		
		function convert2zar(amount, input_currency){
			return Math.round((amount * currency_exange[input_currency].rate));
		}
		
		//Buttons
		$('#button_step2').click(function(){
			//alert('hallo');
			var amount_in_rand = convert2zar($('#input_final_donated_amount').val(), $('#choose_currency').val());
			$('#input_final_donated_amount_rand').val(amount_in_rand);
			$('#wizzard_step2_total_amount').html(currency_exange[$('#choose_currency').val()].sign+""+$('#input_final_donated_amount').val());
			
			if(amount_in_rand < 100){
				alert('You have to donate at least R100!\nYou donated '+currency_exange[currency].sign+''+$('#input_final_donated_amount').val()+' (R'+amount_in_rand+')');
				return false;
			}
			
			//if($('#input_custom_donation'))
			
			$('#step1').hide('slide',function(){$('#step2').show('slide')});
			$('#donate_wizzard_step1').removeClass('donate_wizzard_step_active');
			$('#donate_wizzard_step1').addClass('donate_wizzard_step_inactive');
			$('#donate_wizzard_step2').removeClass('donate_wizzard_step_inactive');
			$('#donate_wizzard_step2').addClass('donate_wizzard_step_active');
			return false;
			
		});
		
		$('#button_step1').click(function(){
			//alert('hallo');
			
			showStep1();
			
			return false;
		});
		
		function showStep1(){
			$('#step2').hide('slide',function(){$('#step1').show('slide')});
			$('#donate_wizzard_step2').removeClass('donate_wizzard_step_active');
			$('#donate_wizzard_step2').addClass('donate_wizzard_step_inactive');
			$('#donate_wizzard_step1').removeClass('donate_wizzard_step_inactive');
			$('#donate_wizzard_step1').addClass('donate_wizzard_step_active');
		}
		
		
		
		
		

		$('#button_donate').click(function(){
			$.fancybox.showActivity();
			//donationFailed();
			setTimeout("donationFailed()", 10000);
			$.get('wp-content/themes/luxury-press/add.php?'+$('#donation_form :input').serialize(),function(data){
				window.location.href = "https://www.givengain.com/cgi-bin/giga.cgi?cmd=donate&cause_id=495&project_id=9706&first_name="+$('#input_first_name').val()+"&last_name="+$('#input_last_name').val()+"&amount="+$('#input_final_donated_amount').val()+"&currency="+$('#choose_currency').val();
			});
		});
		
		//Delete the example text
		$('#input_first_name').css({'color': '#BFBFBF'});
		$('#input_last_name').css({'color': '#BFBFBF'});
		$('#input_first_name').focus(function(){
			$(this).val('');
			$('#input_first_name').css({'color': '#000000'});
		});
		
		$('#input_last_name').focus(function(){
			$(this).val('');
			$('#input_last_name').css({'color': '#000000'});
		});
		/*		
		//Mouseover milestone
		$(".milestones").hover(
		function(e){
			$('.popup_milestone').css('top',e.pageY);
			$('.popup_milestone').css('left',e.pageX);
			$('.popup_milestone').show();
		},
		function(){
			$('.popup_milestone').hide();
		}
		);
		
		
		
		//Mouseover milestone
		$(".main_milestone").hover(
		function(e){
			
			$('.popup_milestone').css('top',e.pageY);
			$('.popup_milestone').css('left',e.pageX);
			$('.popup_milestone').show();
		},
		function(){
			$('.popup_milestone').hide();
		}
		);
			
		*/
		
		//Anonymous checkbox
		$('#anonymous_checkbox').click(function(){
			if($(this).attr('checked')){
				
				$('#input_first_name').attr('disabled', 'disabled');
				$('#input_last_name').attr('disabled', 'disabled');
				$('#input_company_name').attr('disabled', 'disabled');
				$('#input_email').attr('disabled', 'disabled');
			}else{
				$('#input_first_name').removeAttr("disabled");
				$('#input_last_name').removeAttr("disabled");
				$('#input_company_name').removeAttr("disabled");
				$('#input_email').removeAttr("disabled");
			}
		});
		
		//Sla formulier op via AJAX
		$('#form_donate_form').submit(function() {	
			var first_name = $(this+'[name|=input_first_name]').val();
			var last_name = $(this+'[name|=input_last_name]').val();
			var email = $(this+'[name|=input_email]').val();
			
			//return false;
			$.get('data.php?'+$(this).serialize(),function(data){
				//alert(data);
				//document.location = "https://www.givengain.com/cgi-bin/giga.cgi?cmd=donate&cause_id=495&project_id=0&email_address=";
				window.location.href = "https://www.givengain.com/cgi-bin/giga.cgi?cmd=donate&cause_id=495&project_id=9706&email_address="+email+"&first_name="+first_name;
				
			});
			//window.location.href = "https://www.givengain.com/cgi-bin/giga.cgi?cmd=donate&cause_id=495&project_id=0&email_address="+email+"&first_name="+first_name;
			return false;
		});
		
		//Animeer de balken		

//		animate_bar('water',7000);
//		animate_bar('run',80000);
//		animate_bar('cycle',8500);

	});
	
	function wissel(){
		$('#form1').hide('slow');
		//$('#form2').show('slow');
		return false;
	}
	
	//Donate goals [OUD!!!]
	var donate_goals = new Array();	
	donate_goals['water'] = 60000;
	donate_goals['run'] = 180000;
	donate_goals['cycle'] = 84000;
	

	
	//Function to animate te progressbars
	function animate_bar(bar_id,rand_donated){
		
		var goal = disciplines[bar_id].goal;
		var progress_bar_width = disciplines[bar_id].bar_width; //280 
		var percentage = (100*rand_donated)/goal;
		//Calculate the amount of pixels of the prgress bar
		var progress = (percentage*progress_bar_width)/100;
		// var progress = 746;
		
		$('.'+bar_id+'_balk_voortgang').animate({'width':750},2000);
		$('.'+bar_id+'_balk_voortgang').animate({'width':progress},2000);
		$('.'+bar_id+'_donations').animate(
			{'left':progress},
			{step:function(){
				//$('#countdown').html('la'+(Math.parseInt($('.water_balk_voortgang').css('width'))*100)/200);
				//var progress_percentage = Math.floor(parseInt($('.water_balk_voortgang').css('width'))/progress_bar_width*100);
				//$('.water_donations').html(Math.floor((parseInt($('.water_balk_voortgang').css('width'))*progress)/progress_bar_width));
				var huidige_width = parseInt($('.'+bar_id+'_balk_voortgang').css('width'));
				//var steps = Math.floor(rand_donated / progress);
				var steps = rand_donated/100;
				//var new_value = parseInt($('.water_donations').text())+steps;
				//Hoever is de bar geladen van het totaal (totaal = 100%)
				var bar_pecentage = huidige_width/progress*100;
				
				$('.'+bar_id+'_donations').html('R'+Math.round(bar_pecentage*steps));
				
				},
			complete: function(){
				$('.'+bar_id+'_donations').html('R'+rand_donated);
			},
			duration:2000}
			
		);
		
	}
	
	function relocate(){
	window.location.href = "https://www.givengain.com/cgi-bin/giga.cgi?cmd=donate&cause_id=495&project_id=9706&email_address="+email+"&first_name="+firstname;
	}
	
	
	setInterval("countdown()",1000);
	
	//Countdown tot iron brian
	function countdown(){
		var huidigeDate = new Date();
		var countdown = new Date(2011, 3, 10, 7, 0);
		var verschil = (countdown.getTime() - huidigeDate.getTime());
		var msPerDay = 24 * 60 * 60 * 1000;
		dagen = Math.floor(verschil / msPerDay);
		uren = Math.floor((verschil%(60*60*1000*24))/(60*60*1000)*1);
		min = Math.floor(((verschil%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
		sec = Math.floor((((verschil%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
		$('#days').html(dagen);
		$('#hours').html(uren);
		$('#minutes').html(min);
		$('#seconds').html(sec);
	}

