/* absinthe.js | absolutelyabsinthe.com */

WEBSITE= "absolutelyabsinthe.com";
self.focus();

currentImg= getCookieValue( "player");
if( !currentImg) { currentImg= 1; }

/* Replay */
// document.write( '<script type="text/javascript" src="http://static.robotreplay.com/nitobi.replay.js"></script>');

// ---------------------------------------
function getCookieValue( cookieName)
// ---------------------------------------
{
  var allCookies= document.cookie;
  var pos= allCookies.indexOf( cookieName + "=");
  if( pos == -1) return( false); // no such cookie; return false
  // otherwise:
  var start= pos + cookieName.length + 1;       // length of "name="
  var end=   allCookies.indexOf( ";", start);   // until first ";"
  if( end == -1) { end= allCookies.length; }    // or until the end
  return( allCookies.substring( start, end));   // return cookie value
}

// ---------------------------------------
function player( doWhat)
// ---------------------------------------
{
  if( doWhat == "init")
  {
    document.write(
        '<img id="playerImg" src="/img/p/' + currentImg + '.jpg">'
      + '<a href="javascript:player(' + "'prev'" + ')"><img src="/img/p/pL.gif" style="left: 39px; top: 172px;"></a>'
      + '<a href="javascript:player(' + "'next'" + ')"><img src="/img/p/pX.gif" style="left: 80px; top: 172px;"></a>'
      + '<a href="javascript:player(' + "'next'" + ')"><img src="/img/p/pR.gif" style="left: 193px; top: 172px;"></a>'
    );
  }
  else
  {
    if( doWhat == "next")
    {
      if( currentImg == 5) { currentImg= 1; }
      else                 { currentImg++;  }
    }
    else  // doWhat == "prev"
    {
      if( currentImg == 1) { currentImg= 5; }
      else                 { currentImg--;  }
    }
    document.getElementById( "playerImg").src= "/img/p/" + currentImg + ".jpg";
    document.cookie= "player=" + currentImg + "; path=/";
  }
  
}

// ---------------------------------------
function initNavi( currentPage, lastPage)
// ---------------------------------------
{ 
  var arrows= document.getElementById( "arrows");
  var navi= document.getElementById( "navi");
  
  if( arrows && navi) {
  
    // ---Arrows--- (first!)
    
    var arrowsHTML= "";
    var visibility= "";
    for( var i=0; i < lastPage+1; i++)
    {
      visibility= ( i == currentPage ? "visible" : "hidden" );
      arrowsHTML += '<img id="a' + i + '" src="/img/arr.gif" alt="" style="visibility: ' + visibility + '">';  
    }
    //alert( arrowsHTML);
    arrows.innerHTML= arrowsHTML;
    
    // ---Navi--- (second)
    
    var naviHTML= document.getElementById( "navi").innerHTML;
    
    // Important IE fix - must have linebreaks:
    var regex1= new RegExp( "<br>", "ig");
    naviHTML= naviHTML.replace( regex1, "<br>\n" );
    
    //alert( naviHTML);
    
    // The following doesn't work under IE, because image isn't <img src="..." alt="">, but <img alt="" src="...">
    // var regex2= new RegExp( "<a href=\"(.+)\"><img src=\"/img/navi/(.+)\.gif\" alt=\"\"></a>", "ig");
    
    var regex2= new RegExp( "<a [^<]*href=\"(.+)\"[^<]*><img [^<]*src=\"/img/navi/(.+)\.gif\"[^<]*></a>", "ig");  
    naviHTML= naviHTML.replace(
        regex2,
        "<a href=\"$1\" " 
      + " onmouseover=\"getElementById('a$2').style.visibility='visible'\" onmouseout=\"getElementById('a$2').style.visibility='hidden'\" "
      + "><img src=\"/img/navi/$2.gif\" alt=\"\"></a>"
    );
    navi.innerHTML= naviHTML;
    
    //alert( naviHTML);
  }

}

// ---------------------------------------
function em() {
// ---------------------------------------
  
  var x1= 'a' + 'i';
  var x2= ':';
  var x0= 59;
  var x3= String.fromCharCode( x0+5);
  
  if( document.getElementById) {

    var C= document.getElementById( "emC");
    if( C) {
      var name= C.innerHTML.toLowerCase();
      var x=   '<a hr' + "" + 'ef="m' + x1 + 'lto' + x2;
      x +=     name + x3 + WEBSITE + '" title="' + name + x3 + WEBSITE + '">' + C.innerHTML + '</a>';
      C.innerHTML= x;
    }
  }

} // end em()

// ---------------------------------------
function marilyn() {
// ---------------------------------------
  
  var x1= 'p' + '://www.absi';
  var x2= 'e';
  var x0= 65;
  var x3= String.fromCharCode( x0+4).toLowerCase();
  
  if( document.getElementById) {

    var M= document.getElementById( "marilyn");
    if( M) {
      M.style.fontWeight= 'normal';
      var currValue= M.innerHTML;
      var x=   '<a hr' + "" + x3 + 'f="htt' + x1 + 'nth' + x2;
      x +=     'f' + x3 + 'v' + x3 + 'r.com/absinthe/' + x3 + 'ffects"' + ' targ' + x3 + 't="_blank">'; 
      M.innerHTML= x + currValue + '</' + String.fromCharCode( x0) + '>';
    }
  }

} // end marilyn()

