$(document).ready(function() {
		
		$(".login").corner("round top 5px");
		$(".dashboard").corner("round top 5px");
		$("#menu").corner("round bottom 5px");
		
		$("input[name=username]").blur(function () {
			$("input[name=password]").focus();
		});
		
		UpdateStatusBar(null, null, null);
		/*
		$.Juitter.start({

			searchType:"searchWord",
			searchObject:"SmashFM", // , Smash FM
			total: 10, // number of tweets to be show - max 100
			live:"live-20", // it will be updated every 180 seconds/3 minutes
			filter:"sex->*BAD word*,porn->*BAD word*,shit->*BAD word*" // fuck->*BAD word*,
			
		});
			*/	
		$(".gamble").click( function(){
							
			jLoad("Rolling the dice ..", 'Smashing Roulette');
			
			$.post("includes/ajax/post.php?what=song_request", { feature: "gamble" }, function(data){
				jAlert(data.message, 'Smashing Roulette');
				if(data.status == "200"){
					UpdateStatusBar(null, null, null);
					$("#head .section .dashboard .timer").css('display', 'block');
					$("#head .section .dashboard .timer").countdown(true, data.countdown, data.current_time, function() { $(this).css('display', 'none'); } );
					$.fn.update_credits();
				}
			}, "json");	
			
			return false;
			
		});
		
		$(".gamble_top").click( function(){
			
			jConfirm('Het systeem gaat nu automatisch een track voor je aanvragen', 'Smashing Roulette', function(r) {
						
				if(r){
				
				jLoad("Rolling the dice ..", 'Smashing Roulette');
				
				$.post("includes/ajax/post.php?what=song_request", { feature: "gamble" }, function(data){
					jAlert(data.message, 'Smashing Roulette');
					if(data.status == "200"){
						UpdateStatusBar(null, null, null);
						$("#head .section .dashboard .timer").css('display', 'block');
						$("#head .section .dashboard .timer").countdown(true, data.countdown, data.current_time, function() { $(this).css('display', 'none'); } );
						$.fn.update_credits();
					}
				}, "json");
				
				}
			
			});
			
			return false;
		});
		
		
		$("#SongTable tr td.song").hover(
		
			function () {
					
					var songid = $(this).attr("id").replace("song", "");
					
					if(global_subpage == 'favorieten')
						$(this).append('<span class=\"options\"><a class=\"request\" href=\"javascript: void(0);\">Direct aanvragen</a><br /><a class=\"bookmark_remove\" href=\"javascript: void(0);\">Verwijderen als favoriet</a></span>');
					else
						$(this).append('<span class=\"options\"><a class=\"request\" href=\"javascript: void(0);\">Direct aanvragen</a><br /><a class=\"bookmark\" href=\"javascript: void(0);\">Opslaan als favoriet</a></span>');
						
						
					$(".request").click( function(){
						
						jLoad("Je request wordt verwerkt ..", 'SmashFM LIVE Request');
						
						$.post("includes/ajax/post.php?what=song_request", { songid: songid }, function(data){
							jAlert(data.message, 'SmashFM LIVE Request');
							if(data.status == "200"){
								UpdateStatusBar(null, null, null);
								$("#head .section .dashboard .timer").css('display', 'block');
								$("#head .section .dashboard .timer").countdown(true, data.countdown, data.current_time, function() { $(this).css('display', 'none'); } );
								$.fn.update_credits();
							}
							
						}, "json");

					});
					
					
					$(".bookmark").click( function(){
												
						$.post("includes/ajax/post.php?what=add_bookmark", { songid: songid }, function(data){
							jAlert(data.message, 'SmashFM');
						}, "json");

					});
					
					
					$(".bookmark_remove").click( function(){
												
						$.post("includes/ajax/post.php?what=remove_bookmark", { songid: songid }, function(data){ //songid
							
							/*if(global_subpage == 'favorieten'){
								
								$("#song_row_" + songid).fadeOut(500, function() { $().remove(this); });
												
							}
							*/
							window.location = window.location;
							
						}, "json");
						
						return false;
						
					});
				
			}, 
			function () {
				$(this).find("span:last").remove();
			}		  

		);
		
		$(".direct-request").click( function(){
			
			var songid = $(this).attr("id").replace("song", "");
			
			jLoad("Je request wordt verwerkt ..", 'SmashFM LIVE Request');
			
			$.post("includes/ajax/post.php?what=song_request", { songid: songid }, function(data){
				jAlert(data.message, 'SmashFM LIVE Request');
				if(data.status == "200"){
					UpdateStatusBar(null, null, null);
					$("#head .section .dashboard .timer").css('display', 'block');
					$("#head .section .dashboard .timer").countdown(true, data.countdown, data.current_time, function() { $(this).css('display', 'none'); } );
					$.fn.update_credits();
				}
			}, "json");
			
			return false;
			
		});
			
			
		$('.search').submit(function() {
		
			var query = $("input[name=query]").val();
			var query = query.toLowerCase();
			var query = query.replace(' ','+');
			
			var type = $("input[name=type]").val();
						
			if(query == "" || query == " " || query == "+") 
				jAlert("Vul minimaal &eacute;&eacute;n letter in om te zoeken!", "SmashFM");
			else
				window.location='./' + type + '/search/' + query;
			
			return false;
		
		});
		
		$('#tunein').click(function(){
			window.open ("./mediaplayer", "mediaplayer","menubar=0,resizable=0,width=410,height=275,scrollbars=0");
			return false;
		});
		
		//window.open ("http://www.javascript-coder.com", "mywindow","menubar=1,resizable=1,width=350,height=250"); 

	
	});

