
/************************
123RF.com Navigation Menu
************************/

hideElements = new Array();

// hides selectors when user rolls over horizontal dropdown
function findForm() {
  //alert('this is ie');
  //hideElements = new Array();
  for (var f=0; f<window.document.forms.length; f++) {
    var theForm = window.document.forms[f];
    for (var e=0; e<theForm.elements.length; e++) {
      var theElem = theForm.elements[e];
      if (theElem.type.substr(0,6) == "select") {
        hideElements.push(theElem);
      }
    }
  }
}


// set up month rollover scripts
function setNav() {

  // decide if dropdown should hide any flash objects on the page
  var av = navigator.appVersion.toLowerCase();
  var ua = navigator.userAgent.toLowerCase();
  var platform;
  var browser;
  var hideFlash = false;
  var hideAd = false;
  if (av.indexOf("mac") != -1) {
    platform = "mac";
  } else if (av.indexOf("windows") != -1) {
    platform = "win";
  }
  if (ua.indexOf("firefox") != -1) {
    browser = "firefox";
  }

  // if firefox...
  if (browser == "firefox") {
    //alert('user has firefox');
    hideFlash = true;
  }

  if (browser == "firefox" || ua.indexOf("safari") != -1) {
    hideAd = true;
  }



  // swfPresent will be defined if hiding swfs
  if (window.swfList) {
    swfPresent = true;
    //alert('hiding: '+swfsToHide);
    //alert(swfList.length);
  } else {
    swfPresent = false;
    //alert('nothing to hide');
  }



  // drop down
  if (document.getElementById && document.getElementById("topNav")) {
    navRoot = document.getElementById("topNav");
    var IfrRef = document.getElementById('DivShim');

    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.className == "collapsed") {


        node.onmousemove = function() {
        // node.onclick = function() {
          this.className = 'expanded';

          // only apply to IE6 and lower
          if (isIE && !isIE7) {
            // for (e=0; e<hideElements.length; e++) {
            //   var formElem = document.getElementById(hideElements[e].id);
            //   formElem.style.visibility = 'hidden';
            // }

            // alert(this.childNodes[1].offsetWidth);

            if (this.hasChildNodes()) {
               var children = this.childNodes;
               for (var i = 0; i < children.length; i++) {
                    // do something with each child as children[i]
                    // NOTE: List is live, Adding or removing children will change the list
                    if (this.childNodes[i].className == 'dropContainer') {
                        var dropContainer = this.childNodes[i];

                        if (dropContainer.hasChildNodes()) {
                            var theMenu = dropContainer.childNodes[0];

                            IfrRef.style.width = theMenu.offsetWidth;
                            IfrRef.style.height = theMenu.offsetHeight;
                            IfrRef.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0, opacity=0)';

                            // IfrRef.style.top = theMenu.style.top;
                            // IfrRef.style.left = theMenu.style.left;
                            // alert(theMenu.offsetLeft);

                            var coord = findPos(theMenu);
                            IfrRef.style.top = coord[1];
                            IfrRef.style.left = coord[0];

                            // IfrRef.style.zIndex = theMenu.style.zIndex - 1;
                            IfrRef.style.zIndex = 0;
                            IfrRef.style.display = 'block';
                        }
                    }
                }
            }
          }

          // This hides the flash object(s)
          if (hideFlash && swfPresent) {
            for (var s=0; s<swfList.length; s++) {
              var flashobject = document.getElementById(swfList[s]);
              flashobject.style.visibility = 'hidden';
            }
          }

          // hides ad
          /*
          if (hideAd && this.childNodes[1].innerHTML == "More [+]") {
            if (document.getElementById('ad_InContent') != null) {
              document.getElementById('ad_InContent').style.height = '262px';
            } else if (document.getElementById('ad_Poster') != null) {
              document.getElementById('ad_Poster').style.height = '612px';
            }
            var adObj1 = document.getElementById('ad');
            var adObj2 = document.getElementById('adslug');
            adObj1.style.display = 'none';
            adObj2.style.display = 'none';
          }
          */


        }

        node.onmouseout = function() {
          this.className = 'collapsed';

          // testing form thing
          if (isIE) {
            // for (e=0; e<hideElements.length; e++) {
            //   var formElem = document.getElementById(hideElements[e].id);
            //   formElem.style.visibility = 'visible';
            // }

            IfrRef.style.display = "none";

          }

          // This unhides the flash object(s)
          if (hideFlash && swfPresent) {
            for (var s=0; s<swfList.length; s++) {
              var flashobject = document.getElementById(swfList[s]);
              flashobject.style.visibility = 'visible';
            }
          }

          // unhides ad

          /*
          if (hideAd && this.childNodes[1].innerHTML == "More [+]") {
            var adObj1 = document.getElementById('ad');
            var adObj2 = document.getElementById('adslug');
            adObj1.style.display = 'block';
            adObj2.style.display = 'block';
          }
          */


        }

        for (j=0; j<node.childNodes.length; j++) {
          if (node.childNodes[j].className == "dropContainer") {

            elem = node.childNodes[j];
            for (k=0; k<elem.childNodes.length; k++) {

              // find 1st tier dropdowns
              if (elem.childNodes[k].className == "dropMenu" || elem.childNodes[k].className == "anchorDropMenu") {
                menuElem = elem.childNodes[k];

                for (q=0; q<menuElem.childNodes.length; q++) {

                  if (menuElem.childNodes[q].className == "dropItem") {

                    dropElem = menuElem.childNodes[q];
                    dropElem.onmouseover = function() {
                    // dropElem.click = function() {
                      //
                      this.className = 'dropItemHi';
                    }
                    dropElem.onmouseout = function() {
                      //
                      this.className = 'dropItem';
                    }

                    // find 1st tier drop items that are also 2nd tier dropdowns
                    for (d=0; d<dropElem.childNodes.length; d++) {
                      if (dropElem.childNodes[d].className == "dropMenu2") {
                        // found one
                        tier2Item = dropElem.childNodes[d];
                        // assign rollovers
                        for (r=0; r<tier2Item.childNodes.length; r++) {
                          if (tier2Item.childNodes[r].className != "rule") {
                            tier2Item.childNodes[r].onmouseover = function() {
                            // tier2Item.childNodes[r].onclick = function() {
                              this.className = 'dropItemHi';

                            }
                            tier2Item.childNodes[r].onmouseout = function() {
                              this.className = 'dropItem';
                            }
                          }
                        }
                      }
                    }
                  } else if (menuElem.childNodes[q].className == "dropItem_s") { // special drop item, i.e. partner sites
                    dropElem = menuElem.childNodes[q];
                    dropElem.onmouseover = function() {
                    // dropElem.onclick = function() {
                      //
                      this.className = 'dropItemHi_s';
                    }
                    dropElem.onmouseout = function() {
                      //
                      this.className = 'dropItem_s';
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  if (navigator.appName == "Microsoft Internet Explorer" && platform != "mac") {
    isIE = true;

    isIE7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;


    window.attachEvent("onload", findForm);
    //window.onload = findForm;
  }

  else {
      isIE = false;
      isIE7 = false;
  }
}


function goTo(where) {
  window.location = where;
}

function goToNew(where,winName,features) {
  window.open(where,winName,features);
}


// do it
window.onload = setNav;

// unrelated for html dropdowns
function gotosite(site) {
    if (site != "") {
        window.location=site;
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}