var video_type = 'Silverlight';  // possible values: Silverlight, Flash

function createCookie(name,value,hours) {
	if (hours) {
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function clearCookie(name) {
	var date = new Date();
	date.setTime(date.getTime()-(48*60*60*1000));
	var expires = "; expires="+date.toGMTString();

	document.cookie = name+"=nothing"+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function closeTvStream() {
	// stop
	
	if (video_type == 'Silverlight') {
		// Below is the Silverlight way of stopping the player
		if (typeof ply != 'undefined' && ply != null) {
			//alert('ply exists.  Stopping it');
			ply.sendEvent('STOP');
		} else {
			//alert('ply does not exist.  Doing nothing.');
		}
	} else {
		// Below is the Flash way of stopping the player
		$('#container').html('');
	}

	// hide
	document.getElementById('tvstream').style.display = 'none';

	// show
	document.getElementById('show_tvstream').style.display = 'block';

	// cookie
	createCookie('hide_tvstream','Do Not Show','6');
}

function openTvStream() {
	// cookie
	clearCookie('hide_tvstream');

	// hide
	document.getElementById('show_tvstream').style.display = 'none';

	// show
	document.getElementById('tvstream').style.display = 'block';

	// start
	/*if (typeof ply != 'undefined' && ply != null) {
		//alert('ply exists.  Sending PLAY event.');
		ply.sendEvent('PLAY'); // This never worked I think
	} else {*/
		//alert ('ply does not exist.  Creating it.');
		
		createPlayer('260','320');
	//}
}

function createPlayer(height_param, width_param) {
	if (video_type == 'Silverlight') {
		// Below is the Silverlight code for creating a player
		cnt = document.getElementById('container');
		src = '/inc/wmvplayer.xaml';
		cfg = {height:''+height_param,width:''+width_param,file:'rtsp://bizvisionlivewm.fplive.net/bizvisionlivewm-live/bizvision001', overstreach:'fit', shownavigation:'true',showdigits:'false',autostart:'true'};
		ply = new jeroenwijering.Player(cnt,src,cfg);
	} else {
		// Below is the Flash code for creating a player
		$('#container').load('/inc/tvstream_object.inc.php?width='+width_param+'&height='+height_param);
	}
}

