$(document).ready(function() {
   
	$('#soundcontrol').click(function(e) {
  		if(mySound.paused) {
  			mySound.resume();
  			$('#soundon').show();
  			$('#soundoff').hide();
  		} else {
  			mySound.pause();
  			$('#soundon').hide();
  			$('#soundoff').show();
  		}
	   
	 });
	 
	 
	 $("#soundcontrol").hover(
		 function (e) {
		   $('#soundcredit').show();
		   $('#soundcredit').attr('right', e.pageX);
		 }, 
		 function () {
		   $('#soundcredit').hide();
		 }
	 );
	 
	 $("#soundcredit").hover(
		 function () {
		   $('#soundcredit').show();
		 }, 
		 function () {
		   $('#soundcredit').hide();
		 }
	 );
	 
	 //$("#soundon img[title]").tooltip({offset: [45, -40]});
	 

});

function getUrlBase() {
		var url2 = ""+window.location;
		var noHttp = url2.split('//');
		var comWWW = noHttp[1].split('/');
		var urlBase = "";
		if (comWWW.length > 3){
			var ups = comWWW.length - 3;
			for (var i=0; i<ups; i++ ) {
				urlBase += "../";
			}
		};
		//return urlBase;
		return 'http://'+comWWW[0];
	}


var urlBase = getUrlBase();

//alert(urlBase);

soundManager.url = urlBase+'/wp-content/themes/prohibition/swf/'; // directory where SM2 .SWFs live
//alert(soundManager.url);

soundManager.flashVersion = 9;

// Note that SoundManager will determine and append the appropriate .SWF file to the URL,
// eg. /path/to/sm2-flash-movies/soundmanager2.swf automatically.

// Beta-ish HTML5 audio support (force-enabled for iPad), flash-free sound for Safari + Chrome. Enable if you want to try it!
soundManager.useHTML5Audio = true;

// do this to skip flash block handling for now. See the flashblock demo when you want to start getting fancy.
soundManager.useFlashBlock = false;

// disable debug mode after development/testing..
soundManager.debugMode = false;

// Option 1: Simple onload() + createSound() method
/*
soundManager.onload = function() {
  // SM2 has loaded - now you can create and play sounds!
  soundManager.createSound('helloWorld','/path/to/hello-world.mp3');
  soundManager.play('helloWorld');
};


// Option 2 (better): More flexible onload() + createSound() method
var mySound;
soundManager.onload = function() {

  mySound = soundManager.createSound({
    id: 'aSound',
    url: urlBase+'/dev/wp-content/themes/prohibition/audio/Coquette.mp3'
    // onload: [ event handler function object ],
    // other options here..
  });

 var homeurl = location.href;
  //alert(homeurl);
  if (homeurl == "http://www.prohibitiondistillery.com/dev/") {
	  mySound.play({volume:15});
  } else if ( homeurl == "http://www.prohibitiondistillery.com/dev/home/") {
	  //mySound.setPosition('aSound',2500);
	  mySound.play();
  } else {
	  // do nothing
  }

}
*/
// Option 3 (best): onready() + createSound() / ontimeout() methods for success/failure:
var mySound;
soundManager.onready(function() {

  // SM2 has loaded - now you can create and play sounds!
	mySound = soundManager.createSound({
    id: 'aSound',
    url: urlBase+'/wp-content/themes/prohibition/audio/Coquette.mp3'
    // onload: [ event handler function object ],
    // other options here..
  });
  
  var homeurl = location.href;
  //alert(homeurl);
  if (homeurl == "http://www.prohibitiondistillery.com/") {
	  mySound.play({volume:15});
  } else if ( homeurl == "http://www.prohibitiondistillery.com/home/") {
	  //mySound.setPosition('aSound',2500);
	  mySound.play();
  } else {
	  // do nothing
  }
		
});

soundManager.ontimeout(function() {

  // (Optional) Hrmm, SM2 could not start. Show an error, etc.?

});






