var startHiding = null;
var hiding = null;
var startHiding2 = null;
var hiding2 = null;
var mzoom = 100;
var lzoom = 100;
var hidingSearch = null;
var startShow = null;
var startShow2 = null;
var q_defaultText = "Digite aqui o que está procurando";
/*
Prefix-correcting evaluate statement from http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/119
*/

if( document.implementation.hasFeature("XPath", "3.0") ){
 XMLDocument.prototype.selectNodes = function(cXPathString, xNode){
  if( !xNode ) {
   xNode = this;
  }
    
  var defaultNS = this.defaultNS;

  var aItems = this.evaluate(cXPathString, xNode,{
   normalResolver:
    this.createNSResolver(this.documentElement),
        lookupNamespaceURI : function (prefix) {
           switch (prefix) {
             case "dflt":
                return defaultNS;
             default:
                return this.normalResolver.lookupNamespaceURI(prefix);
           }
        }
      },XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);

  var aResult = [];
  for( var i = 0; i < aItems.snapshotLength; i++){
           aResult[i] =  aItems.snapshotItem(i);
  }
  return aResult;
 }

 Element.prototype.selectNodes = function(cXPathString){
  if(this.ownerDocument.selectNodes){
   return this.ownerDocument.selectNodes(cXPathString, this);
  }else{
   throw "For XML Elements Only";
  }
 }

 /* set the SelectionNamespaces property the same for NN or IE: */
 XMLDocument.prototype.setProperty = function(p,v){
  if(p=="SelectionNamespaces" && v.indexOf("xmlns:dflt")==0){
   this.defaultNS = v.replace(/^.*=\'(.+)\'/,"$1");
  }
 }

 XMLDocument.prototype.defaultNS;

}

function showmenu()
{
	if(startShow == null) {
		if(startHiding2 != null) {
			window.clearTimeout(startHiding2);
			startHiding2 = null;
			//hidelojas4();
		}
		if(hiding != null) {
			mzoom = 0;
			window.clearTimeout(hiding);
			hiding = null;
		}
		startShow = window.setInterval('showmenu2()', 500);
	}
}
function showmenu2()
{
	window.clearInterval(startShow);
	startShow = null;
	var m = document.getElementById('floatingmenu');
	//var d = document.getElementById('d');
	//var q = document.getElementById('q');
	//q.style.visibility = 'hidden';
	//d.style.visibility = 'hidden';
	mzoom = 100;
	m.style.zoom = '100%';
	m.style.display = 'block';
	m.style.visibility = 'visible';
	fixmenu();
}
function fixmenu()
{
	if(startHiding != null) {
		window.clearTimeout(startHiding);
		startHiding = null;
	}
}
function hidemenu()
{
	if(startShow != null) {
		window.clearInterval(startShow);
		startShow = null;
		return;
	}
	if(startHiding == null)
	{
		startHiding = window.setTimeout('hidemenu4()', 500);
	}
}
function hidemenu2()
{
	hiding = window.setTimeout('hidemenu3()', 10);
}
function hidemenu3()
{
	var m = document.getElementById('floatingmenu');
	if(mzoom > 30) {
		m.style.zoom = mzoom + '%';
		mzoom -= 10;
		hidemenu2();
	}
	else {
		hidemenu4();
	}
}
function hidemenu4()
{
	var m = document.getElementById('floatingmenu');
	//var d = document.getElementById('d');
	//var q = document.getElementById('q');
	m.style.display = 'none';
	m.style.visibility = 'hidden';
	//d.style.visibility = 'visible';
	//q.style.visibility = 'visible';
}

function showlojas()
{
	if(startShow2 == null) {
		if(startHiding != null) {
			window.clearTimeout(startHiding);
			startHiding = null;
			hidemenu4();
		}
		if(hiding2 != null) {
			lzoom = 0;
			window.clearTimeout(hiding2);
			hiding2 = null;
		}
		startShow2 = window.setInterval('showlojas2()', 500);
	}
}
function showlojas2()
{
	window.clearInterval(startShow2);
	startShow2 = null;
	
	var m = document.getElementById('floatinglojas');
	var d = document.getElementById('d');
	var q = document.getElementById('q');
	lzoom = 100;
	m.style.zoom = '100%';
	q.style.visibility = 'hidden';
	d.style.visibility = 'hidden';
	m.style.display = 'block';
	m.style.visibility = 'visible';
	fixlojas();
}
function fixlojas()
{
	if(startHiding2 != null) {
		window.clearTimeout(startHiding2);
		startHiding2 = null;
	}
}
function hidelojas()
{
	if(startShow2 != null) {
		window.clearInterval(startShow2);
		startShow2 = null;
		return;
	}
	if(startHiding2 == null)
	{
		startHiding2 = window.setTimeout('hidelojas4()', 500);
	}
}
function hidelojas2()
{
	hiding2 = window.setTimeout('hidelojas3()', 10);
}
function hidelojas3()
{
	var m = document.getElementById('floatinglojas');
	if(lzoom > 30) {
		m.style.zoom = lzoom + '%';
		lzoom -= 10;
		hidelojas2();
	}
	else {
		hidelojas4();
	}
}
function hidelojas4()
{
	var m = document.getElementById('floatinglojas');
	var d = document.getElementById('d');
	var q = document.getElementById('q');
	m.style.display = 'none';
	m.style.visibility = 'hidden';
	d.style.visibility = 'visible';
	q.style.visibility = 'visible';
}
function searchOnKey(q)
{
	preview.query(q.value, 
		function() {
			var o = document.getElementById('instantsearch');
			o.style.posLeft = 230;
			o.style.posTop = 80;
			o.style.display = 'block';
			o.style.visibility = 'visible';
			document.getElementById('instantsearch').innerHTML = '';
		},
		function(texto, codigoProduto) {
			var r = document.getElementById('instantsearch').innerHTML;
			r += '<a class="quicklink" href=\'javascript:goProduto("' + codigoProduto + '")\'>' + texto + '</a><br>';
			document.getElementById('instantsearch').innerHTML = r;
		},
		function() {
			hideInstantSearch2();
		});
}
function goProduto(c)
{
	document.location.href = '/Click.aspx?id=busca_preview&dest=/Produto.aspx$codigo=' + c;
}
function hideInstantSearch()
{
	if(hidingSearch == null) {
		hidingSearch = window.setTimeout('hideInstantSearch2()', 1000);
	}
}
function hideInstantSearch2()
{
	var o = document.getElementById('instantsearch');
	o.style.display = 'none';
	o.style.visibility = 'hidden';
	hidingSearch = null;
}
function showInstantSearch()
{
	if(hidingSearch != null) window.clearTimeout(hidingSearch);
	hidingSearch = null;
}
function doBusca(r)
{
	preview.disabled = true;
	document.getElementById('q').value = r;
	document.forms[0].submit();
}
function q_focus(o)
{
	if(o.value.indexOf('Digite aqui o que') != -1) o.value = '';
}
function q_blur(o)
{
	if(o.value == '') o.value = q_defaultText;
}
function SI(o, f)
{
	if(!f) 
		o.src = o.src.replace('_u.jpg', '.jpg');
	else
		o.src = o.src.replace('.jpg', '_u.jpg');
}
function preloadBlackImages()
{
	var imgs = [ 
		'home', 'faleconosco', 'faturamentopj', 'meuspedidos', 'meucadastro', 'seguranca', 'ligueecompre', 
		'lojas', 'cozinha', 'banheiro', 'lavanderia', 'eletronicos', 'bebesecriancas', 'ofertas'
	];
	var o_imgs = new Array(imgs.length);
	for(i = 0; i < imgs.length; i++) {
		o_imgs[i] = new Image();
		o_imgs[i].src = '/Visual/black/top_' + imgs[i] + '_u.jpg';
	}
}


