    function ajaxSearch(){
        pretendthis=this;  
        this.levels=new Array(),this.leftLinks=new Array(),this.leftMenus=new Array();   
        this.createLeft=function(link,category,class1,class2,class3,opt){this.leftLinks.push(new this.leftLink(link,category,class1,class2,class3,opt));}   
        this.createMenu=function(menu){this.leftMenus.push(new wrapMenu(menu));}
        this.createCat=function(category,key1,key2){this.levels.push(new this.catHash(category,key1,key2));}  
        this.getCat=function(category){for(i in this.levels){if(this.levels[i].category===category){return this.levels[i];};}};  
    };    
    ajaxSearch.prototype.updateLevels=function(key1,key2,key3,key4){ //function is wrong needs replacing abovebeyond this point       
        var thisSplit,thisHash=this.hash.replace(key1,'');     
        thisSplit=thisHash.split(key2);                   
        for(var i in this.levels){            
            for(var j=0;j<thisSplit.length;j++){
                var hashBlock=thisSplit[j].split(key3);        
                if(this.levels[i].category==hashBlock[0]){          // goes thru whole leftlink array oO?!!!
                    var thisHash=hashBlock[1].split(key4);
                    this.levels[i].cHash.splice(0,this.levels[i].cHash.length);
                    for(var y=0;y<thisHash.length;y++){this.levels[i].addToLevel(thisHash[y]);}
                    for(var m=0;m<this.leftLinks.length;m++){
                        if(this.leftLinks[m].category==this.levels[i].category){                            
                            if(this.searchHash(this.levels[i],this.leftLinks[m])==true)
                            {
                                this.leftLinks[m].status=1;
                                this.leftLinks[m].link.className=this.leftLinks[m].active;
                            
                            }else{if(this.leftLinks[m].status!=2){this.leftLinks[m].resetLink();}}                             
                        } 
                    }
                }         
            }                   
        }
    };    
    ajaxSearch.prototype.getHash=function(){return this.hash;}
    ajaxSearch.prototype.updateHash=function(hash){this.storeHash=hash;this.hash=this.storeHash;};    
    ajaxSearch.prototype.checkHash=function(hash){if(this.storeHash!==hash){return 1;}else{return 0;}};            
    ajaxSearch.prototype.intervaler=function(todo,time){clearInterval(this.interval);this.interval=setInterval(todo,time);};    
    ajaxSearch.prototype.timer=function(todo,time){clearTimeout(this.timeout);this.timeout=window.setTimeout(todo,time);}; 
    ajaxSearch.prototype.submitHash=function(hash)
    {
        var bLevel="";
        this.url=''
        if(this.getCat('pageNum').cHash=='')
        {
            this.url="&ppg=1"//+this.getCat('perPage').cHash;
        }else
        {
            //this.url=this.getCat('perPage').cHash;
        }
        window.location.hash=hash+this.url;        
    } 
    ajaxSearch.prototype.createHash=function(hash){
        this.hash=new String();
        for(i in this.levels){                                                      
            for(j in this.levels[i].cHash){
                if(j>1){this.hash+=this.levels[i].split2;} // not in place yet should be for final
                this.hash+=this.levels[i].cHash[j];
            }                                  
        }return this.hash;
    }
    ajaxSearch.prototype.searchHash=function(obj,hashCell){ // alert(obj.cHash+"____"+hashCell.id);           
        for(i in obj.cHash){      
            if(obj.cHash[i].length==hashCell.id.length){if(obj.cHash[i].match(hashCell.id)){return true;}}        
        }return false;   
    }    
    ajaxSearch.prototype.catHash=function(hash,split1,split2){           
        this.category=hash;
        this.prevLength=hash.length;//something
        this.split1=split1;
        this.split2=split2;
        this.cHash=new Array();
        this.baseLevel=0;
        this.clearHash=function(pr){this.cHash=new Array();this.setBase(pr);}//create reset links funtion}  
        this.addToLevel=function(hash){        
            this.cHash[0]=this.split1;
            if(this.split2.length<1&&this.cHash.length>1){this.cHash.pop();}
            this.cHash.push(hash);//+this.split2;      
        };        
        this.removeFromLevel=function(hash){ //duplicated functionality between here and search function?          
            var thisLength=hash.length;            
            for(i in this.cHash){
                if(this.cHash[i].length==thisLength){
                    if(this.cHash[i].match(hash)){this.cHash.splice(i,1);}               
                }    
            }
            if(this.cHash.length==1){this.cHash=new Array();}                 
        };         
    };    
    ajaxSearch.prototype.catHash.prototype.setBase=function(pr){this.baseLevel=pr;}
    ajaxSearch.prototype.leftLink=function(link,cat,class1,class2,class3,opt){
        this.category=cat;
        this.id=link.id.substr(5);
        this.link=link;
        this.status=0;
        this.normal=class1;
        this.active=class2;
        this.inactive=class3;
        if(opt!=true){
            if(this.link.className==class2){this.status=1;}
            if(this.link.className==class3){this.status=2;}
        }
        this.resetLink=function(){this.status=0;this.link.className=this.normal;}
        this.clickerd=function(){
            if(this.status==0){                          
                this.status=1;
                this.link.className=this.active;
            }else if(this.status==1){this.status=0;              
                this.link.className=this.normal;                          
            }else if(this.status==2){}
            return this.status;
        }
    }   
    ajaxSearch.prototype.searchBases=function(pass){for(i in this.levels){if(this.levels[i].baseLevel==pass){return true;}}return false;}
    ajaxSearch.prototype.setBases=function(pass){for(i in this.levels){this.levels[i].setBase(pass);}}
    ajaxSearch.prototype.appendHash=function(hashCell){
        this.activeLevel=this.getCat(hashCell.category);      
        if(this.searchHash(this.activeLevel,hashCell)&&this.activeLevel.category!='pageNum'){
            this.activeLevel.removeFromLevel(hashCell.id); 
            var page=this.getCat('pageNum'); // add exception property to be kept seperate
            page.addToLevel('1');                             
        }
        else if(this.activeLevel.category=='perPage'){
            this.activeLevel.cHash=[];// :? :/:/
            this.activeLevel.addToLevel(hashCell.id);
            if(this.activeLevel.category!='pageNum'){var page=this.getCat('pageNum');page.addToLevel('1');}
        }
        else{        
            this.activeLevel.addToLevel(hashCell.id);
            if(this.activeLevel.category!='pageNum'){var page=this.getCat('pageNum');page.addToLevel('1');}                    
        };
    }        
               
    function sortCollection(data){// replace this function NOWWWWWWWW
        deptArr=[];typeArr=[];colourArr=[],brandArr=[],sizeArr=[],priceArr=[];       
        var temp=data.split("#split#")       
        deptArr=temp[0];
        deptArr=deptArr.split("~split~");
        brandArr=temp[1];
        brandArr=brandArr.split("~split~"); 
        typeArr=temp[2];
        typeArr=typeArr.split("~split~");
        colourArr=temp[3];
        colourArr=colourArr.split("~split~");
        sizeArr=temp[4];
        sizeArr=sizeArr.split("~split~");  
            updateLinks(deptArr,aSrch.getCat('department'));
            updateLinks(brandArr,aSrch.getCat('brand'));
            updateLinks(typeArr,aSrch.getCat('type'));
            updateLinks(colourArr,aSrch.getCat('colour'));
            updateLinks(sizeArr,aSrch.getCat('size')); 
        var getPage=$$(document,"a","plist_all");
        var getNavs=$$(document,"a","pageCount");

        try{
            for(var i=0,j=aSrch.leftLinks.length;i<j;i++)
            {            
                if(aSrch.leftLinks[i].category=='perPage')
                {                
                    aSrch.leftLinks.splice(i,1);
                }
                if(aSrch.leftLinks[i].category=='pageNum')
                {
                    aSrch.leftLinks.splice(i,1);
                } 
            }
        }catch(err){}
        for(var i=0;i<getPage.length;i++)
        {
            getPage[i].onclick=function(){return false;}
            aSrch.createLeft(getPage[i],"perPage","plist_all","plist_all","plist_all",true);
            eval("Event.add(getPage[i],'mouseup',function(){aSrch.submitHash(aSrch.createHash(aSrch.appendHash(aSrch.leftLinks["+aSrch.leftLinks.length+"-1])));});");
        }
        //alert(getNavs.length+"__link length__");
        for(var i=0;i<getNavs.length;i++)
        {
            getNavs[i].onclick=function(){return false;}
            //alert(getNavs[i].id);
            aSrch.createLeft(getNavs[i],"pageNum","pageCount","pCt","pageCount",true);
            eval("Event.add(getNavs[i],'mouseup',function(){aSrch.submitHash(aSrch.createHash(aSrch.appendHash(aSrch.leftLinks["+aSrch.leftLinks.length+"-1])));});");
        }
        /*for(p in aSrch.leftLinks)
        {
            if(aSrch.leftLinks[p].category==aSrch.getCat(baseLevel).category)
            {
                if(aSrch.leftLinks[p].status!=1){aSrch.leftLinks[p].resetLink();}
            
            }
        } */   
    }       

    function updateLinks(resultsArray,level){
        var linksArray=[];
        for(i in aSrch.leftLinks)
        {
            if(level.category==aSrch.leftLinks[i].category)
            {
                linksArray[linksArray.length]=aSrch.leftLinks[i];
            }               
        }        
        for(var i=0;i<linksArray.length;i++){         
            linksArray[i].status=2;
            for(j in resultsArray) {
                if(linksArray[i].id==resultsArray[j])
                {
                    if(linksArray[i].link.className==linksArray[i].active)
                    {
                        linksArray[i].status=1;
                    }
                    else//(array[i].link.className==array[i].normal)
                    {
                        linksArray[i].status=0;
                        linksArray[i].link.className=linksArray[i].normal;
                    }       
                }           
            }
            if(aSrch.searchHash(level,linksArray[i])==true)
            {
                if(linksArray[i].status!=0){
                    linksArray[i].status=1;
                    linksArray[i].link.className=linksArray[i].active;
                }
                
            }
            if(linksArray[i].status==2){linksArray[i].link.className=linksArray[i].inactive;} 
        }    
    }   
    ajaxSearch.prototype.clearThis=function(){}
    ajaxSearch.prototype.getMenu=function(category)
    {
        for(i in this.wrapLink){alert(this.wrapLink.id);}
    } 
    var aRequest;
    ajaxSearch.prototype.httpGo = function (URL) {
        aRequest = createxmlHttp();
        var thisPage = document.getElementById('plist_wrap');
        var thisMainPage = document.getElementById('thisContent');
        var ajaxLoader = document.getElementById('ajaxLoader');

        aRequest.onreadystatechange = function () {
            if (aRequest.readyState == 4 && aRequest.status == 200) {
                this.busy = false; var collectResponse;
                collectResponse = aRequest.responseText.split("#splitmain#");
                if (collectResponse[0] != "") {
                    try {
                        ajaxLoader.style.display = "none";
                        thisPage.style.background = 100 / 100;
                        thisPage.style.opacity = 100 / 100;
                        thisPage.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
                        thisPage.style.filter = 'alpha(opacity=100)';
                    } catch (e) { }
                    thisMainPage.innerHTML = collectResponse[0];
                }
                try {
                    if (collectResponse.length > 1) {
                        sortCollection(collectResponse[1]);
                    }
                } catch (e) { }
            } else {
                ajaxLoader.style.display = "block";
                try {
                    thisPage.style.opacity = .25;
                    thisPage.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=25)';
                    thisPage.style.filter = 'alpha(opacity=25)';
                } catch (e) { }
            }
        }
        //alert(URL);
        aRequest.open("GET", URL, true);
        aRequest.send(null);
        this.busy = true;
    }
    function wrapMenu(obj) {
        obj.style.display="block"; 
        this.opener=function(){if(obj.style.display=="block"){this.close();}else{this.open();}}
        this.open = function () {
            obj.style.display = 'block';
        };
        this.close=function(){obj.style.display="none";};               
    }     
    function createClearLeft(obj,idOffset){          
        var category=obj.id.substr(idOffset);
        obj.onclick=function(){return false;}
        Event.add(obj,'mouseup',function(){                    
            for(var j in aSrch.levels){               
                if(aSrch.levels[j].category==category){
                    for(var i in aSrch.leftLinks){
                        if((aSrch.leftLinks[i].category==aSrch.levels[j].category)&&(aSrch.leftLinks[i].status==1))
                        {
                            aSrch.leftLinks[i].resetLink(0);
                            aSrch.appendHash(aSrch.leftLinks[i]);
                        }        
                    }
                }
            }    
            aSrch.submitHash(aSrch.createHash(null));            
        });   
    }
