

var my_channel_uri;					// own channel's uri
var main_channel_uri;				// uri of default channel on partner realm
var ticket = false;					// user ticket
var current_channel_uri;		// indicates if and which channel's shows are listed in canvas 2
var canvas2_keep = false;		// boolean var needed for toggling lower canvas
var produce_mode = false;		// boolean var indicating if producing in player is enabled
var player_loaded = false;	// boolean var indicating if player has been loaded
var channel_to_edit; 				// uri of channel to manage/edit
var is_admin = false;				// boolean indicating if user has admin privilege
var current_uri = false;		// show uri displayd in player
var test_key = false;

// eventListener-functions to be bound to player events
var listener_showchg = function(ev){ player_show_changed(ev); };	// show changed in player
var listener_channelchg = function(ev){ player_channel_changed(ev); };	// show changed in player



/**
*	Create player. If player has been created already then re-load, remove
*	eventListeners and re-add them. Param produce indicates if producing
*	is enabled in player or not.
*/
function player_load(uri) {
	if (wide == true) {
		kyteplayer = new Kyte.Player(uri, { premium: true, height: 455, layoutMode: "wide", width: 820, t: ticket }, "player");
	} else {
		kyteplayer = new Kyte.Player(uri, { premium: true, height: 460, t: ticket }, "player");
	}

	kyteplayer.addEventListener("Navigation.ShowChanged", listener_showchg);
	kyteplayer.addEventListener("Navigation.ChannelChanged", listener_channelchg);
	
	var temp=uri;
	test_key = uri;
	setTimeout('player_hide("'+temp+'")',20000);
}

function player_hide(key) {
	return;

	if (test_key==key) {
		$('player_container').hide();
		alert("Melde dich jetzt an f�r die gr�sste Peter Maffay Community und erlebe Peter Maffay live!");
	}
}


function showdata_refresh(uri) {
	var myAjax = new Ajax.Request("ajax_calls.php", {
		parameters: {
			"action": "updataShowData",
			"uri": uri
		},
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			$("now_playing").innerHTML = response;
		},
		onFailure: function() {
			//smth
		}
	});	
	//$("ad_frame1").src = "load_ad.html";
	//var randomnumber = Math.floor(Math.random()*3) +1;
	//$("small_ad").innerHTML = "<img src='img/ad"+ randomnumber +".jpg'>";	
}


function player_show_changed(event) {
//	$('player_container').show();
	showdata_refresh(event.data.uri);
}

show_to_comment = false;
function comment_write(uri) {
	if (uri) {
		show_to_comment = uri;
		$("comment_form").show();
	}
}

function comment_send() {
	var myAjax = new Ajax.Request("ajax_calls.php", {
		parameters: {
			"action": "comment",
			"nick": $F("nick"),
			"uri": show_to_comment,
			"comment": $F("comment")
		},
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			if (response == "Show commented!") showdata_refresh(show_to_comment);
		},
		onFailure: function() {
			//loading(false);
		}
	});
	//show_to_comment = false;
	comment_box_hide();
}

function comment_box_hide() {
	$("comment_form").hide();
	$("comment").value = "";
	$("nick").value = "";	
}

function player_channel_changed(event) {
	var myAjax = new Ajax.Request("ajax_calls.php", {
		parameters: {
			"action": "updataChannelData",
			"uri": event.data.uri
		},
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			$("artist_profile").innerHTML = response;
		},
		onFailure: function() {
			//smth
		}
	});	
}

/**
*	Display show with defined uri in player
*/
function show_play(uri) {
	$('player_container').show();
	kyteplayer.setURI(uri);
	test_key = uri;
	var temp=test_key;
	setTimeout('player_hide("'+temp+'")',20000);
}



//////////////////////////////////////////////77 bluewin

var mouseX, mouseY;
function getMousePos(e) {
	if (!e) var e = window.event||window.Event;
	if('undefined'!=typeof e.pageX) {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}	else if (e.clientX) {
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
	}
}
if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePos;

function peep(show_uri, display, rand_id) {
	if (display) {
		$("peepshow").style.left = mouseX+20;
		$("peepshow").style.top = mouseY-30;
		$("peepshow").innerHTML = $(rand_id+"_"+show_uri).innerHTML;
		$("peepshow").show();
		//$("play_"+rand_id+"_"+show_uri).show();
	} else {
		$("peepshow").hide();
		$("play_"+rand_id+"_"+show_uri).hide();
		$("peepshow").innerHTML = false;
	}
	play_button("play_"+rand_id+"_"+show_uri, display);
}

function play_button(element_id, display) {
	if (display) $(element_id).show();
	else $(element_id).hide();
}

function diary_show() {
	$("video_diary").show();
}

function alertMe() {
	alert("Dieser Link dient um eine Funktion darzustellen, die durch den API m�glich ist!"); 
	
}

function print_shows(category, orderSpec) {
	if (orderSpec == "totalMessageCount-d") {
		alertMe();
		return;
	}
	//category = ""; // temporary drop all cats
	
	var myAjax = new Ajax.Request("ajax_calls.php", {
		parameters: {
			"action": "print_shows",
			"cat": category,
			"orderSpec": orderSpec
		},
		onSuccess: function(transport) {
			var response = transport.responseText || error_text();
			$("show_list_box").innerHTML = response;
		},
		onFailure: function() {
			//smth
		}
	});		
}

function search_shows() {
	search_key = $F("search_key");
	print_shows(search_key, "");
}

