var DDSPEED = 5;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  h.style.backgroundImage = "url(/images/menu/header_blue_over.gif)";
  clearInterval(c.timer);
  c.style.display = 'block';
  c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  if(d == 1){
    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';
	}
  }else{
	h.style.backgroundImage = "url(/images/menu/header_blue.gif)";
    h.timer = setTimeout(function(){ddCollapse(c,h)},10);
	clearInterval(c.timer);
  	
  }
}

function ddHome(d){
	var h = document.getElementById('one-ddheader');
	if(d == 1){
		h.style.backgroundImage = "url(/images/menu/header_blue_over.gif)";
	}else{
		h.style.backgroundImage = "url(/images/menu/header_blue.gif)";
	}
}
	
function liHover(d){
	var h = document.getElementById('one-ddheader');
	if(d == 1){
		h.style.backgroundImage = "url(/images/menu/header_blue_over.gif)";
	}else{
		h.style.backgroundImage = "url(/images/menu/header_blue.gif)";
	}
}

// collapse the menu //
function ddCollapse(c,h){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
  h.style.backgroundImage = "url(/images/menu/header_blue.gif)";
  c.style.display = 'none';
 // c.style.height = '0px';
//  c.offsetHeight = '0px';
//  c.maxh = '0px';
//  clearTimeout(h.timer);
//  clearInterval(c.timer);
  
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  h.style.backgroundImage = "url(/images/menu/header_blue_over.gif)";
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  if (currh + (dist * d) > c.maxh){
	  c.style.height = c.maxh;
  }else{
  	c.style.height = currh + (dist * d) + '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 ChangePic(img_name,img_src) {
document[img_name].src=img_src;
}

function ChangeBkgnd(div_name,img_src) {
document.getElementById(div_name).style.backgroundImage = img_src;
}

function Search() {
	var query = document.getElementById('query_text').value;
	if (query == "Search Masterclock.com...") {return;}
	if (query == "") {return;}
	//window.navigate('../MCsearch.asp?query_text=' + query);	
	//window.location.href='../MCsearch.php?query_text=' + query;
	
	// This passes to the search program the text that the user entered into the search box.
	// In the file search.php the variable called zoom_query holds the text to search for.
	window.location.href='../zoom_search_engine/search.php?zoom_query=' + query;
}

function SearchText(query_text) {
	document.getElementById('query_text').style.color = "#000000";
	document.getElementById('query_text').style.fontStyle = "normal";
	document.getElementById('query_text').value = query_text; 
	document.getElementById('query_text').select();
	document.getElementById('query_text').focus();
}

function CheckClearStatus() {
	var docURL = document.URL;
	if (docURL.search("query_text") == -1) {
		document.getElementById('query_text').value = "";
		document.getElementById('query_text').style.color = "#000000";
		document.getElementById('query_text').style.fontStyle = "normal";
		}
}

var newwindow = '';
function OpenPopup(url,ht,wd) {

var lft = parseInt((screen.availWidth/2) - (wd/2));
var tp = parseInt((screen.availHeight/2) - (ht/2));
    	
if (newwindow.location && !newwindow.closed) {
    newwindow.location.href = url; 
    newwindow.focus(); } 
else { 
    newwindow=window.open(url,'_blank','width=' + wd + ',height=' + ht + ',top=' + tp + ',left=' + lft + ',resizable=0,scrollbars=1');} 
}


function ClosePopup() {
if (newwindow.location && !newwindow.closed) { 
   newwindow.close(); } 
}