var DDSPEED = 5;
var DDTIMER = 0;
ua = navigator.userAgent.toLowerCase();
ie6 = (ua.indexOf("msie") && document.all && ua.indexOf("netscape") == -1);
if (jQuery.browser.msie) {
if(parseInt(jQuery.browser.version) == 7) {
DDSPEED = 1;
} else if(ie6) {
DDSPEED = 1;
}
}
// main function to handle the mouse events //
function ddMenu(id, d) {
var h = document.getElementById(id + '-ddheader');
var c = document.getElementById(id + '-ddcontent');
clearInterval(c.timer);
if (d == 1) {
clearTimeout(h.timer);
if (c.maxh && c.maxh <= c.currh) { return }
else if (!c.maxh) {
c.style.display = "block";
c.style.visibility = 'visible';
c.style.height = 'auto';
c.maxh = c.offsetHeight;
c.currh = 0;
c.style.height = '0px';
}
c.timer = setInterval(function() { ddSlide(c, 1) }, DDTIMER);
} else {
h.timer = setTimeout(function() { ddCollapse(c) }, 50);
}
}
// collapse the menu //
function ddCollapse(c) {
c.timer = setInterval(function() { ddSlide(c, -1) }, DDTIMER);
}
// 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);
if (c.currh < 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.currh;
var dist;
if (d == 1) {
dist = (Math.round((c.maxh - currh) / DDSPEED));
$(c).prev('a.pnav').siblings().removeClass('hover');
$(c).prev('a.pnav').addClass('hover');
} else {
dist = (Math.round(currh / DDSPEED));
$(c).prev('a.pnav').removeClass('hover');
}
if (dist <= 1 && d == 1) {
dist = 1;
}
c.currh = (currh + (dist * d));
c.style.height = (currh + (dist * d)) + 'px';
if(ie6){
} else {
c.style.opacity = currh / c.maxh;
c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
}
// Collapse
if (currh < 5 && d != 1) {
clearInterval(c.timer);
c.style.height = "0px";
c.style.visibility = 'hidden';
c.maxh = 0;
c.currh = 0;
return;
}
// Expand
if (currh > (c.maxh - 2) && d == 1) {
clearInterval(c.timer);
}
}
function toggleHide(id) {
var c = document.getElementById(id + '-ddcontent');
if(c.currh > 0)
setTimeout(function() { ddCollapse(c) }, 50);
}
function toggleShow(id) {
var c = document.getElementById(id + '-ddcontent');
c.style.display = "block";
c.style.visibility = 'visible';
c.style.height = 'auto';
c.maxh = c.offsetHeight;
c.currh = 0;
c.style.height = '0px';
c.timer = setInterval(function() { ddSlide(c, 1) }, DDTIMER);
}
