var DDSPEED = 5;
var DDTIMER = 15;
var STATUS;


var PAGE;
// main function to handle the mouse events //
function ddMenu(action,id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
 clearInterval(c.timer);
  if(d == 1){
       clearInterval(c.timer);
     if(action=='over'){
      if(PAGE!='none'){
       hideSlide(PAGE,action);
        }
     }

    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight)
	{   return
    }
   else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';

    }

    if(STATUS=="up"){
       if (window.XMLHttpRequest) {
			// IE 7, mozilla, safari, opera 9
			  c.style.bottom="-32px";
			} else {
			    c.style.bottom="46px";
			// IE6, older browsers
			}
    }
    c.timer = setInterval(function(){ddSlide(h,c,1,id,action)},DDTIMER);



  }
  else if(d==-2){
 h.style.color='#000000';

  }
  else if(d==-1){
  if(id!==PAGE || STATUS=='down')  {
   h.timer = setTimeout(function(){ddCollapse(h,c,id,action)},50);
   if(PAGE!='none'){
        remainSlide();
   }
  
  }
  else{
      h.timer = setTimeout(function(){ddCollapse(h,c,id,'header')},50);
    }
  }
}


function hideSlide(id,action){
var h = document.getElementById(id + '-ddheader');
var c = document.getElementById(id + '-ddcontent');
    clearInterval(c.timer);
    clearTimeout(h.timer);
 h.timer = setTimeout(function(){ddCollapse(h,c,id,action)},50);



}
// collapse the menu //
function ddCollapse(h,c,id,action){
  c.timer = setInterval(function(){ddSlide(h,c,-1,id,action)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(field,id,status){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
 if(status==3&&PAGE!='none'){
     hideSlide(PAGE,field);
   
 }

  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(h,c,1,id,field)},DDTIMER);
    }

  }





// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(h,c,d,id,action){

 var background;

if (window.XMLHttpRequest) {
// IE 7, mozilla, safari, opera 9
 background="url(../images/bg_4.jpg)";
} else {
   background="#ffa501";
// IE6, older browsers
}
  var currh = c.offsetHeight;

  var dist;
  if(d == 1){
     h.style.color='#000';
     h.style.background=background;
     dist = (Math.round((c.maxh - currh) / DDSPEED));

    }else if(d==-1 && action=='header'){
    h.style.color='#000' ;
    h.style.background=background;
    dist = (Math.round(currh / DDSPEED));
   }else {
   h.style.color='#000';
   h.style.background="none";
   dist = (Math.round(currh / DDSPEED));
   }

  if(dist <= 1 && d == 1){
    dist = 1;
  }
if(id!=PAGE || action=='over'||STATUS=='down' ){
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
}

else{

  c.style.height = 0+ 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
    }




  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }

}


function showClick(field,id, defaultColor, pointerColor, markColor){
 var h = document.getElementById(id + '-ddheader');
 var c = document.getElementById(id + '-ddcontent');
    var newColor
    var currentColor

    currentColor=field.style.color;


    if ( currentColor.toLowerCase() == defaultColor.toLowerCase()) {

        newColor=markColor;
    }
    if ( currentColor.toLowerCase() == pointerColor.toLowerCase()) {
        newColor=markColor;
    }
    if (currentColor.toLowerCase() == markColor.toLowerCase()) {
        newColor=pointerColor;
    }
    if (newColor) {
        h.style.color='#000000';


    }



}
function  remainSlide(){
  ddMenu('out',PAGE,1);

}

function page(page){
  PAGE=page;

}
function changeColor(id){
     var h = document.getElementById(id);
      h.style.color='#fff';

}
  function upDownMenu(){
    var fudgeFactor = document.all? 4: 6; // Moz only
  var docHeight, totalHeight;
  var result;
 if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    totalHeight=window.innerHeight ;
    docHeight = document.body.scrollHeight+ fudgeFactor;

  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    totalHeight = document.documentElement.offsetHeight;
    docHeight   = document.documentElement.scrollHeight;
   // docHeight=docHeight-100;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    totalHeight = document.body.offsetHeight;
    docHeight = document.body.scrollHeight;
  //  docHeight=docHeight-100;
  }
      docHeight=docHeight-14;
  if(docHeight > totalHeight ){
      STATUS="up"
  }
  else{
     STATUS="down"
  }

return STATUS;


  }
   function upDown_Menu(){
  var fudgeFactor = document.all? 4: 6; // Moz only
  var docHeight, totalHeight;
  var result;
 if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    totalHeight=window.innerHeight ;
    docHeight = document.body.scrollHeight+ fudgeFactor;
    docHeight=docHeight-14;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    totalHeight = document.documentElement.offsetHeight;
    docHeight   = document.documentElement.scrollHeight;
    docHeight=docHeight-100;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    totalHeight = document.body.offsetHeight;
    docHeight = document.body.scrollHeight;
      
  }  


// alert(docHeight+"brower"+totalHeight)
 if(docHeight > totalHeight ){
     result="up"
 }
 else{
   result="down"
 }

return result;


  }



