﻿function GetVideo(VideoTitle, VideoId) {
    $("#FlashFile").load("XmlServices/Process.aspx", { type: "GetVideo", vid: VideoId });
    $("#VideoTitle").text(VideoTitle);
    $("#InfoBar").show();
    $("#aCloseVideo").show();
}

function CloseFlashWindow() {
	$("#FlashFile").text("");
	$("#VideoTitle").text("");
	$("#InfoBar").hide();
	//FocusSearchBox();
}

$(document).ready(function() {
	FocusSearchBox();
	AttachBottomVideoDisplayer();
	AttachSearchSuggest();
});

function AttachSearchSuggest(){
	jQuery("#search").autocomplete("/XmlServices/AutoComplete.aspx", {
		extraParams: {
		   s: function() { return $("#search").val(); }
		},
		multiple: false,
		dataType: "json",
		parse: function(data) {
			return jQuery.map(data, function(row) {
				return {
					data: row,
					value: row,
					result: row
				}
			});
		},
		formatItem: function(item) {
			return item;
		}
	});

}

function AttachBottomVideoDisplayer(){
	$(".SearchResults a.BottomVideo").click(function(event) {
		var myregexp = new RegExp("Video/(\\d+)/(.*)\\.aspx");
		var VideoId = myregexp.exec($(this).attr("href"))[1];
		GetVideo($(this).text(), VideoId);
		event.preventDefault();
	});
}

function FocusSearchBox(){
	$('.SearchBox #search').focus();
}