function Yahoo() {
    this.id      = 'avTPb57V34ERIa1G46YbthLKpjxYQbGRbvrA9vGU3ki7dwUKzBIYNmLrEccDT.r.orZ.SJw-';
    this.url     = 'http://search.yahooapis.com/WebSearchService/V1/webSearch?output=json';
	this.urlFull = '';
	this.link    = 'http://search.yahoo.com/search?p=';
	this.name    = '';
	this.type    = 'web'; // images, news, video, web, market, youtube
    this.q       = null;
    this.query   = null;
    this.src1    = null;
    this.src2    = null;
    this.params  = '';
    this.limit   = 4;
    
    this.exec=function(){
        
        switch (this.type) {
            case 'images':
                this.url  = 'http://search.yahooapis.com/ImageSearchService/V1/imageSearch?output=json&query=';
                this.link = 'http://images.search.yahoo.com/search/images?p='; // link to all results
                break;
            case 'news':
                this.url  = 'http://search.yahooapis.com/NewsSearchService/V1/newsSearch?output=json&query=';
                this.link = 'http://news.search.yahoo.com/search/news?p=';
                break;
            case 'video':
                this.url  = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?output=json&query=';
                this.link = 'http://video.search.yahoo.com/search/video?vo=';
                break;
            case 'youtube':
                this.url  = 'http://search.yahooapis.com/VideoSearchService/V1/videoSearch?output=json&query=site:youtube.com%20';
                this.link = 'http://video.search.yahoo.com/search/video?vs=youtube.com&vo=';
                break;
            // FIXME: json not support :(
//            case 'market':
//                this.url  = 'http://api.shopping.yahoo.com/ShoppingService/V2/productSearch?output=json&query=';
//                this.link = 'http://shopping.yahoo.com/search?p=';
//                break;
            case 'web':
            default:
                this.url  = 'http://search.yahooapis.com/WebSearchService/V1/webSearch?output=json&query=';
                this.link = 'http://search.yahoo.com/search?p=';
                break;
        }
        
        
        
        targ   = this.params.split(";"); 
        params = new Array();
		empty  = true;
        for (i=0;i<targ.length;i++){ 
            params[i] = $(targ[i]).val();
			if (params[i] != '') {
				empty = false;
			}
        }
		if (empty) {
			$(this.src1).html('0');
			return true;
		}
		
        this.img    = $('li#pl-'+this.name+' img.icon');
        this.imgsrc = $('li#pl-'+this.name+' img.icon').attr('src')+'';	
        this.img.attr('src','/public/images/preloading.gif');
		        
				
		this.queryFull = $.vsprintf(this.query, params);
		this.queryFull = this.queryFull.replace('"" OR ','');
		this.queryFull = this.queryFull.replace(' OR ""','');
		this.queryFull = encodeURIComponent(this.queryFull);
        this.urlFull   = this.url + this.queryFull +'&results='+this.limit+'&appid='+this.id;
		
        var plugin = this;
		
        $.ajax({
            // AJAX-specified URL
           url: plugin.urlFull,
           dataType : "jsonp",
           // Handle the success event
           success: function (data, textStatus) {
				var ul = document.createElement("ul");
				
				switch (plugin.type) {   
	                case 'images':
	                   $.each(data.ResultSet.Result,
        					function(i, val) {
        						var li = document.createElement("li");
        						
        						inner  = '<a href="'+val.Url+'" title="'+val.Title+'" target="_blank" class="img"><img src="'+val.Thumbnail.Url+'" width="'+val.Thumbnail.Width+'" height="'+val.Thumbnail.Height+'" alt="'+val.Title+'"/></a>';
						        inner += '<span>'+val.Summary+'<br/><a href="'+val.RefererUrl+'" title="'+val.Title+'" target="_blank">'+val.RefererUrl+'</a></span>';
						            						
        						li.innerHTML = inner;        						
        						ul.appendChild(li);
        					}
        				);
                        break;
                    case 'video':
                    case 'youtube':
	                    $.each(data.ResultSet.Result,
        					function(i, val) {
        						var li = document.createElement("li");
        						
        						inner  = '<a href="'+val.Url+'" title="'+val.Title+'" target="_blank" class="img"><img src="'+val.Thumbnail.Url+'" width="'+val.Thumbnail.Width+'" height="'+val.Thumbnail.Height+'" alt="'+val.Title+'"/></a>';
						        inner += '<span>'+val.Summary+'<br/><a href="'+val.RefererUrl+'" title="'+val.Title+'" target="_blank">'+val.RefererUrl+'</a></span>';
						            						
        						li.innerHTML = inner;        						
        						ul.appendChild(li);
        					}
        				);
                        break;
                        
                    case 'news':
                    case 'web':
                    default:
                        // build results set
                        $.each(data.ResultSet.Result,
        					function(i, val) {
        						var li = document.createElement("li");
        						var inner = '<a href="'+val.Url+'" title="'+val.Url+'" target="_blank">'+val.Title+"</a>";
        						if (val.Summary != "" && val.Summary != "undefined") {
        						    inner += " - "+val.Summary;
        						}
        						li.innerHTML = inner;        						
        						ul.appendChild(li);
//        						val.Title;
//        						val.Summary;						
//        						val.Url;                
//        						val.DisplayUrl;
//        						val.ClickUrl;
        						
        					}
        				);
                        break;
				    
				}
				
				link = '<a href="'+plugin.link+plugin.queryFull+'" title="View All Results (in new window)" target="_blank">'+data.ResultSet.totalResultsAvailable + '</a>';
				$(plugin.src1).html(link);
				$(plugin.src2).html(ul);
				plugin.img.attr('src',plugin.imgsrc);
			}
        });
    };
}
