Tweefind = {
	getTweeps : function (){
		var q = document.getElementById('q').value;
		$.post('./tweepleclient.php',{"q":escape(q)},function(data){
				divimgs = '';
				if (data.resp!="errors"){
					var q = document.getElementById('q').value;
					for(i=0;i < data.length;i++){
						if (i > 0) divimgs += "&nbsp;";
						divimgs += "<a href='http://tweepfind.com/search.php?q="+q+"'><img title='"+data[i]['sname']+"' class='tweepleimg' src='"+data[i]['img']+"' /></a>";
					}
				}
				$('#tweeplePlace').html(divimgs+"&nbsp;&nbsp;");
		},"json");
	},
	getTwitterResults : function(){
		
		document.getElementById('loaderarrow').style.visibility = 'visible';
		var q = document.getElementById('q').value;
		var poststring = 'q='+q+'&lang='+lang;
		flink = false;
		if (filterlinks == true) flink = true;
		$.post('./twittersearch.php',{"q":escape(q),"lang":lang,"filterlinks":flink},function(data){
				$('#twitterRes').html(data);
				document.getElementById('loaderarrow').style.visibility = 'hidden';
				setHover();
				setTooltip();
				if (tweetmeme == 1) {
					Tweefind.initTweetMemeMenu('item02');
					tweetmeme = 0;
				}
		});
		
	},
	getTMemeResults : function(){
		var q = document.getElementById('q').value;
		$.post('./ajaxserv/gettweetmemeres.php',{"q":escape(q),"lang":lang},function(data){
			$('#memeContent').html(data);
		});
	},
	getBingResults : function(){
		var q = document.getElementById('q').value;
		$.post('./ajaxserv/getbingres.php',{"q":escape(q)},function(data){
			$('#bingResContent').html(data);
		});
	},
	getGoogleResults : function(){
		var q = document.getElementById('q').value;
		$.post('./ajaxserv/getgoogleres.php',{"q":escape(q)},function(data){
			$('#googleResContent').html(data);
		});
	},
	getYoutubeVideo : function(){
		var q = document.getElementById('q').value;
		$.post('./ajaxserv/getyoutubevideo.php',{"q":escape(q)},function(data){
			$('#youTubeContent').html(data);
		});
	},
	getFeedsResults : function(){
		var q = document.getElementById('q').value;
		$.post('./ajaxserv/getfeedsres.php',{"q":escape(q)},function(data){
			$('#feedsContent').html(data);
		});
	},
	initYoutubeMenu : function(menuid){
		//$("#"+menuid).tooltip({showBody: " - "});
		var q = document.getElementById('q').value;
		$.post('./ajaxserv/countyoutubevideo.php',{"q":escape(q)},function(data){
			//alert(data);
			var nvideo = parseInt(data);
			if (nvideo > 0){
				$("#"+menuid).show();
				$("#"+menuid).find(".num-res").html(nvideo);
				$("#"+menuid).hover(function(){
					$(this).css({"cursor":"pointer"});
					//$(this).attr("title","this is a tooltip");
					$(this).tooltip({
							showBody: " - ",
							bodyHandler:function(){
								return "click here to see the most viewed YouTube<br /> videos related to your search keyword";
							},
							track: true, 
					    delay: 0, 
					    showURL: false, 
					    opacity: 1, 
					    fixPNG: true, 
					    extraClass: "mytooltip tooltiptext", 
					    top: -15, 
					    left: 15 

					});
				});
				$("#"+menuid).animate({"left":"0px"},500);
				$("#"+menuid).bind("click",function(){
					openYouTubeVideoList(q);
					$("#"+menuid).find(".num-res").hide();
				});
			}
		});
	},
	initTweetMemeMenu : function(menuid){
		
		link_array = new Array();
		
		$("#twitterRes").find("a").each(function(){
			thishref = $(this).attr("href");
			if (thishref.indexOf("http") == 0) {
				//if (link_array.indexOf(thishref) == -1) link_array.push(thishref);
				if (jQuery.inArray(thishref,link_array) == -1) link_array.push(thishref);
			}
		});
		
		if (link_array.length > 0){
			$("#"+menuid).show();
			$.post("./ajaxserv/tweetmeme.php",{'arrlink[]' : link_array},function(data){
					$("#tweetmeme-content").html(data);
					if (data != ''){
						$("#"+menuid).hover(function(){
							$(this).css({"cursor":"pointer"});
							$(this).tooltip({
									showBody: " - ",track: true, delay: 0,  showURL: false, 
									opacity: 1, fixPNG: true, extraClass: "mytooltip tooltiptext", top: -15, left: 15,
									bodyHandler:function(){
										return "click here to see the most retweeted links<br /> included in the search results contained in this page";
									}
							});
						});
						$("#"+menuid).find(".num-res").html(link_array.length);
						$("#"+menuid).animate({"left":"0px"},500);
						$("#"+menuid).bind("click",function(){
							$("#"+menuid).find(".num-res").hide();
							$.fn.colorbox({width:"500px",height:"80%",opacity:"0.60",inline:true,href:"#tweetmeme-results",open:true});
						});
					}
			});
		}
	},
	initRssMenu : function(menuid){
		var q = document.getElementById('q').value;
		$.post('./ajaxserv/getfeedsres.php',{"q":escape(q)},function(data){
			$('#rss-content').html(data);
			rsscount = 0;
			$('.news').each(function(){
				rsscount++;
			});
			if (rsscount > 0){
					$("#"+menuid).show();
					$("#"+menuid).hover(function(){
						$(this).css({"cursor":"pointer"});
						$(this).tooltip({
								showBody: " - ",track: true, delay: 0,  showURL: false, 
								opacity: 1, fixPNG: true, extraClass: "mytooltip tooltiptext", top: -15, left: 15,
								bodyHandler:function(){
									return "click here to see relevant news from top<br /> blogs/websites related to your search keyword";
								}
						});
					});
					$("#"+menuid).find(".num-res").html(rsscount);
					$("#"+menuid).animate({"left":"0px"},500);
					$("#"+menuid).bind("click",function(){
						$("#"+menuid).find(".num-res").hide();
						$.fn.colorbox({width:"490px",height:"600px",opacity:"0.60",inline:true,href:"#rss-results",open:true});
					});
			}
		});
	},
	initTweepfindMenu : function(menuid){
		var q = document.getElementById('q').value;
		$.post('./ajaxserv/toptweeps.php',{"q":escape(q)},function(data){
			var ntweeps = parseInt(data);
			if (ntweeps > 0){
				$("#"+menuid).show();
				$("#"+menuid).find(".num-res").html(ntweeps);
				$("#"+menuid).hover(function(){
					$(this).css({"cursor":"pointer"});
					//$(this).attr("title","this is a tooltip");
					$(this).tooltip({
							showBody: " - ",
							bodyHandler:function(){
								return "click here to see the highest-ranked Twitter users<br /> whose bio contain your search keyword";
							},
							track: true, 
					    delay: 0, 
					    showURL: false, 
					    opacity: 1, 
					    fixPNG: true, 
					    extraClass: "mytooltip tooltiptext", 
					    top: -15, 
					    left: 15 

					});
				});
				$("#"+menuid).animate({"left":"0px"},500);
				$("#"+menuid).bind("click",function(){
					//openYouTubeVideoList(q);
					$("#"+menuid).find(".num-res").hide();
					openTopTweeps(q);
				});
			}
		});
	}
};