// ---------------------------------------
function initFeatr() {
// ---------------------------------------

  //
  // NOTE: Do not put an <IMG> that is NOT an advert into <DIV id="feat">
  //       else the regex will mess up!


  var element= document.getElementById( 'featr'); // This is a <DIV> element
  if( element)
  {

    // The following syntax will throw a compile-time (untrappable) error
    // if there is anything wrong:
    //
    // var regex= /(<img.*?img\/featr\/(.*?)NGG(..)\.(gif|jpg).*?>)/ig;

    // The following syntax will throw a run-time (trappable) error
    // if there is anything wrong:
    //
    // var regex= new RegExp( "(<img.*?img\/featr\/(.*?)NGG(..)\.(gif|jpg).*?>)", "ig");
    
    // But we can't use either of the above, because Internet Explorer 5.0
    // (in fact, any JavaScript 1.2) does NOT support non-greedy matching;
    // it is only available from version 1.3
    //
    // Here is the fix: we replace all ".*?" with "[^<]*", meaning "anything
    // other than the '<' character; this way, we never "run over" to another <tag>.
    // Also note we use the second syntax so that we can trap any possible errors,
    // and because it somehow seems more reliable/stable under Explorer 5.0
    // (and probably other earlier browsers).

    var regex= new RegExp( "(<img[^<]*img\/featr\/([^<]*)NGG(..)\.(gif|jpg)[^<]*>)", "ig");
    
    element.innerHTML= element.innerHTML.replace(
        regex,
        '<a hr'
   // + "ef=\"http://www.$2$3\" target=\"_blank\" onmouseover=\"window.status='http://www.$2$3/'; return true;\" onmouseout=\"window.status=''; return true;\" title=\"http://www.$2$3/\">$1<\/a>"
      + "ef=\"http://www.$2$3\" target=\"_blank\" onmouseover=\"window.status='http://www.$2$3/'; return true;\" onmouseout=\"window.status=''; return true;\">$1<\/a>"
    );
  }

} // end initFeat()

// ---------------------------------------
function initSpecl() {
// ---------------------------------------

  document.getElementById( "speclOne").onmouseover=  function()  { document.getElementById( "speclThree").style.visibility= "visible"; }
  document.getElementById( "speclOne").onmouseout=   function()  { document.getElementById( "speclThree").style.visibility= "hidden";  }
  document.getElementById( "speclOne").onclick=      function()
  {
      window.open( "/up/specials.html", "AbsolutelyAbsinthePopUpWindow", "left=12,top=12,width=584,height=660,scrollbars=no"); return( false);
  }
  
  document.getElementById( "speclTwo").onmouseover=  function()  { document.getElementById( "speclThree").style.visibility= "visible"; }
  document.getElementById( "speclTwo").onmouseout=   function()  { document.getElementById( "speclThree").style.visibility= "hidden";  }
  document.getElementById( "speclTwo").onclick=      function()
  {
      window.open( "/up/specials.html", "AbsolutelyAbsinthePopUpWindow", "left=12,top=12,width=584,height=660,scrollbars=no"); return( false);
  }
  
  document.getElementById( "speclThree").onmouseover= function() { document.getElementById( "speclThree").style.visibility= "visible"; }
  document.getElementById( "speclThree").onmouseout=  function() { document.getElementById( "speclThree").style.visibility= "hidden";  }
  document.getElementById( "speclThree").onclick=     function()
  {
      window.open( "/up/specials.html", "AbsolutelyAbsinthePopUpWindow", "left=12,top=12,width=584,height=660,scrollbars=no"); return( false);
  }
  
} // end initSpecl()

// ---------------------------------------
function initSpeclB() {   // "Buy" page
// ---------------------------------------

  document.getElementById( "speclOne").onclick=      function()
  {
      window.open( "/up/specials.html", "AbsolutelyAbsinthePopUpWindow", "left=12,top=12,width=584,height=660,scrollbars=no"); return( false);
  }

  document.getElementById( "speclTwo").onclick=      function()
  {
      window.open( "/up/specials.html", "AbsolutelyAbsinthePopUpWindow", "left=12,top=12,width=584,height=660,scrollbars=no"); return( false);
  }

  document.getElementById( "speclThree").onclick=     function()
  {
      window.open( "/up/specials.html", "AbsolutelyAbsinthePopUpWindow", "left=12,top=12,width=584,height=660,scrollbars=no"); return( false);
  }
  
} // end initSpeclB()

// ---------------------------------------
// Global (see function initVideo() below)
// ---------------------------------------
origCaption= "";
caption= new Array();
// ---------------------------------------

// ---------------------------------------
function initVideo() {
// ---------------------------------------

  var captionPara= document.getElementById( "smallPrint");
  
  origCaption= captionPara.innerHTML; // global
  
  // global:
  caption[1]= "Johnny Depp takes a sip. A great demonstration of the absinthe ritual!";
  caption[2]= "Elli Mayham's Green Fairy dream. Effects of absinthe animated in 3D.";
  caption[3]= "Euro Trippin' - And you thought absinthe didn't work?";
  
  var element;
  
  element= document.getElementById( "videoOne");
  if( element)
  {
    element.onmouseover= function() { captionPara.innerHTML= caption[1];  }
    element.onmouseout=  function() { captionPara.innerHTML= origCaption; }
  }
  
  element= document.getElementById( "videoTwo");
  if( element)
  {
    element.onmouseover= function() { captionPara.innerHTML= caption[2];  }
    element.onmouseout=  function() { captionPara.innerHTML= origCaption; }
  }
  
  element= document.getElementById( "videoThree");
  if( element)
  {
    element.onmouseover= function() { captionPara.innerHTML= caption[3];  }
    element.onmouseout=  function() { captionPara.innerHTML= origCaption; }
  }
  
} // end initVideo()
