var currentsong;
var movieName = "songPlayer";
function normRoll(imgname, imgsrc) {
	imgsrc = "/newimg/" + imgsrc;
	document.images[imgname].src = imgsrc;
	return true;
}
// THIS RUNS ADDING AND DELTING FROM THE STORE

function addToCart(target,mediaType,selection,docroot) {
	  $.get("/inc/add_to_cart.php", { docroot: docroot, product_id: selection, mediaType: mediaType } );
	  $('#jBasketContents').load('/inc/cart_view.php');
	  $('jBasket').hide();
	  $('#jBasket').load('/inc/cart_totals.php');
	  $('jBasket').show();
	  //$('jBasket').effect("highlight", {}, 3000);
	  $(target).html("<div class=\"buybutton\"><span class=\"format\">In Cart</span></div>");
}

function removeFromCart (target,mediaType,selection,docroot){
	$.get("/inc/remove_from_cart.php", {product_id: selection, mediaType: mediaType } );
	$('jBasket').hide();
        $('#jBasket').load('/inc/cart_totals.php');
        $('jBasket').show();
	$('jBasketContents').hide();
        $('#jBasketContents').load('/inc/cart_view.php');
	$('jBasketContents').show();
}


function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  } else {
    return document[movieName]
  }
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
  // First make sure the movie's defined.
  if (typeof(theMovie) != "undefined") {
    // If it is, check how much of it is loaded.
    return theMovie.PercentLoaded() == 100;
  } else {
    // If the movie isn't defined, it's not loaded.
    return false;
  }
}

// THIS PLAYS SAMPLE AND LISTEN TRACKS
function playSong(isrc,xxx) {
	//alert(isrc+xxx);
        if(currentsong!=xxx){
                         currentsong=xxx;
                         $(".isPlaying").each(function () {
                                        $(this).removeClass('isPlaying');
                                        $(this).addClass('isStopped');
					//$(this).css('background-color','#006600');
                                        $(this).text('play');
                          });
                         $(xxx).removeClass('isStopped');
                         $(xxx).addClass('isPlaying');
                         $(xxx).text('stop');
			if (movieIsLoaded(thisMovie(movieName))) {
                         thisMovie('songPlayer').playSong(isrc);
			}
        }else{
  	         currentsong="";
                 thisMovie('songPlayer').stopSong();
                 $(".isPlaying").each(function () {
                                $(this).removeClass('isPlaying');
                                $(this).addClass('isStopped');
                                $(this).text('play');
                  });
        }

}
