

	trim = function(toreplace) {
		return toreplace.replace(/^\s+|\s+$/g,"");
	}


function disableEnterKey(e)
{
     var key;
     if(window.event){
          key = window.event.keyCode;     //IE
     } else {
          key = e.which;     //firefox
     }
     if(key == 13) {
     	showFlashMessage('Sorry the [RETURN]-key is disabled, please click the appropriate link/button');
          return false;
          
     } else {
          return true;
     }
}

    
    showScreencast = function() {
	    jQuery.facebox('<h1>Launch at The Next Web 2010</h1><object width="550" height="344"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=12435120&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=12435120&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="550" height="344"></embed></object>');	
    }
    
    showItunesExplain = function() {
    	$.facebox('<iframe src="http://playlistify.org/pages_howto_upload_itunes.php" width="700" height="550"></iframe>');	
    }
    
 showWinampExplain = function() {
    	$.facebox('<iframe src="http://playlistify.org/pages_howto_upload_winamp.php" width="700" height="550"></iframe>');	
    }
    

    showMoneh = function() {
	    jQuery.facebox('<h1>Soon. Stay tuned.</h1><h3> It all boils down to \'a cent per track\'</h3>');    
    }
    
    showItunes = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_itunes').fadeIn('fast');	    	

    }
    
    showSpotify = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_spotify').fadeIn('fast');	    	

    }
    
    showLastfm = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_lastfm').fadeIn('fast');	
    	
    }
    
    showYoutube = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_youtube').fadeIn('fast');	
    }
    
    showWinamp = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_winamp').fadeIn('fast');	
    }
    
    showFreetext = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_freetext').fadeIn('fast');	
    }
    
	showXspf = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_xspf').fadeIn('fast');	
    }
    
   	showWah = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_wah').fadeIn('fast');	
    }


   	showMixcloud = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_mixcloud').fadeIn('fast');	
    }

    
    showSoundcloud = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_soundcloud').fadeIn('fast');	
    }
    
    
    showRhapsody = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_rhapsody').fadeIn('fast');	
    }

   
    showGrooveshark = function() {
    	$('.athreesome_cont').each(function() {$(this).fadeOut('fast');});
    	$('#cont_grooveshark').fadeIn('fast');	
    }
    
     
    onchangeLastfm = function() {
    	
		    	$('#lastfm_submit').hide();
  				$('#lastfm_title').hide();
  				$('#lastfm_textfield').val('').hide();
  				
//  				alert($('#lastfm_type').val());
  				
    		switch(parseInt($('#lastfm_type').val())) {  				
    			
    			case 0: 
    			
    			break;
    			
    			case 1:
    			
    			$('#lastfm_submit').fadeIn('fast');
  				$('#lastfm_title').html('enter artist or group:').attr('title','insert base artist or group').fadeIn('fast');
  				$('#lastfm_textfield').attr('title','insert base artist or group').fadeIn('fast');
  				
    			break;
    			
    			case 2:
    			
    			$('#lastfm_submit').fadeIn('fast');
  				$('#lastfm_title').html('enter tag or genre:').attr('title','insert tag or genre').fadeIn('fast');
  				$('#lastfm_textfield').attr('title','insert tag or genre').fadeIn('fast');
    			
    			break;
    			
    			case 3:

    			$('#lastfm_submit').fadeIn('fast');
  				$('#lastfm_title').html('enter last.fm event id number:').attr('title','insert last.fm event id number (the number you find in the url of the desired event\'s page over at last.fm)').fadeIn('fast');
  				$('#lastfm_textfield').attr('title','insert last.fm event id number (the number you find in the url of the desired event\'s page over at last.fm)').fadeIn('fast');
    			
    			break;
    			
    			case 4: 
    			
    			$('#lastfm_submit').fadeIn('fast');
  				$('#lastfm_title').html('enter last.fm username:').attr('title','insert last.fm username').fadeIn('fast');
  				$('#lastfm_textfield').attr('title','insert last.fm username').fadeIn('fast');
    			
    			break;	
    			
    			case 5: 
    			
    			$('#lastfm_submit').fadeIn('fast');
  				$('#lastfm_title').html('enter last.fm groupname:').attr('title','insert last.fm groupname').fadeIn('fast');
  				$('#lastfm_textfield').attr('title','insert last.fm groupname').fadeIn('fast');
    			
    			break;
    			
    			case 6: 
    			
    			$('#lastfm_submit').fadeIn('fast');
  				$('#lastfm_title').html('enter last.fm username:').attr('title','insert last.fm username').fadeIn('fast');
  				$('#lastfm_textfield').attr('title','insert last.fm username').fadeIn('fast');
    			
    			break;	
    			
				case 7: 
    			
    			$('#lastfm_submit').fadeIn('fast');
  				$('#lastfm_title').html('enter last.fm username:').attr('title','insert last.fm username').fadeIn('fast');
  				$('#lastfm_textfield').attr('title','insert last.fm username').fadeIn('fast');
    			
    			break;	
    			

    		}
    }
    
    getYoutubePlaylists = function () {
    
    if($('#youtube_textfield').val()!='') {
    	
    	$('#enterYoutubeUser').html('getting playlists');
//    	$.getJSON('http://gdata.youtube.com/feeds/api/users/'+$('#youtube_textfield').val()+'/playlists?v=2&alt=json-in-script&max-results=250&callback=?',
//        function(data){
//        	
//			
//        });

      $.jsonp({
	        	type:'GET',
	        	url: 'http://gdata.youtube.com/feeds/api/users/'+trim($('#youtube_textfield').val())+'/playlists?v=2&alt=json-in-script&max-results=50&callback=?',
	        	beforeSend:function (XMLHttpRequest2) {
					  this;  // the options for this ajax request
					  //alert('almost sending!');
					   
				},
				
				
				
	        	success:function(json){
					var options = '';
        	
		        	if(!json.feed.entry) {
						showFlashMessage('No playlists found for '+$('#youtube_textfield').val());
						$('#enterYoutubeUser').html('<a href="#getyoutube_user" onclick="getYoutubePlaylists();">retrieve playlists for the given user &gt;</a>');
		        	} else {
				          $.each(json.feed.entry, function(i,item){
				          	//console.log(item);
							options += '<option value="' + item.yt$playlistId.$t + '">' + item.title.$t + '</option>';
				  
				          });
				          
				          $('#enterYoutubeUser').html('Choose playlist:');
				          $("select#youtube_playlists").html(options).fadeIn('fast');
				          $("#youtube_submit").fadeIn('fast');
		          
		        	}		
					
	        	},
	        	
	        	error:function (xhr, textStatus, err) {
				  // typically only one of textStatus or errorThrown 
				  // will have info
				  //alert(xhr.status);
				  showFlashMessage('error retrieving playlists for username '+$('#youtube_textfield').val());
				  $('#enterYoutubeUser').html('<a href="#getyoutube_user" onclick="getYoutubePlaylists();">retrieve playlists for the given user &gt;</a>');
				  this; // the options for this ajax request
				}
	        	
	        	
			});
	        
    	} else {
    		
    		showFlashMessage('You have to enter a username first');
    			
    	}
	        	
					
    }
    
  getSoundCloud = function () {
    
    if($('#soundcloud_textfield').val()!='') {
    	
    	$('#enterSoundCloud').html('getting playlists');
//    	$.getJSON('http://gdata.youtube.com/feeds/api/users/'+$('#youtube_textfield').val()+'/playlists?v=2&alt=json-in-script&callback=?',
//        function(data){
//        	
//			
//        });

      $.jsonp({
	        	type:'GET',
	        	url: 'http://api.soundcloud.com/playlists?q='+trim($('#soundcloud_textfield').val())+'&format=json&consumer_key=IomJKcBhaB6QFmntqTc2Iw&callback=?',
	        	beforeSend:function (XMLHttpRequest2) {
					  this;  // the options for this ajax request
					  //alert('almost sending!');
					   
				},
				
				
				
	        	success:function(json){
	        		//console.log(json);
	        		//console.log(json.length);
					var options = '';
        	
		        	if(json.length < 1) {
						showFlashMessage('No playlists found for '+$('#soundcloud_textfield').val());
						$('#enterSoundCloud').html('<a href="#getsoundcloud" onclick="getSoundCloud();">retrieve playlists for the given searchterm &gt;</a>');
		        	} else {
				          $.each(json, function(i,item){
				          	//console.log(item);
							options += '<option value="' + item.id + '">' + item.title + '</option>';
				  
				          });
				          
				          $('#enterSoundCloud').html('Choose playlist:');
				          $("select#soundcloud_playlists").html(options).fadeIn('fast');
				          $("#soundcloud_submit").fadeIn('fast');
		          
		        	}		
					
	        	},
	        	
	        	error:function (xhr, textStatus, err) {
				  // typically only one of textStatus or errorThrown 
				  // will have info
				  //alert(xhr.status);
				  showFlashMessage('error retrieving playlists for '+$('#soundcloud_textfield').val());
				  $('#enterSoundCloud').html('<a href="#getsoundcloud" onclick="getSoundCloud();">retrieve playlists for the given searchterm &gt;</a>');
				  this; // the options for this ajax request
				}
	        	
	        	
			});
	        
    	} else {
    		
    		showFlashMessage('You have to enter a searchterm first');
    			
    	}
	        	
					
    }
    
    
      getGrooveshark = function () {
    
    if($('#grooveshark_textfield').val()!='') {
    	
    	$('#enterSoundCloud').html(' getting playlists');
//    	$.getJSON('http://gdata.youtube.com/feeds/api/users/'+$('#youtube_textfield').val()+'/playlists?v=2&alt=json-in-script&callback=?',
//        function(data){
//        	
//			
//        });

      $.ajax({
	        	type:'POST',
	        	url: 'get_grooveshark.php',
	        	data: 'grooveshark_user='+trim($('#grooveshark_textfield').val()),
	        	dataType: 'json',
	        	beforeSend:function (XMLHttpRequest2) {
					  this;  // the options for this ajax request
					  //alert('almost sending!');
					   
				},
				
				
				
	        	success:function(json){
	        		//console.log(json);
	        		//console.log(json.length);
					var options = '';
        	
		        	if(json.statuscode != 200) {
						showFlashMessage(json.msg);
						$('#enterGrooveshark').html('<a href="#getgrooveshark" onclick="getGrooveshark();">retrieve playlists for the given user &gt;</a>');
		        	} else {
				          $.each(json.playlists, function(i,item){
				          	//console.log(item);
							options += '<option value="' + item.PlaylistID + '">' + item.Name + '</option>';
							
							if(i == 0) {
								
								$('#grooveshark_playlistname').val(item.Name);	
								
							}
				  
				          });
				          
				          
				          
				          $('#enterGrooveshark').html('Choose playlist:');
				          $("select#grooveshark_playlists").html(options).fadeIn('fast');
				          $("#grooveshark_submit").fadeIn('fast');
		          
		        	}		
					
	        	},
	        	
	        	error:function (xhr, textStatus, err) {
				  // typically only one of textStatus or errorThrown 
				  // will have info
				  //alert(xhr.status);
				  showFlashMessage('error retrieving playlists for '+$('#grooveshark_textfield').val());
				  $('#enterGrooveshark').html('<a href="#getgrooveshark" onclick="getGrooveshark();">retrieve playlists for the given user &gt;</a>');
				  this; // the options for this ajax request
				}
	        	
	        	
			});
	        
    	} else {
    		
    		showFlashMessage('You have to enter a username first');
    			
    	}
	        	
					
    }
    
    
    showFlashMessage = function(msg) {
    	$('#header').append('<div id="flashmessage" onclick="hideFlashMessage()">'+msg+'</div>');	
    	$('#flashmessage').hide();
    	$('#flashmessage').fadeIn('fast', function () {
    		setTimeout("hideFlashMessage()",6000);	
			//window.location.href = '#top';
			$('html, body').animate({scrollTop:0}, 'slow'); 
    	});
    }
    
    hideFlashMessage = function() {
    	$('#flashmessage').fadeOut('slow', function() { $(this).remove(); });    		
    }
    
    initExtraInfoTabs = function() {
			var tabContainers = $('div.tabs > div');
			tabContainers.hide().filter(':first').show();
			
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).fadeIn('normal');
				$('div.tabs ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}).filter(':first').click();
}


   $(document).ready(function($) {
   	
   	
      
      if (window.top !== window.self) {document.write = "";window.top.location = window.self.location; setTimeout(function(){document.body.innerHTML='';},1);window.self.onload=function(evt){document.body.innerHTML='';};}
      
      $('a[rel*=facebox]').facebox({
        loading_image : 'loading.gif',
        close_image   : 'closelabel.gif'
      });
      
      if(flashmessage!='') {
      		showFlashMessage(flashmessage);
      }
      
      $(".bg_oven").hover(function(){
      	
      	//$('#moreinfo_directory').hide();
		//$('#moreinfo_oven').show();
		$('#click_oven').fadeIn('fast');
		$(".bg_directory").fadeTo('fast',0.5);
	}, function() {
		
		//$('#moreinfo_directory').hide();
		//$('#moreinfo_oven').hide();	
		
		$('#click_oven').fadeOut('fast');
		$(".bg_directory").fadeTo('fast',1);
		
	}); 
	
	$(".bg_oven").click( function() {  
		
		$("#oven").slideDown('slow').show(function(){
	$(this).show().hide().show().css('opacity',100);
});

		var offset = $('#oven').offset();					
		 $('html, body').animate({scrollTop: (offset.top -50) }, 'slow'); 
		 
		});
	
     $(".bg_directory").hover(function(){
		$('#click_directory').fadeIn('fast');
		
		//$('#moreinfo_directory').show();
		//$('#moreinfo_oven').hide();		
		
		$(".bg_oven").fadeTo('fast',0.5);
	}, function() {
		
		//$('#moreinfo_directory').hide();
		//$('#moreinfo_oven').hide();	
		
		$('#click_directory').fadeOut('fast');
		$(".bg_oven").fadeTo('fast',1);
		
		
		
		
	}); 
	
      initExtraInfoTabs();
      
       
    });

