﻿function GetVideo(VideoTitle, VideoId, elem) {
	_set_interface(function() {
		$("#FlashFile").load("/XmlServices/Process.aspx", { type: "GetVideo", vid: VideoId }, function(){
			if (jQuery.browser.msie == true) {
				$("#FlashFile embed").each(function(index){
					$(this).attr("id", "FlashObject" + index);
					var params = {
						quality : "high",
						menu : "false",
						allowScriptAccess : "always",
						wMode : "window",
						allowFullScreen : "true",
						flashvars: $(this).attr("flashvars")
					};
					swfobject.embedSWF($(this).attr("src"), "FlashObject" + index, $(this).attr("width"), $(this).attr("height"), "9.0.0", false, false, params);
				});
			}
			_center_lightbox();
		});
		$("#VideoTitle").text(VideoTitle);
		$("#InfoBar").show();
		$("#aCloseVideo").show();
		if (typeof(pageTracker) != undefined)
			pageTracker._trackEvent("Videos", "Lightbox", $(elem).attr("href"));
	});
}

function CloseFlashWindow() {
	$("#FlashFile").text("");
	$("#VideoTitle").text("");
	//$("#InfoBar").hide();
	_finish();
	//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, this);
		event.preventDefault();
	});*/
}

function FocusSearchBox(){
	$(".SearchBox #search").focus();
}
