var timer = 0;
 
function getQuerys(q)
{
  window.clearTimeout(timer);
  timer = window.setTimeout('getQuerys2("'+escape(q)+'")',300);
}
 
var xml = null;
 
function getQuerys2(q)
{
  	if(window.XMLHttpRequest)
	{ 
		xml = new XMLHttpRequest(); 
	}
  	else if(window.ActiveXObject)
  	{
   		try
		{ 
			xml = new ActiveXObject('Msxml2.XMLHTTP'); 
		}
   		catch(e1)
   		{
    		try
			{ 
				xml = new ActiveXObject('Microsoft.XMLHTTP'); 
			}
    		catch(e2){}
   		}
  	}
 
  	if(xml != null)
  	{
   		nocache = Math.random();
   		xml.open('GET','http://www.posterlounge.de/loajaxaction/LoSearchSuggestAjaxAction.php?query='+q+'&nocache = '+nocache,true);
   		xml.onreadystatechange = showQuerys;
   		xml.send(null);
  	}
 }
 
 
function showQuerys()
{
  	if(xml.readyState == 4 && xml.status == 200)
  	{
   		x = xml.responseXML.documentElement;
   		s = '<div style="padding:0px;">';
   		p = 0;
		a = 0;
		w=0;
		insertQuery = x.getAttribute('encodedQuery');
	   for(i=0;i<x.childNodes.length;i++)
	   {
			if(i == 0)
			{
				s += '<div><a href="http://www.posterlounge.de/page.shop.search.php?query='+insertQuery+'" style="text-decoration:underline; color:#0000CC; background:none;text-align:center; padding:3px;">alle Ergebnisse anzeigen</a>'
			}
			
			itm = x.childNodes.item(i);
			if(itm.nodeType == 1)
			{
				name = itm.getAttribute('name');
				query = itm.getAttribute('query');
				type = itm.getAttribute('type');
				
				if(type == 'word')
				{
					if(w == 0)
					{
						s += '<b style="color:#000; padding:8px; font-size:1.2em; display:block;">Meinten Sie...</b>';	
					}
					
					s += '<div class="clearfix" style="padding:3px;'+(a%2==0?'background-color:#FFF;':'background-color:#FFF;')+'" >';
					s += '<a href="http://www.posterlounge.de/page.shop.search.php?query='+query+'&suggest=1&pre_query='+insertQuery+'">'+
					'<span class="suggest_text" style="height:auto;width:220px;">';
					s += name+'</span></a></div>';
					
					w++;
				}
				
				if(type == 'product')
				{
					if(p == 0)
					{
						s += '<b style="color:#000; padding:8px; font-size:1.2em; display:block;">Produktvorschläge</b>';	
					}
					
					img = itm.getAttribute('img');
					
					s += '<div class="clearfix" style="padding:3px;'+(p%2==0?'background-color:#FFF;':'background-color:#FFF;')+'" >';
					s += '<a href="http://www.posterlounge.de/page.shop.search.php?query='+query+'&suggest=1&pre_query='+insertQuery+'">'+
					'<span class="suggest_img">'+
						'<img src="http://www.posterlounge.de/glimg/crossover/products/'+img+'" border="0" />'+
					'</span>'+
					'<span class="suggest_text">';
					s += name+'</span></a></div>';
					p++;
				}
				
				if(type == 'artist')
				{
					if(a == 0)
					{
						s += '<b style="color:#000; padding:8px; font-size:1.2em; display:block;">Künstlervorschläge</b>';	
					}
					
					s += '<div class="clearfix" style="padding:3px;'+(a%2==0?'background-color:#FFF;':'background-color:#FFF;')+'" >';
					s += '<a href="http://www.posterlounge.de/page.shop.search.php?query='+query+'&suggest=1&pre_query='+insertQuery+'">'+
					'<span class="suggest_text" style="height:auto;width:220px;">';
					s += name+'</span></a></div>';
					
					a++;
				}
			}
	   }
   	   
	   if(x.childNodes.length == 0)
   	   { 
	   		s+= '<div>Keine Treffer.</div>'; 
	   }
   	   s += '</div>';
   	   d = document.getElementById('suggestLayer');
       d.innerHTML = s;
       d.style.display = 'block';
     }
}
 
 
function hideQuerys()
{
  window.clearTimeout(timer);
  timer = window.setTimeout('hideQuerys2()',300);
}
 
 
function hideQuerys2()
{
  document.getElementById('suggestLayer').style.display = 'none';
}