$(document).ready(function(){
						   
	$('#left, #footer, #logo, #logo img, #shadow').ifixpng(); 

	 $("#registerForHearus").validationEngine();
	 
	 $('#uploadTrack').submit(function() {
		
		$('#uploadTrack button').remove();
		
		$('#loader').fadeIn('slow');
	});
	 
	 $('.notLoggedIn').click(function() {
									  
		 $('#login').dialog({
				bgiframe: true,
				height: 140,
				modal: true,
				draggable: false,
				resizable: false,
				width: 400,
				height: 230,
				close: function(event, ui) { location.reload(true); }

			}); 	
	});
	 
	 $('.loggedIn').click(function() {
		
		var voteFor = $(this).attr('id').split('_');
				
		 $.ajax({
		   type: "POST",
		   url: "/hearus/hearus/vote",
		   data: "id="+voteFor[1],
		   success: function(msg){
			 $('#aantalvotes').html(msg);
		   }
		 });

		
	 });
	 
	 $('#addcomment').submit(function() { 

        $(this).ajaxSubmit({success:showResponse}); 

        return false; 
    }); 
	 
	 
	 $('#shareBtn').click(function() {
									  
		 $('#share').dialog({
				bgiframe: true,
				height: 140,
				modal: true,
				draggable: false,
				resizable: false,
				width: 500,
				height: 330,
				close: function(event, ui) { location.reload(true); }

			}); 	
	});
	
});

function showResponse(responseText, statusText)  { 
	$('#commentwrapper').append(responseText);
	$('#addcomment button').replaceWith('<div class="succes">Je comment is toegevoegd!</div>');
}


function ertt(data){
	data = data.replace(/[^a-z0-9\+\/=]/ig, '');
	if (typeof(atob) == 'function') return atob(data);
	var b64_map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
	var byte1, byte2, byte3;
	var ch1, ch2, ch3, ch4;
	var result = new Array();
	var j=0;
	while ((data.length%4) != 0) {
		data += '=';
	}
	
	for (var i=0; i<data.length; i+=4) {
		ch1 = b64_map.indexOf(data.charAt(i));
		ch2 = b64_map.indexOf(data.charAt(i+1));
		ch3 = b64_map.indexOf(data.charAt(i+2));
		ch4 = b64_map.indexOf(data.charAt(i+3));

		byte1 = (ch1 << 2) | (ch2 >> 4);
		byte2 = ((ch2 & 15) << 4) | (ch3 >> 2);
		byte3 = ((ch3 & 3) << 6) | ch4;

		result[j++] = String.fromCharCode(byte1);
		if (ch3 != 64) result[j++] = String.fromCharCode(byte2);
		if (ch4 != 64) result[j++] = String.fromCharCode(byte3);	
	}

	return result.join('');
}
