

function menuItem( parentObj, attachTo, ind, aniDelay, txtOrObj)
{
  var _i = this;
  
  _i.parentObj = parentObj;
  _i.attachTo = attachTo;
  _i.ind = ind;
  _i.txt = ( typeof(txtOrObj) == "string" ) ? txtOrObj : txtOrObj.label;
  _i.aniDelay = aniDelay;
  _i.rendered = ( typeof(txtOrObj) != "string" );
  
  _i.cont = null;
  _i.label = null;
  _i.ani = null;
  _i.aniTarget = null;
  _i.aniRatio = null;
  
  _i.selected = null;
  _i.maxWidth = 185;
  
  _i.selectedX = 11;
  _i.unselectedX = 104;
    
  _i.hide = function()
  {
    _i.unselect();
    _i.ani.line( _i.cont, -xWidth(_i.cont), xTop(_i.cont), 625, 1, 0, _i.parentObj.doneHide );
  }
  
  
  _i.destroy = function()
  {
    _i.cont.parentNode.removeChild(_i.cont);
  }
  
  
  _i.contClick = function()
  {
    if ( _i.selected == true ) { return; }
    _i.parentObj.reportClick( _i.ind );
  }
  
  
  _i.select = function()
  {
    _i.selected = true;

    if ( _i.rendered == false )
    {
      _i.cont.style.backgroundColor = "#FBF509";
      _i.label.style.color = "#333333";
      return;
    }

    _i.label.style.backgroundPosition = "-" + txtOrObj.selectedX + "px -" + txtOrObj.top + "px";    
  }
  
  
  _i.unselect = function()
  {
    _i.selected = false;
    
    if ( _i.rendered == false )
    {
      _i.cont.style.backgroundColor = "#333333";
      _i.label.style.color = "#5F5F5F";
      return;
    }
    else
    {
      _i.label.style.backgroundPosition = "-" + txtOrObj.left + "px -" + txtOrObj.top + "px";      
    }
  }
  
  _i.mouseover = function()
  {
    if ( !_i.selected )
    {
      _i.label.style.backgroundPosition = "-" + txtOrObj.selectedX + "px -" + txtOrObj.top + "px";    
    }
  }
  
  _i.mouseout = function()
  {
    if ( !_i.selected )
    {
      _i.label.style.backgroundPosition = "-" + txtOrObj.left + "px -" + txtOrObj.top + "px";      
    }
  }
  
  _i.aniOut = function()
  {
    if ( _i.aniTarget > 10 );
    {
      _i.aniTarget *= _i.aniRatio;
      _i.aniRatio *= .8;
      _i.ani.line( _i.cont, -_i.aniTarget, _i.contStyleTopAsInt, _i.aniTarget * _i.parentObj.aniOutMsMultiplier, 1, 0, _i.aniIn );
    }
  }
  
  
  _i.aniIn = function()
  {
    if ( _i.aniTarget == null )
    {
      xLeft( _i.cont, -xWidth(_i.cont) );
      _i.cont.style.display = "block";
      
      _i.aniTarget = parseInt(_i.cont.style.width);
      _i.aniRatio = .15;      
    }

    var onEnd = _i.aniTarget > 0.5 ? _i.aniOut : undefined;
	_i.ani.line( _i.cont, 0, _i.contStyleTopAsInt, parseInt(_i.cont.style.width) * _i.parentObj.aniInMsMultiplier, 2, 0, onEnd );
  }
  
  
  _i.setTextWidth = function()
  {
    _i.label.innerHTML = "";
    _i.label.style.width = null;

    var tmpText = _i.txt;
    
    while ( strStyleWidth( tmpText, _i.label ) > _i.maxWidth )
    { tmpText = tmpText.substr( 0, tmpText.length - 1 ); }
    if ( tmpText != _i.txt ) { tmpText += "..."; }
    tmpText = tmpText.replace(/%20/g," ");
        
    var w = strStyleWidth( tmpText, _i.label );
    _i.label.style.width = w + 12 + "px";
    _i.cont.style.width = w + 12 + 18 + "px";
    
    _i.label.innerHTML = tmpText;

  }
  
  
  _i.changeText = function( txt )
  {
    _i.txt = txt;
    _i.setTextWidth();
  }
  
  
  _i.makeRenderedLabel = function()
  {
    _i.label = document.createElement("DIV");
    _i.label.style.position = "absolute";
    _i.label.style.left = "0px";
    _i.label.style.top = "0px";
    _i.label.style.width = txtOrObj.width + "px";
    _i.label.style.height = txtOrObj.height + "px";
    _i.label.style.backgroundImage = "url(images/forPng.png)";
    _i.label.style.backgroundRepeat = "no-repeat";
    _i.label.style.backgroundPosition = "-" + txtOrObj.left + "px -" + txtOrObj.top + "px";
    
    _i.cont.style.width = _i.label.style.width;
  }
  
  
  _i.makeTextLabel = function()
  {
    _i.label = document.createElement("DIV");
    if( isIplatform == true )
    {
      _i.label.className = "menuText menuTextIPlatform";
    }
    else
    {
      _i.label.className = "menuText";
    }
  }
  
  
  _i.constructor = function()
  {
    _i.ani = new xAnimation();
    _i.selected = false;

    _i.cont = document.createElement("DIV");
    _i.cont.className = "mediumShad";
    _i.cont.style.position = "absolute";
    _i.cont.style.display = "block";
    _i.cont.style.left = "-200px";
    _i.cont.style.marginBottom = "3px";
    _i.cont.style.left = "-100px";
    _i.cont.style.height = "30px";
    _i.cont.style.cursor = "pointer";
    
    _i.contStyleTopAsInt = _i.ind * 33;
    _i.cont.style.top = _i.contStyleTopAsInt + "px";
    
    if ( isIplatform != true )
    {
      _i.cont.onclick = _i.contClick;
      _i.cont.onmouseover = _i.mouseover;
      _i.cont.onmouseout = _i.mouseout;
    }
    else
    {
      _i.cont.ontouchstart = _i.contClick;
    }
    
    if ( _i.rendered == false )
    {
      _i.makeTextLabel();
    }
    else
    {
      _i.makeRenderedLabel();
    }
    
    _i.attachTo.appendChild(_i.cont);
    _i.cont.appendChild(_i.label);

    if ( _i.rendered == false )
    {
      _i.setTextWidth();
    }
    
    _i.unselect();
    
    setTimeout( _i.aniIn, _i.ind * _i.aniDelay );
  }
  
  _i.constructor();
}


