////////////////////////////////////////////////
// Called by the EP_onEvent(evt) function
// (located in 'ep_player.js') when the status of 
// the player changes.

function EP_eventHandler(evt) 
{
	// write the event to the text-area in the HTML page
	//EP_logEvent(evt);
	
	switch(evt) {
		
		case 'MP3_LOADING':
			
			break;
		case 'MP3_BUFFERING':

			break;
		case 'MP3_PLAYING':
			
			// get track info
			var t = EP_getTrackInfo('ep_player');
			
			var i = document.getElementById('fls_songtitle');
			if(t)i.innerHTML = t.title;
			//alert(t.title);

			// write the event to the text-area in the HTML page
			//EP_logEvent('playlistIndex: '+t.playlistIndex);
			//EP_logEvent('location: '+t.location);
			//EP_logEvent('title: '+t.title);
			//EP_logEvent('annotation: '+t.annotation);
			//EP_logEvent('creator: '+t.creator);
			//EP_logEvent('info: '+t.info);
			//EP_logEvent('image: '+t.image);
			//EP_logEvent('album: '+t.album);
			//EP_logEvent('trackNum: '+t.trackNum);
			//EP_logEvent('link: '+t.link);
			//EP_logEvent('----------------------------');

			break;			
		case 'MP3_PREV':

			break;				
		case 'MP3_NEXT':

			break;			
		case 'MP3_SELECT':
		
			// write the event to the text-area in the HTML page
			EP_logEvent("Select MP3 (#"+EP_getTrackInfo('ep_player').playlistIndex+") from playlist ...");
			
			break;
		case 'MP3_PAUSED':

			break;
		case 'MP3_COMPLETE':

			break;			
		case 'MP3_STOPPED':

			break;						
		default:
			break;
	}
}

////////////////////////////////////////////////

// write the event to the text-area in the HTML page
function EP_logEvent(evt) 
{
	ep_form.events.value += '>'+evt+'\n';
}

//if(window.top==self) { 
//    var parentURL = "/index.php"
//    var childURL = window.location.href
//    var reframeURL = parentURL + "?" + childURL
//    location.href = reframeURL
//}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}
this.ie4 = document.all && !document.getElementById;
function showme(code,cat,file,extra){
  iSrc = ((this.ie4)?document.all[code]:document.getElementById(code));
  iTgt1 = ((this.ie4)?document.all['previewtextbox']:document.getElementById('previewtextbox'));
  iTgt2 = ((this.ie4)?document.all['previewimage']:document.getElementById('previewimage'));

switch(cat){
case 'originalmusic':
  if(document.all)iTgt1.filters(0).apply();
  iTgt1.innerHTML = iSrc.innerHTML;
  if(document.all)iTgt1.filters(0).play();

  if(document.all)iTgt2.filters(0).apply();
  iTgt2.style.backgroundImage = 'url(img/previewspecialbg.gif)';
  iTgt2.style.textAlign = 'right';
  iTgt2.style.verticalAlign = 'top';
  iTgt2.style.margin = '15px';
  iTgt2.innerHTML = '<img src="img/portfolio/' + cat + '/thumbs/' + file + '.gif" hspace="5" vspace="5" align="left" style="border-top: solid 1px white;border-left: solid 1px white;border-right: solid 2px #990000;border-bottom: solid 2px #990000;">' + extra + '<br clear="all"><img src="img/previewbg.gif" width=20 height=20>';
  if(document.all)iTgt2.filters(0).play();
  break;
default:
  if(document.all)iTgt1.filters(0).apply();
  iTgt1.innerHTML = iSrc.innerHTML;
  if(document.all)iTgt1.filters(0).play();

  if(document.all)iTgt2.filters(0).apply();
  iTgt2.innerHTML = '<img src="img/portfolio/' + cat + '/thumbs2/' + file + '.jpg">';
  if(document.all)iTgt2.filters(0).play();
}

}

