$(function() { 
$("div.box").html('<ul id="marm" class="stop-marquee LatestTrack"></ul>');	   
$(".LatestTrack").html('<li>Currently listening to..</li>');
	var previousSong = "";
	var thisSong = "";
 
	$(".LatestTrack").everyTime(6000,function(i) {
	   
	 $.ajax({
	   url: "/_inc/nowplaying.php",
	   cache: false,
	   success: function(thisSong){
	   
	 if ( thisSong != previousSong )
	 {
  $(".LatestTrack").html('<li>' + previousSong + '</li>').fadeOut(700, function() { // Run this after the fade-out is done..
	 $(".LatestTrack").html('<li>' + thisSong + '</li>');
 
	 $(function(){
	   $box = $('div.box');
	   $box2 = $('div.box2');
	 $box.children().each(function(){
         $box2.text( $box.text() );
	  
	 if (! $('ul').hasClass("yes-marquee")) // if doesn't have class marquee
	 {
		 if ($box.width() < $box2.width()) { // and is bigger than box1
		   $("#marm").removeClass("stop-marquee");
		   $("#marm").addClass("yes-marquee");
		   $("#marm").addClass("yes-marquee-2");
		   $(".marquee").marquee();
		   $(".marquee").marquee("update");
		   //alert("if not yes-marquee - bigger than box1");
	     }
		 
		 else if ($box2.width() < $box.width()) { // and is smaller than box1
		  //$("#marm").addClass("");
		   //alert("if not yes-marquee - smaller than box1");
	     }
	 }
	   
	 else if ($('ul').hasClass("yes-marquee")) // if does have marquee class
	 { 
         if ($box.width() < $box2.width()) { // and bigger than box1
		   $("#marm li").removeClass("marquee-showing");
		   $("#marm").removeClass("marquee");
		   $("#marm").addClass("stop-marquee");
		   $(".marquee").marquee();
		   $(".marquee").marquee("update");
		   //alert("if yes-marquee - bigger than box1");
		   //alert("CLASS STOP ADDED");
		   
		 }
	 
		 else if ($box2.width() < $box.width()) { // or smaller than box1
		   $("#marm li").removeClass("marquee-showing");
		   $("#marm").removeClass("marquee");
		   $("#marm").removeClass("yes-marquee").removeClass("yes-marquee-2").addClass("stop-marquee");
		   $(".marquee").marquee();
		   $(".marquee").marquee("update");
			 //alert("if yes-marquee - smaller than box1");
		 }
	 }		 
	 });
  });

	 $(".LatestTrack").fadeIn(2900, function() {
	 $(function(){
	   $box = $('div.box');
	   $box2 = $('div.box2');
	 $box.children().each(function(){
         $box2.text( $box.text() );


	 if ($('ul').hasClass("yes-marquee")) // if does have marquee class
	 { 
         if ($box.width() < $box2.width()) { // and bigger than box1
		   $("#marm").removeClass("stop-marquee");
		   $("#marm").addClass("marquee");
		   $(".marquee").marquee();
		   $(".marquee").marquee("update");
		  //alert("CLASS STOP REMOVED!!");
		 }
		
	 }	

	 else if (! $('ul').hasClass("yes-marquee")) // if doesn't have class marquee
	 {
		 if ($box.width() < $box2.width()) { // and is bigger than box1
		   $("#marm").removeClass("stop-marquee");
		   $("#marm").addClass("marquee");
		   $(".marquee").marquee();
		   $(".marquee").marquee("update");
	     }
	 }
	  	 	 
       }); 
      });
     });
    });
       }
	      previousSong = thisSong;
       }
    });
 
  });
});