function browseMediaWidget (root, start, max, urlDiv, total) {
    this.root = root;
    this.start = start;
    this.max = max;
    this.urlDiv = urlDiv;
    this.total = total;
}

browseMediaWidget.prototype.displayPreviewWidget=null;
browseMediaWidget.prototype.displayErrorWidget=null;
browseMediaWidget.prototype.previewWidget=null;

browseMediaWidget.prototype.displayPreviewWidget = function () {
    DOM(this.root).innerHTML = this.previewWidget();
}

browseMediaWidget.prototype.previewWidget = function () {
	var result = this.result;
	var title = result['title']['$t'];

 	var video = result['id']['$t'];
 	video = video.replace('http://gdata.youtube.com/feeds/api/videos/','http://www.youtube.com/watch?v=');  //replacement of link
 	videoID = video.replace('http://www.youtube.com/watch?v=',''); // removing link and getting the video ID

    var fr_st  = "<div class='attackWidgetFrame'>";
    var fr_end = "</div>";
    var mirror = ""; //"<div class='title' id='previewTitle'>" + title + "</div>";
  	mirror += '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/'+videoID+'?fs=1&amp;hl=en_US&enablejsapi=1&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+videoID+'?fs=1&amp;hl=en_US&enablejsapi=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>';

    //mirror += "<div class='statusBar' id='statusBar'><img src='http://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif' width='100%'/></div>";
    var tables = fr_st + mirror + fr_end;
    return tables;
}

browseMediaWidget.prototype.displayErrorWidget = function () {
    DOM('searchcontrol').innerHTML =  "<span style='color: red'>No results found for <i>" + query + "</i>.</span>";
}

browseMediaWidget.prototype.displayQueryWidget = function () {
    var html = "";
    for(var i=0;i<player.length;i++) {
	var result = player[i];

	var title = result['title'].$t;

	if(title.indexOf("webcam video")>0) { var name = title.substr(0,title.indexOf("webcam video")-3); var title = "<small>@<a onClick='window.open(http://youtube.com/"+name+")'>"+name+"</a></small>"; }

	title = title.replace(/Grind Time Now Presents:/gi, "");

 	var video = result['id']['$t'];
 	video = video.replace('http://gdata.youtube.com/feeds/api/videos/','http://www.youtube.com/watch?v=');  //replacement of link
 	videoID = video.replace('http://www.youtube.com/watch?v=',''); // removing link and getting the video ID

	var thumb = "http://i3.ytimg.com/vi/" + videoID + "/default.jpg";
	html += "<div id='bubble"+(i)+"' ";
	if(i==0) { html += "class='glass'"; } else { html += "class='bubble'"; }
	html += " style='float: left; clear:both; margin: 1px 1px 6px 1px; padding: 2px; width: 280px; cursor: pointer'" + " onMouseOver=\"this.style.margin = '0px 0px 5px 0px'; this.style.border='1px solid #222'\" onMouseOut=\"this.style.margin = '1px 1px 6px 1px'; this.style.border='0px solid #CCC'\" onclick=\"updatePreview(" + i + ", '" + this.urlDiv + "')\">";

	html += "<div style='clear: both; height: 8px'></div>"
	html += "<div style=\"float: left\" onclick=\"updatePreview(" + i + ", '" + this.urlDiv + "')\">" + "<img src='" + thumb + "' width='26px' style='margin: 4px;'/></div>";
	html += "<small><a onclick=\"updatePreview(" + i + ", '" + this.urlDiv + "')\">" + "<div style='overflow: hidden; height: 24px'>" + title + "</div></a></small>";
	html += "<div style='clear: both; height: 4px'></div>"
	html += "</div>";
    }
    var prev_display = "block";
    if(this.start==1) {
	prev_display = "none";
    }
    var next_display = "block";
    if(this.total<(this.start+this.max)) {
	next_display = "none";
    }

    var next = "<div id=\"next_button\" class=\"nav_buttons\" style=\"text-align: center; display: " + next_display + "; float: right\" onclick=\"submitQueryUpdate('searchInput', " + (this.start+10) + " ," + (this.max) + ", '" + this.urlDiv + "', total)\">next " + (this.max) + "</div>";
    var prev = "<div id=\"prev_button\" class=\"nav_buttons\" style=\"text-align: center; display: " + prev_display + "; float: left;\" onclick=\"submitQueryUpdate('searchInput', " + (this.start-10) + " ," + (this.max) + ", '" + this.urlDiv + "', total)\">prev " + (this.max) + "</div>";
    var nav = "<div class=\"nav\" style=\"width: 100%\">"+ prev + "" + next +"</div>";
	DOM('searchcontrol').innerHTML = nav + html;
}

browseMediaWidget.prototype.youTube = function () {
    return '<object width="100%" height="240"><param name="movie" value="http://www.youtube.com/v/' + this.result['videoId'] + '&hl=en_US&fs=1&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + this.result['videoId'] + '&hl=en_US&fs=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100%" height="240"></embed></object>';
}

