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 fr_st  = "<div class='attackWidgetFrame'>";
    var fr_end = "</div>";
    var mirror = "<div class='title' id='previewTitle'>" + this.result['title'] + "</div>";
    mirror += "<div class='grey' id='previewSrc'>" + this.result['watch'] + "</div>";
    if(this.result['origin']!='youtube') { mirror += "<div class='videoEmbed' id='previewEmbed'>" + this.result['embed'] + "</div>"; }
    else { mirror += "<div class='videoEmbed' id='previewEmbed'>" + this.youTube() + "</div>"; }

    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('searchResults').innerHTML =  "<span style='color: red'>No results found.</span>";
}

browseMediaWidget.prototype.displayQueryWidget = function () {
    var html = "";
    for(var i=0;i<results.length;i++) {
	var result = results[i];
	var thumb = "http://i3.ytimg.com/vi/" + result['videoId'] + "/default.jpg";
	html += "<div style='float: left; clear:both; height: 20px; margin: 1px 1px 6px 1px; padding: 2px; width: 280px; cursor: pointer'" + " onMouseOver=\"this.style.margin = '0px 0px 5px 0px'; this.style.border='1px solid #EEE'\" onMouseOut=\"this.style.margin = '1px 1px 6px 1px'; this.style.border='0px solid #CCC'\">";
	html += "<div style='float: left'><img src='" + thumb + "' width='24px'/></div>";
	html += "<a onclick=\"updatePreview(" + i + ", '" + this.urlDiv + "')\">" + "<div style='overflow: hidden; height: 18px'>&nbsp;&nbsp;" + result['title'] + "</div></a>";
	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";
    }

    DOM('searchResults').innerHTML =  "<div id=\"prev_button\" class=\"nav_button\" style=\"text-align: center; display: " + prev_display + "; float: left;\" onclick=\"submitQuery('inputQuery', " + (this.start-10) + " ," + (this.max) + ", '" + this.urlDiv + "', total)\">prev " + (this.max) + "</div>" + html + "<div id=\"next_button\" class=\"nav_button_bottom\" style=\"text-align: center; display: " + next_display + "; float: left\" onclick=\"submitQuery('inputQuery', " + (this.start+10) + " ," + (this.max) + ", '" + this.urlDiv + "', total)\">next " + (this.max) + "</div>";
}

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>';
}