function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) {
		return false;
	}
	return true;
}

function currencyFormatted(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s.replace(".",",");
}

$(document).ready(function() {
						   
	$("#submit").hover(function() { 
			$(this).addClass("hover"); 
		}, function() { 
			$(this).removeClass("hover"); 
	});
	
	$("div#sponsors").scrollable({ 
        items: '.items',
		size: 1,
		speed: 500,
		easing: 'swing',
		circular: true
    }).autoscroll({ 
		autoplay: true,
		interval: 3000
	});
	
	$("ul.sf-menu").superfish();
	
	$("span.prijs").each(function () {
	   $(this).html(currencyFormatted($(this).text()));
	});
		
	getTwitters('tweet', {
		id: 'ZFCZaandijk',
		count: 1,
		enableLinks: true,
		ignoreReplies: true,
		clearContents: true,
		template: '"%text%" <a href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a>'
	});
	
	//Pop-up box
	$("a.colorbox1").colorbox({transition:"fade"});
	$("a.colorbox2").colorbox({transition:"fade", iframe:true, width: 620, height: 740});
	$("a.colorbox3").colorbox({transition:"fade", iframe:true, width: 620, height: 500});
	$("a.colorbox4").colorbox({transition:"fade", iframe:true, width: 420, height: 300});
	
	//Countdown
	/*var austDay = new Date();
	austDay = new Date(austDay.getFullYear(), 4 - 1, 16, 10,00,00);
	$("#defaultCountdown").countdown({until: austDay, description: "tot aan 'De MuziekFabriek!'"});
	$("#year").text(austDay.getFullYear());*/
	
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$("a#totop").animate({right: 0}, 1000);
		} else {
			$("a#totop").animate({right: -125}, 1000);
		}
	});
 
	$("a#totop").click(function(e) {
		e.preventDefault();
		$("body,html").animate({scrollTop:0},800);
	});
	
	//Close function GEZOCHT
	if (("div.slide").length) {
		if (!cookie('closedbox')) {
			$("a.closebox").click(function() {
				$("div.slide").fadeOut();
				cookie('closedbox',true);
			});			
			
			if (!cookie('loaded')) {
				$("div.slide").hide().delay(2000).slideDown(2000);
				cookie('loaded',true);
			}
			else{
				$("div.slide").show();
				cookie('loaded',false);
			}
		}
		else{
			$("div.slide").hide();
			cookie('closedbox',false);
		}
	}
	
	//Show/hide leden pagina
	$("#birthday, #members, #available, #user, #polls, #music").hide();
	$("#hidemenu a[rel]").click(function(e){
		e.preventDefault();
		var showid = $(this).attr("rel");
		$(".showhide").not("#"+showid).hide();
		$("#"+showid).fadeIn(function(){
			$("a[rel]").removeClass("current");
			$("a[rel="+showid+"]").addClass("current");
			if(showid == "music"){
				$("#music").load("muziekbibliotheek.php");
			}
		});
	});
	
	$("body").delegate("a#first, a#previous, a#next, a#last", "click", function(e){
		e.preventDefault();
		url = $(this).attr("rel");
		$("#music").load(url);
	});
	
	//Tooltip
	$("a.tip").tipsy({fade: false, gravity: $.fn.tipsy.autoNS, title: "title"});
	
	//Voting
	$(".vote").click(function() 
	{
		var id = $(this).attr("rel");
		var name = $(this).attr("name");
		var dataString = "id="+ id ;
		var parent = $(this);
		if(name=="up")
		{
			$(this).fadeIn(200).html('<img src="media/img/load.gif" align="absmiddle">');
			$.ajax({
			   type: "POST",
			   url: "up_vote.php",
			   data: dataString,
			   cache: false,
			   success: function(html)
			   {
					parent.html(html);
				} 
	  	});
	}
	else
	{
		$(this).fadeIn(200).html('<img src="media/img/load.gif" align="absmiddle">');
		$.ajax({
		   type: "POST",
		   url: "down_vote.php",
		   data: dataString,
		   cache: false,
		   success: function(html)
		   {
			   parent.html(html);
			}
	 });
	}
		return false;
	});
});
