/**
 * Albatross Javascript
 * @author David E. Still
 */
function update_size(size) {
	var size_value = size.options[size.selectedIndex].value;
	albatross.currentSize = size_value;
	var els = $("input");
	for (var i=0; i<els.length; i++) {
		if (els[i].name == "size" && els[i].type == "hidden") { els[i].value = size_value; }
	}
}

function kill_stream() {
	$('#tykiller').remove();
	//$("body").append("<iframe id='tykiller' src='"+albatross.killlink+"' class='nowhere'></iframe>");
	$.get('haltstream.php');
	$("#flash").replaceWith("<div id='flash'></div>");
	$("#player").jqmHide();
}

function load_flash() {
	var flash = null;
	if (useFlowPlayer) {
		flash = new SWFObject("FlowPlayerThermo.swf","single",albatross.sizes[albatross.currentSize].width,albatross.sizes[albatross.currentSize].height,"7");
		flash.addVariable("config", "{ showPlayListButtons: true, playList: [ {overlayId: 'play' }, { url: '"+albatross.streamlink+"' } ], initialScale: 'fit' }");
	} else {
		flash = new SWFObject("mediaplayer.swf","single",albatross.sizes[albatross.currentSize].width,albatross.sizes[albatross.currentSize].height,"7");
		flash.addParam("allowFullScreen","true");
		flash.addVariable("autostart","true");
		flash.addVariable("file",albatross.streamlink);
		flash.addVariable("width",albatross.sizes[albatross.currentSize].width);
		flash.addVariable("height",albatross.sizes[albatross.currentSize].height);
	}
	flash.write("flash");
}

var listings = null;
var player = "";
var useFlowPlayer = false;

$(document).ready(function(){
	$("#player").jqm({modal: true, overlay: 70});
	$("table.listings tr").click(function(){
		var forms = $(this).find("form");
		if (forms.length > 0) {
			if (forms.find('input[name=action]').length < 1) {
				forms.submit();
				return;
			}
			var fields = forms.serializeArray();
			$("#player div span.title").html(forms.find('input[name=progname]')[0].value);
			$.ajax({
				type: "get",
				url: "",
				data: fields,
				timeout: 1000,
				complete: function(){
					setTimeout(function(){
						load_flash();
						var width = (albatross.sizes[albatross.currentSize].width / 1);
						$("#player").jqmShow().css({marginLeft: '-'+Math.floor(width / 2)+'px', 'width': width+'px'});
					}, 1000);
				}
			});
		}
		var links = $(this).find("a.folder");
		if (links.length > 0) { document.location.href = links[0].href; }
	});
	$("table.listings").tablePager({rowstyles: ["row1","row2"]});
});