function menu( parentObj, attachTo )
{
  var _i = this;
  
  _i.parentObj = parentObj;
  _i.attachTo = attachTo;
  
  _i.cont = null;
  _i.items = [];
  _i.selectedX = 11;
  _i.unselectedX = 104;
  _i.searchBox = null;
  _i.curSearchValue = "";
  _i.aniDelay = 100;
    
  _i.aniOutMsMultiplier = null;
  _i.aniInMsMultiplier = null;

  
  _i.mainItems = [
    { 
      label : "all",
      left : 104,
      top : 58,
      selectedX : 11,
      width : 80,
      height : 30,
      landmark : {
          url : "http://ozoneitsolutions.com/content/landing_all.png"
        }
    },
    { 
      label : "company",
      left : 104,
      top : 91,
      selectedX : 11,
      width : 75,
      height : 30,
      landmark : {
          url : "http://ozoneitsolutions.com/content/company.png"
        }
    },
    { 
      label : "services",
      left : 104,
      top : 124,
      selectedX : 11,
      width : 75,
      height : 30,
      landmark : {
          url : "http://ozoneitsolutions.com/content/services.png"
        }
    },
    { 
      label : "clients",
      left : 104,
      top : 157,
      selectedX : 11,
      width : 65,
      height : 30,
      landmark : {
          url : "http://ozoneitsolutions.com/content/clients.png"
        }
    },
    { 
      label : "products",
      left : 104,
      top : 190,
      selectedX : 11,
      width : 80,
      height : 30
    },
    { 
      label : "contact",
      left : 104,
      top : 223,
      selectedX : 11,
      width : 71,
      height : 30,
      landmark : {
          url : "http://ozoneitsolutions.com/images/cont.PNG"
        }
    },
    { 
      label : "press",
      left : 104,
      top : 256,
      selectedX : 11,
      width : 59,
      height : 30,
	  landmark : {
          url : "http://ozoneitsolutions.com/images/cont.PNG"
        }
    },
    { 
      label : "careers",
      left : 104,
      top : 289,
      selectedX : 11,
      width : 69,
      height : 30,
      landmark : {
          url : gWebServerUrl + "content/wp-content/uploads/2006/09/" + "landing_careers.png"
        }
    },
    { 
      label : "contact",
      left : 104,
      top : 355,
      selectedX : 11,
      width : 71,
      height : 30,
      landmark : {
          url : "http://ozoneitsolutions.com/works/artfactor/images/cont.PNG"
        }
    },
    
  ];
  
  
  _i.reportClick = function( ind, searchType )
  {
    if (( _i.items[ind].selected == true ) && ( ind < _i.mainItems.length ))
    {
      return;
    }
    
    for ( var z = 0; z < _i.items.length; z++ )
    {
      _i.items[z].unselect();
    }
    
    // if search text menu item
    if (( _i.items.length > _i.mainItems.length ) && ( ind < _i.mainItems.length ))
    {
      _i.items[_i.items.length-1].hide();
      _i.searchBoxClear();
    }

    if ( ind >= _i.mainItems.length ) 
    {
      if ( searchType == "search" )
      {
        window.location.hash = "/content/search/" + _i.curSearchValue;
      }
      
      if ( searchType == "tag" )
      {
        window.location.hash = "/content/tag/" + _i.curSearchValue;
      }
    }
    
    if (( ind >= 0 ) && ( ind < _i.mainItems.length ))
    {
      window.location.hash = "/content/category/" + _i.mainItems[ind].label;
    }
    
    _i.items[ind].select();
    
    _i.searchBoxClear();
    
    _i.parentObj.reportLocationChange();
  }
  
  
  _i.searchBoxTagSearch = function( tagStr )
  {
    _i.curSearchValue = tagStr;
    _i.searchBox.value = tagStr;
    _i.searchBox.style.color = "#FF0D47";
  }
  
  
  _i.searchBoxClear = function()
  {
    _i.curSearchValue = "";
    _i.searchBox.value = "Search";
    _i.searchBox.style.color = "#999999";
  }
  
  
  _i.doneHide = function( ind )
  {
    _i.items[_i.items.length-1].destroy();
    _i.items.length = _i.mainItems.length;
  }
  
  
  _i.searchBoxFocus = function()
  {
    if ( _i.searchBox.value == "Search" )
    {
      _i.searchBox.value = "";
    }
  }
  
  _i.abandonSearch = function()
  {
    _i.searchBox.value = "";
    _i.searchBox.blur();
  }
  
  _i.searchBoxBlur = function()
  {
    _i.searchBox.value = trim(_i.searchBox.value);
    
    if ( _i.searchBox.value == "" )
    {
      _i.searchBoxClear();
      return;
    }
    
    if ( _i.searchBox.value == _i.curSearchValue )
    {
      return;
    }
    
    _i.curSearchValue = _i.searchBox.value;
    _i.searchTag();
  }
  
  
  _i.categoryFromString = function( str )
  {
    for ( var z = 0; z < _i.mainItems.length; z++ )
    {
      if ( _i.mainItems[z].label == str )
      {
        return z;
      }
    }
    
    return -1;
  }
  
  
  _i.searchTag = function( tagStr )
  {
    if ( tagStr != null )
    {
      _i.curSearchValue = tagStr;
    }
    
    if ( _i.categoryFromString(_i.curSearchValue) > -1 )
    {
      _i.reportClick( _i.categoryFromString(_i.curSearchValue) );
      return;
    }
    
    if ( _i.items.length == _i.mainItems.length )
    {
      _i.addMenuItem( _i.curSearchValue );
    }
    else
    {
      _i.items[_i.items.length-1].changeText( _i.curSearchValue);
    }

    var searchType = ( tagStr != null ) ? "tag" : "search";
    
    _i.reportClick( _i.items.length - 1, searchType );
  }
  

  _i.menuFromLocation = function()
  {
    var arr = window.location.hash.toString().split("search/");
    
    if ( arr.length == 2 ) 
    {
      if (( arr[1] != null ) && ( arr[1] != "" ))
      {
        var searchStr = arr[1];
        _i.searchTag(searchStr);
        return;
      }
    }
    
   
    var arr = window.location.hash.toString().split("tag/");
    
    if ( arr.length == 2 )
    {
      if (( arr[1] != null ) && ( arr[1] != "" ))
      {
        var tagStr = arr[1];
        _i.searchTag(tagStr);
        return;
      }
    }
    
    
    var arr = window.location.hash.toString().split("category/");
    
    if ( arr.length == 2 )
    {
      if (( arr[1] != null ) && ( arr[1] != "" ))
      {
        var categoryStr = arr[1];
        _i.searchTag(categoryStr);
        return;
      }
    }
    
    
    var arr = window.location.hash.toString().split("content/");
    
    if ( arr.length == 2 )
    {
      if (( arr[1] != null ) && ( arr[1] != "" ))
      {
        var articleStr = arr[1];
        _i.parentObj.initialArticle = articleStr;
      }
    }
    
    _i.reportClick(0);
  }
  
    
  _i.addMenuItem = function( txtOrObj )
  {
    _i.items[_i.items.length] = new menuItem( _i, _i.cont, _i.items.length, _i.aniDelay, txtOrObj );
  }
  
  
  _i.searchBoxKeydown = function(evt)
  {
    evt = evt || window.event;
    
    if (( evt.keyCode == 13 ) && ( trim(_i.searchBox.value) != "" ))
    {
      _i.searchBox.blur();
    }
  }
  
  
  _i.resetAniMultiplier = function()
  {
    _i.aniDelay = 0;
    _i.aniOutMsMultiplier = 3;
    _i.aniInMsMultiplier = 3;
  }
  
  
  _i.bgroundMousemove = function( evt )
  {
    evt = evt || window.evt;
    cancelEvent(evt);
  }
  

  _i.setContSize = function()
  {
    var w = 1;
    
    for ( var z = 0; z < _i.items.length; z++ )
    {
      var nw = xWidth(_i.items[z].cont);
      if ( nw > w ) { w = nw; }
    }

    var lstCnt = _i.items[_i.items.length-1].cont;
    var tp = xPageY(_i.cont);
    var btm = xPageY(lstCnt) + xHeight(lstCnt);
    
    xWidth( _i.cont, w );
    xHeight( _i.cont, btm - tp );
  }
  
  
  _i.constructor = function()
  {
    _i.aniOutMsMultiplier = ( isIplatform != true ) ? 6 : 10;
    _i.aniInMsMultiplier = ( isIplatform != true ) ? 6 : 10;

    _i.cont = document.createElement("DIV");
    _i.cont.style.position = "absolute";
    _i.cont.style.left = "0px";
    _i.cont.style.top = "120px";
    _i.cont.style.zIndex = 1;
    
    _i.bground = document.createElement("DIV");
    _i.bground.style.position = "absolute";
    _i.bground.style.left = "0px";
    _i.bground.style.top = "0px";
    _i.bground.style.width = "100%";
    _i.bground.style.height = "100%";
    _i.bground.style.backgroundColor = "#FFFFFF";
    xOpacity( _i.bground, .01 );
    
    _i.searchBox = document.createElement("INPUT");
    _i.searchBox.style.position = "absolute";
    _i.searchBox.style.right = "15px";
    _i.searchBox.style.top = "15px";
    _i.searchBox.style.width = "165px";
    _i.searchBox.style.height = ( isIplatform == true ) ? "30px" : "23px";
    _i.searchBox.style.fontFamily = "Arial";
    _i.searchBox.style.fontSize = ( isIplatform == true ) ? "14px" : "11px";
    _i.searchBox.style.fontWeight = "bold";
    _i.searchBox.style.color = "#999999";
    _i.searchBox.value = "Search";
    _i.searchBox.style.lineHeight = ( isIplatform == true ) ? "30px" : "23px";
    _i.searchBox.style.paddingLeft = "12px";
    _i.searchBox.style.border = "0px";
    _i.searchBox.style.backgroundColor = "#FFFFFF";
    _i.searchBox.onfocus = _i.searchBoxFocus;
    _i.searchBox.onblur = _i.searchBoxBlur;
    _i.searchBox.style.outline = "none";
    _i.searchBox.onkeydown = _i.searchBoxKeydown;
    _i.searchBox.type = "text";
    _i.searchBox.spellcheck = "off";
    
    _i.attachTo.appendChild(_i.cont);
    _i.cont.appendChild(_i.bground);
    _i.attachTo.appendChild(_i.searchBox);
    
    for ( var z = 0; z < _i.mainItems.length; z++ )
    {
      _i.addMenuItem( _i.mainItems[z] );
    }
    
    if ( isIplatform != true )
    {
      _i.bground.onmousemove = _i.bgroundMousemove;
    }
    
    setTimeout( _i.resetAniMultiplier, 5000 );
    
    _i.setContSize();
  }
  
  _i.constructor();
}



