var onPhone = navigator.userAgent.match( "iPhone"  );
var inApp = document.location.href.match( "ident=" );

if ( !inApp  && !document.cookie.match( /ident=/ ) ) {
  var dt = new Date();
  dt.setTime(dt.getTime()+7.*24*60*60*1000);
  //alert(  
  document.cookie = "ident="+-Math.random()*2147483648+"; expires="+dt.toGMTString();
  // );
}

if ( onPhone && !inApp ) {
  try {
   document.location.href =  "onematrix:"+document.location.hash;
   //window.open ( "twomatrix:"+document.location.hash );
  }
catch ( e ) {
  alert( "Please install SoundMatrix" );
 }
   //setTimeout( "close();", 500 );
}

function player(link, state) {
  link.href = "cgi-bin/smsynth.cgi?onematrix:"+state;
  if ( inApp )
       return true;
  document.getElementById("dummyspan").innerHTML =
    "<span><embed src='"+ link.href +"' height=0 hidden=true autostart=true loop=false></span>";
  return false;
}

function loader(link,state) {
  link.href = (onPhone?"":"cgi-bin/smsynth.cgi?")+"onematrix:"+state;
  if ( inApp )
    link.href += "&download";
  else
     link.target = "_blank";
  return true;
}

function clicker(link) {
  link.href += document.location.search;
  return true;
}

var lastfm;

function onsub(fm) {
  if ( fm == lastfm ) {
    alert( "You've already voted on this matrix." );
    return false;
  }
  lastfm = fm;
  fm.ident.value = (inApp ? 
	document.location.href : document.cookie)
	.match( /ident=(-?\d+)/ )[1];
  fm.action = "cgi-bin/ratematrix.cgi";
  fm.target = "hiframe";
  return true;
}

function force() {
  if ( lastfm )
    document.getElementById( lastfm.path.value ).src += "?1";
}


