//So yeah this is really non portable Javascript
//if you can find something useful here nice and please leave
//a thanks to the bloke at www.somedodgywebsite.com in your comments
//-----------------------------------------------------------------
function GetTopSearch(type) {
   XmlGetRequest('v='+type,SetTopSearch);
}

function GetSubSearch(type,value) {
   XmlGetRequest('s='+type+'&va='+value,SetSubSearch);
}

var const_href = new Array;
const_href[1]='/mac/mac2.php?model=';
const_href[2]='#';//'/mac/mac2.php?photographer=';
const_href[3]='#';
const_href[4]='#';///mac/mac2.php?foundby=';

function SetTopSearch(dataarray){
   var ListPosition=document.getElementById('top_search');
   //Remove Existing List
   while (ListPosition.childNodes.length>0) {
      ListPosition.removeChild(ListPosition.childNodes[0]);
   }
   //Create New List, Append and store position
   ListPosition = ListPosition.appendChild(document.createElement('ol'));
   for (a=1;a<dataarray.length;a++){
      var ThisResult = dataarray[a].split(',');
      var ListItem=document.createElement('li');
      ListPosition.appendChild(ListItem);
      var Link=document.createElement('a');
      Link.href=const_href[1]+ThisResult[0];
      var ThisClick = new Function ("GetSubSearch("+dataarray[0]+",'"+ThisResult[0]+"');return false;");            
      Link.onclick=ThisClick;
      Link.innerHTML=ThisResult[0];
      ListItem.appendChild(Link);     
      //alert(dataarray[a]);
   }
}

function SetSubSearch(dataarray){
   //clear stats
   document.getElementById('gallery_stats').innerHTML="";
   var ListPosition=document.getElementById('sub_search');
   //Remove Existing List
   while (ListPosition.childNodes.length>0) {
      ListPosition.removeChild(ListPosition.childNodes[0]);
   }
   //Create New List, Append and store position
   ListPosition = ListPosition.appendChild(document.createElement('ol'));
   for (a=0;a<dataarray.length;a++){
      var ThisResult = dataarray[a].split(',');
      var ListItem=document.createElement('li');
      ListItem.innerHTML=a+1+'. ';
      ListPosition.appendChild(ListItem);
      var Link=document.createElement('a');
      Link.onmouseover=new Function('DisplayStats("'+ThisResult[3]+'","'+ThisResult[4]+'","'+ThisResult[5]+'");');
      Link.href='/mac/showpage.php?hID='+ThisResult[2];
      Link.innerHTML=ThisResult[0];
      Link.target='right';
      ListItem.appendChild(Link);     
      //alert(dataarray[a]);
   }
}

function DisplayStats(clicks,foundby,photographer)
{
   var out;
   out = "photographer " + photographer + "<br>";
   out += "found by " + foundby + "<br>";
   out += "clicks " + clicks;
   document.getElementById('gallery_stats').innerHTML=out;
}

function JumpToModel(name){
   GetSubSearch(1,name);   
}
//--------------------------
//Vars
//--------------------------

window.onload=function () {
   XmlTest();
   GetTopSearch(1);
   if (typeof(GetSubGalleriesOnLoad)!="undefined") {
      GetSubSearch(1,GetSubGalleriesOnLoad);   
   }   
      
}
