/// <reference path="jquery-1.3.2-vsdoc2.js" />
var celebrityData;
//var domain_name = "http://localhost:5823/"
var domain_name = "http://esnube.com/"

loadjscssfile_search(domain_name + "LiveStream/style/search.css", "css")
var tweetcode

function tweetfind_search_init(){   

    var search_div = document.getElementById("tweetfind_search_div");
    var search_html;        
    search_html = "<table width='250px' cellpadding='1' cellspacing='1'>";
    search_html += "<tr>";
    search_html += "<td colspan='2' valign='top'><div style='width:10px; float:left'>&nbsp;</div><img src='" + domain_name + "LiveStream/image/download.gif'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='openCode()' class='twitterfind_search_text'>Share</a></td>";
    search_html += "</tr>";
    search_html += "<tr>";    
    search_html += "<td valign='bottom'><input type='text' class='search_text' id='tweetfind_search_text'></td>";
    search_html += "<td valign='bottom'><input class='button' type='button' value='Search' onclick='tweetfind_search_text();'></td>";
    search_html += "</tr>";
    search_html += "</table>";

    search_div.innerHTML = search_html;
    loadCebrities();
}

function tweetfind_search_wo_image_init(){   

    var search_div = document.getElementById("tweetfind_search_div_woimg");
    var search_html;        
    search_html = "<table width='250px' cellpadding='1' cellspacing='1'>";
    search_html += "<tr>";
    search_html += "<td colspan='2' valign='top'><div style='width:30px; float:left'>&nbsp;</div><img src='" + domain_name + "LiveStream/image/logo.gif'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='openCode()' class='twitterfind_search_text'>Share</a></td>";
    search_html += "</tr>";
    search_html += "<tr>";    
    search_html += "<td valign='bottom'><input type='text' class='search_text' id='tweetfind_search_text'></td>";
    search_html += "<td valign='bottom'><input class='button' type='button' value='Search' onclick='tweetfind_search_text();'></td>";
    search_html += "</tr>";    
    search_html += "</table>";
    
    search_div.innerHTML = search_html;
}

function tweetfind_search_125_init(){   

    var search_div = document.getElementById("tweetfind_search_div_125");
    var search_html;        
    search_html = "<table width='100px' cellpadding='1' cellspacing='1'>";
    search_html += "<tr>";
    search_html += "<td colspan='2' valign='top' width='100px'  ><div style='width:12px; float:left'>&nbsp;</div><img src='" + domain_name + "LiveStream/image/tweetfind_125.gif'></td>";
    search_html += "</tr>";
    search_html += "<tr>";
    search_html += "<td colspan='2' valign='top' width='100px' align='center'><a href='javascript:void(0);' onclick='openCode()' class='twitterfind_search_text'>Share</a></td>"
    search_html += "</tr>";    
    search_html += "<tr>";    
    search_html += "<td colspan='2' valign='bottom' align='center'><input type='text' class='search_text_125' id='tweetfind_search_text'></td>";
    search_html += "</tr>";    
    search_html += "<tr>";    
    search_html += "<td valign='bottom' align='center' ><input class='button' type='button' value='Search' onclick='tweetfind_search_text();'></td>";
    search_html += "</tr>";    
    search_html += "</table>";

    search_div.innerHTML = search_html;
    
}


function tweetfind_search_468_init(){   

    var search_div = document.getElementById("tweetfind_search_div_468");
    var search_html;        
    search_html = "<table cellpadding='1' cellspacing='1'>";
    search_html += "<tr>";
    search_html += "<td valign='center'><img src='" + domain_name + "LiveStream/image/tweetfind_468.gif'></td>";  
    search_html += "<td valign='center'>&nbsp;&nbsp;&nbsp;<input type='text' class='search_text' id='tweetfind_search_text'></td>";
    search_html += "<td valign='center'><input class='button' type='button' value='Search' onclick='tweetfind_search_text();'></td>";
    search_html += "<td valign='center'>&nbsp;&nbsp;<a href='javascript:void(0);' onclick='openCode()' class='twitterfind_search_text'>Share</a></td>";
    search_html += "</tr>";        
    search_html += "</table>";
    
    search_div.innerHTML = search_html;
}

function tweetfind_search_text(){
    var search_text = document.getElementById('tweetfind_search_text').value;
    var searchURL = "http://www.tweetfind.com/search.php?what=" + search_text +"&search_top=Search"
    window.location.href=searchURL;
}

function openCode(){
    //if(tweetcode=='undefined' || tweetcode == null){
    tweetcode = window.open("http://www.esnube.com/LiveStream/SearchCode.html", 'tweetfindcode', 'height=350, width=400, menubar=0,resizable=0');
        tweetcode.focus();
        
       //}       
       
}


(function($) {
    loadCebrities = function() {
        $("#tweetfind_celebrity").html("<div id='tweetfind_celebrity_slider'></div>")
        load_celebrity_json("http://esnube.com/tweethandler/GetCategoryUsers.aspx?callback=loadCelebData");
    };

    loadCelebData = function(data) {

        celebrityData = data;        
        setProfile();
        setInterval("setProfile()", 7000);

    };

    setProfile = function() {

        if (celebrityData != null && celebrityData.length != null) {
            var index = Math.ceil(Math.random() * (celebrityData.length - 1));

            $("#tweetfind_celebrity_slider").slideUp("slow", function() {
                $("#tweetfind_celebrity_slider").html("<div id='tweetfind_celebrity_slider_img'><image src='" + celebrityData[index].image + "' height='48px' width='48px'></div>");
                $("#tweetfind_celebrity_slider").append("<div id='tweetfind_celebrity_name'><a href='" + celebrityData[index].path + "'>" + celebrityData[index].title + "</a></div>");
                $("#tweetfind_celebrity_slider").slideDown("slow");

            });
        }

    };
})(jQuery);


//Load JSON
function load_celebrity_json(url) {
    var headID = document.getElementsByTagName("head")[0];
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = url
    headID.appendChild(newScript);

}

//Load script dynamically
function loadjscssfile_search(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}
