var Top10Array=new Array();
var LatestArray=new Array();

var Top10Idx=0;
var LatestIdx=0;
var OpacIdx=0;
var AniTimer1=0;
var AniTimer2=0;

function holdListingData(){
    this.title;
    this.desc;
    this.cat;
    this.hits;
    this.pos;
    this.url;
    this.image;
    
    this.setValues=function(title, desc, cat, hits, pos,url, imgsrc){
        this.title=title;
        this.desc=desc;
        this.cat=cat;
        this.hits=hits;
        this.pos=pos;
        this.url=url;
        this.image=imgsrc;
   }   
    this.getTitle=function(){return  this.title=title; }   
    this.getDesc=function(){return  this.title=desc; }   
    this.getCategory=function(){return  this.title=cat; }   
    this.getHits=function(){return  this.title=hits; }   
    this.getPos=function(){return  this.title=pos; }   
    this.getUrl=function(){return  this.title=url; }   
    this.getImage=function(){return  this.image=image; }   
}

function OutputTable(i, type){
    if(type=="top10"){
        item=Top10Array[i];
    }
    else{
         item=LatestArray[i];
       
    }
    
    cats=item.getCategory.Split('::');
    
    output='<table width="100%" cellpadding="2" cellspacing="2">';
    output+='<tr>';
    output+='    <td align="center" style="background-color: #138aff;">Position: <?php echo $count; ?></td>';
    output+='</tr>';
    output+='<tr>';
    output+='    <td>';
    output+='    <table width="468" cellpadding="2" cellspacing="2">';
    output+='    <tr>';
    output+='        <td rowspan="4"><a href="'+item.getUrl()+'" class="CatListing"><img src="'+item.getImage()+'" border="0" width="125" height="125" alt=""/></a></td>';
    output+='        <td><a href="'+item.getUrl()+'" class="CatListing"><b>'+item.getTitle()+'</b></a></td>';
    output+='    </tr>';
    output+='    <tr>';
    output+='        <td>'+item.getDesc()+'</td>';
    output+='    </tr>';
    output+='    <tr>';
    output+='        <td><a href="index.php?main='+escape(cats[0])+'" class="CatListing">'+cats[0]+'"</a> >> <a href="index.php?main='+escape(cats[0])+'"&sub='+escape(cats[1])+'" class="CatListing"><?php echo $cat[1] ?></a></td>';
    output+='    </tr>';
    output+='    <tr>';
    output+='        <td>Hits: '+item.getHits()+'</td>';
    output+='    </tr>';
    output+='    </table></td>';
    output+='</tr>';
    output+='<tr>';
    output+='    <td>&nbsp;</td>';
    output+='</tr>';
    output+='</table>';
    
    return output;
}

function fadeIn(elem, timer){
    if(OpacIdx!=100){
        if(document.all){
             elem.style.filter = 'alpha(Opacity='+OpacIdx+')';
        } 
        else{
            elem.style.opacity  = OpacIdx;
        }
        OpacIdx=OpacIdx+10;
    }
    else{
       clearTimeout(timer);
    }   
}
function fadeOut(elem, timer, screen){
    if(OpacIdx!=0){
        if(document.all){
             elem.style.filter = 'alpha(Opacity='+OpacIdx+')';
        } 
        else{
            elem.style.opacity  = OpacIdx;
        }
        OpacIdx=OpacIdx-10;
        if(type=="top10"){
            timer=setTimeOut('function(){fadeOut('+getElem(type+"Listing")+','+AniTimer1+',"'+screen+'"); }', 100);
       }  
       else{
            timer=setTimeOut('function(){fadeOut('+getElem(type+"Listing")+','+AniTimer2+',"'+screen+'"); }', 100);
       }
       
    }   
   else{
       clearTimeout(timer);
       getElem(screen).removeChild(elem);
    }   
}

function showListItem(output, type){
   if(getElem(type+"Listing")!=null){
       if(type=="top10"){
            fadeOut(getElem(type+"Listing"), AniTimer1, "top10Screen");
       }  
       else{
            fadeOut(getElem(type+"Listing"), AniTimer2, "RecentlyAddedScreen");           
       }
   }
     var elem = document.createElement('div');
    elem.setAttribute('id', type+"Listing");
   if (width) {
       elem.style.width = "100%";
   }
   
   if (height) {
       elem.style.height = 340;
   }
   
   if ((left || top) || (left && top)) {
       elem.style.position = "absolute";
       
       if (left) {
           elem.style.left = 0;
       }
       
       if (top) {
           elem.style.top = 0;
       }
   }
   
   elem.style.background = "#ffffff";
   if(document.all){
        elem.innerText = num;
        elem.style.filter = 'alpha(Opacity=0)';
   } 
   else{
        elem.textContent = num;
        elem.style.opacity  = 0;
   }
   
   document.body.appendChild(elem);
   if(type=="top10"){
        AniTimer1=setTimeOut('function(){ fadeIn('+elem+','+AniTimer1+');}', 100)
   }
   else{
        AniTimer2=setTimeOut('function(){ fadeIn('+elem+','+AniTimer2+');}', 100)      
   }
   
   
}
function outputTop10Listing(){
    rec=OutputTable(Top10Idx, "top10");
    showListItem(rec, "top10");
    
    Top10Idx++;
}
function outputLatestListing(){
    rec=OutputTable(LatestIdx, "latest");
    showListItem(rec, "listing");
    LatestIdx++;
}

