

﻿var faabo = {
    base_url: "http://faabo.com/",
    tabs: Array("tabs-1","tabs-2","tabs-3","tabs-4","tabs-5","tabs-6"),
    switchTab: function(t){
        for(var i=0; i<this.tabs.length; i++) {
        obj = document.getElementById(this.tabs[i]);        
        obj.firstChild.className="fbtab";        
        obj = document.getElementById(this.tabs[i]+"_container");
        obj.style.display = "none";
        }
        obj = document.getElementById(t.id);					 
        obj.firstChild.className="fbtab selected";
        obj_container = document.getElementById(t.id+"_container");
        obj_container.style.display = "block";    
    },
   closeit: function()
   {
     document.getElementById("results").style.display = "none";
   },
   init: function()
   {
     var obj_tab = document.getElementById("tabs-1");
     if(obj_tab!=null)
     {
        obj_tab.firstChild.className="fbtab selected"; 
     } 
     
     var imgcontrol = document.getElementById("imgSearchControl");     
     if(imgcontrol!=null)
     {  
        google.setOnLoadCallback(faabo.onload());       
     }
   },
   onload: function()
   {      
    try
    {
     var tabbed = new google.search.SearchControl();            
     tabbed.setResultSetSize(google.search.Search.LARGE_RESULTSET);                
     tabbed.addSearcher(new google.search.ImageSearch());               
     var drawOptions = new google.search.DrawOptions();
     drawOptions.setDrawMode(google.search.SearchControl.EXPAND_MODE_OPEN);        
     tabbed.draw(document.getElementById("imgSearchControl"), drawOptions);               
     tabbed.execute(pd_des_im_gs);   
     return;                
     }
     catch(err){}
   },
   tooltip: function()
   {   
    try{
    if ($("a.tooltip").length > 0){         
        $('a.tooltip').cluetip({
            splitTitle: '|',                      
            showTitle: false,
            width:'320'
           });
    } 
    }
    catch(err){}
   },
   imgerror: function()
   {   
     $('img').error(function() {
         $(this).css('display','none');
      }); 
   },
   load: function()
   {    
      $("#category > ul > li > a,#navbar > ul > li > a").click(function (e) {
        e.preventDefault();
        rel = $(this).attr("value");
		href = this.href;
		text = $(this).html();
		$.post(faabo.base_url+"topics/"+rel,{search_term: rel},function(xml)
		{
		    $("#results").hide();
				if (rel == 11 || rel == 7) {
					$("#results").html('<h2><a href="' + href + '">' + text + '</a></h2><span id="hide-results" onclick="javascript:faabo.closeit();" >Close</span>');
					$("#hide-results").css({
						cursor: "pointer"
					});
				} else {
					$("#results").html('<h2>Top Stories in <a href="' + href + '">' + text + '</a></h2><span id="hide-results" onclick="javascript:faabo.closeit();" >Close</span>');
					$("#hide-results").css({
						cursor: "pointer"
					});
				}
			$("#results").append(xml).slideDown("slow");
		    
		}); 
      });
   }
};  

$(document).ready(function(){
    faabo.load(); 
    faabo.tooltip();
    faabo.imgerror(); 
    faabo.init();
           
});