/*
 * Javascript for the Events page
 * Date: 2010-07-09 
 * Revision: 003
 */

var playtext = [];
	playtext[0]="This piece was written by George Gershwin & arranged by Goff Richards, a Cornishman who is a prolific writer and arranger of brass band and other music, reposonsible for several of tonight's selection.";
	playtext[1]="Written by Peter Graham, featuring themes including 'London Pride' , 'Who will Buy ?' & 'A Nightingale sang in Berkeleey Square";


	function showmask(){
		var e = document.getElementById('overlay');
		e.style.visibility='visible';
		}

	function hidemask(){
	var e=document.getElementById('overlay');
	e.style.visibility='hidden';
	}
	
	function playup(tpic)	{
	var pivdiv = $('#playdiv');
	var filename = "Playlists/" +  "Div-" + tpic + ".htm";
		pivdiv.load(filename);
 		pivdiv.show(10,function() {pivdiv.center();});
		showmask();
		pivdiv.center();
	}

	

	function playajax(tpic)	{

	var pivdiv = $('#playdiv');
	var filename = "Playlists/" +  tpic + ".txt";
// 	alert(filename);
	$.getJSON(filename, function(data) 
			{
			var ts = data.Tracks;
			// alert('Parsed');
			$("#playdiv").empty();
			$(topbar()).appendTo("#playdiv");	
  		 	$('<h1>' + data.Title + '</h1>' + '<ul>' ).appendTo("#playdiv");
			$.each(data.Tracks, function(i,item)
				{
		         if (item.Track=="INTERVAL")
				 	 		$("<BR><h2>Interval</h2><BR>").appendTo("#playdiv");

				 else {
				   	var line = "<a href='#' id='" + i +"' onMouseOver='javascript:minipop(this);' onMouseOut='hideminipop()'>" + item.Track + "</a>";
  					playtext[i] =item.Desc;
  					$("<li>"  +  line + "</li>").appendTo("#playdiv");
					}

				 });

	    $("</ul>").appendTo("#playdiv");
			$("<div id='Caption' class='Caption'> Playlist for the " + data.Title + '  ' + data.Date +" </div>").appendTo("#playdiv");
	});


   		$("#playdiv").show(10,function() {$('#playdiv').center();});
			// var  el=document.getElementById('playdiv');
			// centrel(el);

		showmask();
	} // end of 'playajax'
	

	function topbar(){
	var div = ' <div Class="CloseX">' ;
	div = 	div + '<span class="jsAction" onclick="playdown();">Close</span>'; 
	div = 	div +'</div>';
	return div;
	} // end of 'topbar'

	

	function playdown(tpic)	{
	var pivdiv = $('#playdiv');
   		pivdiv.fadeOut(5);
		hidemask();
		return false;
	}	// end of 'playdown'
	

function minipop(el) {
	var par= $('#playdiv');
	var pos = par.offset();   
	var id = parseInt(el.id);	
	var x =el.offsetLeft +  pos.left;
  var y =el.offsetTop +  pos.top;
	var tracktext = "<p>Information about the track</p>";

 	// alert ('x=' + x + " y=" + y);

	if (playtext[id])
		{tracktext = playtext[id]}

	var pu = $('#popdiv');

	 pu.css('top', y + 0); 
	 pu.css('left', x + 200); 

  $('#popdiv').html(tracktext);
	$('#popdiv').fadeIn('fast') ;

	return false;
	}



	function hideminipop() {
		 $('#popdiv').fadeOut(10);
	return false;
	}

	
	function centrel(el)
	{
      el.css('top', $(window).height()/2- el.height()/2); 
  	  el.css('left', $(window).width()/2- el.width()/2); 
	}

	

	// Doc ready Function 

	  $(function(){
         $.fn.fadeToggle = function(speed, easing, callback) 
		{return this.animate({opacity: 'toggle'}, speed, easing, callback);}


		$.fn.cen = function()
		{ var h = this.height()/2;
		  var w =  this.width()/2	;
          this.css('top', $(window).height()/2 - h); 
  	      this.css('left', $(window).width()/2 - w);
					return this;
	    }

		jQuery.fn.center = function () {
    			this.css("position","absolute");
					this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
					this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
					return this;
		}

			
			
			
     }); // End of Doc Ready