// NEW SCRIPTS

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function setCookieArray(name){
    this.length = setCookieArray.arguments.length - 1;

    var expdate = new Date();
    expdate.setTime (expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 

    for (var i = 0; i < this.length; i++) {
    data = setCookieArray.arguments[i + 1]
    setCookie (name + i, data, expdate);
    }        
}

function getCookieArray(name){
var i = 0;
    while (getCookie(name + i) != null) {
    this[i + 1] = getCookie(name + i);
    i++; this.length = i; 
    }
}

function switchtext(str){
	document.getElementById('mytext').innerHTML = "\"" + str + "\"";
}

function opentext(str){
	switchtext(str);
	setTimeout("Effect.Appear('mytext')",1250);
}

function slideshowtext(){
	if(document.getElementById('mytext').innerHTML)Effect.Fade('mytext'); 
	eval("setTimeout(\"opentext(mytext[textnode])\",1250);");
	
	if(textnode <= mytext.length)textnode++;
	else textnode = 0;

	setTimeout("slideshowtext()",14000);
}

function UpdateSongInfo(){
	EP_updateTrackInfo('ep_player');
	setTimeout("UpdateSongInfo()",500);
}

function myplay(){
    var myexpdate = new Date();
    myexpdate.setTime (myexpdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	EP_play('ep_player');
	setCookie ('musicstate', 'play', myexpdate);
	//deleteCookie('musicstate');
}

function mystop(){
    var myexpdate = new Date();
    myexpdate.setTime (myexpdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	EP_stop('ep_player');
	//musicstate = getCookie('musicstate');
	setCookie ('musicstate', 'paused', myexpdate);
}

function init(){
    
	var musicstate = getCookie('musicstate');
	playerbox = document.getElementById('fls_player');
	//if(urlsegment != "shop")
	playerbox.style.display = "block";
	//<b>now playing:</b>
	playerbox.innerHTML = '<br /><span id="fls_songtitle"></span>';
	playerbox.innerHTML += '<div id="fls_controls"></div>';
	
	songtitle = document.getElementById('fls_songtitle');
	if(songtitle)songtitle.innerHTML = "&nbsp;";
	
	songcontrols = document.getElementById('fls_controls');
	if(songcontrols){
		songcontrols.innerHTML = '';
		songcontrols.innerHTML += '<a href="#" onclick="EP_prev(\'ep_player\'); return false; this.blur();" class="back"><span>Back</span></a>';
		songcontrols.innerHTML += '<a href="#" onclick="myplay(); return false; this.blur();" class="play"><span>Play</span></a>';
		songcontrols.innerHTML += '<a href="#" onclick="mystop(); return false; this.blur();" class="stop"><span>Stop</span></a>';
		songcontrols.innerHTML += '<a href="#" onclick="EP_next(\'ep_player\'); return false; this.blur();" class="forward"><span>Forward</span></a>';
		
		//if(urlsegment != "shop")
		so.addVariable("playlistxml", playlistxml);
		so.write("flashcontent");
		
		//EP_setPlayListXML("ep_player", playlistxml);
		//alert(playlistxml);

		if(musicstate == 'paused')so.addVariable("autoplay", "false");
		else so.addVariable("autoplay", "true");
		so.write("flashcontent");

		//alert(musicstate);
		if(musicstate != 'paused')setTimeout("EP_play('ep_player')",750);
		
		//UpdateSongInfo('ep_player');
		
		//<a href="#" onclick="EP_play('ep_player');">play</a><br />
		//<a href="#" onclick="EP_stop('ep_player');">stop</a><br />
		//<a href="#" onclick="EP_pause('ep_player');">pause</a><br />
		//<a href="#" onclick="EP_prev('ep_player');">previous track</a><br />
		//<a href="#" onclick="EP_next('ep_player');">next track</a><br />

		
	}
}

//window.onload = init;