/*** undermenu control 0.2
     1008 - 2010.06.13
     (c) cryout creations
     part of htx.ro ***/

// var undermenu_timer - defined in config
// var undermenu_wait - defined in config
var currentid = 1;
var th = 0 ; // timer handle
var twh = 0 ; // timer_wait handle
var tix = 0 ; // initial_timer handle
var sleep = 0 ; // wether or not to sleep the undermenu

function step(n){
if (sleep==0) {
debug(th+": slider - step "+n);
if (document.getElementById('foaieloading').display = 'block') {Effect.Fade('foaieloading', { duration: 1 });};
for (var i=1;i<7;i++) {
          if (document.getElementById('foaie'+i).style.zIndex==5) {
                                                                  document.getElementById('item'+i).src=underimgs[i].replace('.jpg','')+'.jpg';
                                                                  document.getElementById('foaie'+i).style.zIndex=3;
                                                                  Effect.Fade('foaie'+i, { duration: 0.5 });
                                                                  }
          else if (i==n) {
                         document.getElementById('foaie'+n).style.zIndex=5;
                         document.getElementById('item'+n).src=underimgs[n].replace('.jpg','')+'_3.jpg';
                         Effect.Appear('foaie'+n, { duration: 0.5 }); }
                      } //for
} //if
}

function sw(n){
if (currentid!=n) {
     debug('#  cleared th='+th);
     clearInterval(th); th=0;
     if (twh>0) { debug('#  cleared twh='+twh); clearTimeout(twh); twh=0;};
     twh = setTimeout('sliderStart()',undermenu_wait*1000);
     debug('#  new twh='+twh);
     currentid = n;
     step(n);
     }
else {
     debug('#  clicked on active item; nothing to do');
     }
}

function slider(){
if (currentid>=6) {currentid=1;} else {currentid+=1;}
debug(th+": slider call s("+currentid+")");
step(currentid);
}

function sliderStart(){
if (currentid>=6) {currentid=0;}
step(currentid+1);
currentid+=1;
th = setInterval('slider()',undermenu_wait*1000);
debug('#  new th='+th);
debug(th+": slider starting...");
}

function initialSliderStart(){
var tix = setTimeout('sliderStart()',undermenu_wait*1000);
}

function roll2(img_name, i, s){
//img_name = img_name.replace('.jpg','');
var new_img = underimgs[i].replace('.jpg','');
switch(s){
     case 2: // mouseover
          debug('-roll2('+i+','+s+') mouseover');
          document[img_name].src = new_img+'_'+s+'.jpg';
          break;
     case 3: // mouseclick
          debug('-roll2('+i+','+s+') mouseclick');
          document[img_name].src = new_img+'_'+s+'.jpg';
          break;
     default: // mouseout
          if (currentid==i) {
                            debug('-roll2('+i+','+s+') current');
                            document[img_name].src = new_img+'_3.jpg';
                            }
                         else {
                            debug('-roll2('+i+','+s+') mouseout');
                            document[img_name].src = new_img+'.jpg';
                            }
} // switch
}

function pause(w){
if (w==1) {
// sit and wait...
     debug('#  mouse motion detected; updating sleep (1)');
     sleep = 1;
} else {
// reenable timers
     sleep = 0;
     debug('#  mouse motion detected; updating sleep (0)');
}
}

/* END */
