/*
    Show either the silverlight or the flash stream player
*/

var myPly = '';
var myVol = '50';

function switchLivePlayer(mode) {
    switch(mode) {
        case 'silverlight':
            $('#flContentStream').css('display', 'none');
            $('#slContent').css('display', 'block');
        break;

        case 'jwplayer':
            $('#slContent').css('display', 'none');
            $('#flContentStream').css('display', 'block');
        break;
    }
}

function loadSilverlight(myfile,mutebool){

	myVol = '50';
 	if(mutebool == true) myVol = 0;

 	switchLivePlayer('silverlight');

 	var cnt = document.getElementById('slContainer');
 	if (!cnt) {
 		var cnt = document.createElement("div");
		cnt.setAttribute("id", "slContainer");
		document.getElementById("slContent").appendChild(cnt);
 	}
 	
 	var src = '/fileadmin/SWF/wmvplayer.xaml';
 	var cfg = {height:'311',width:'540',file:myfile,windowless:'true',backcolor:'1D5C87',frontcolor:'FFFFFF',screencolor:'1D5C87',lightcolor:'FF6600',overstretch:'true',shownavigation:'false',autostart:"true",volume:myVol};
 	var ply = new jeroenwijering.Player(cnt,src,cfg);

	myPly = ply;
}

function loadJW(myfile,type,duration,mutebool){

	var c = document.getElementById("jwPlayerStream");
	if (!c) {
		var d = document.createElement("div");
		d.setAttribute("id", "jwPlayerStream");
		document.getElementById("flContentStream").appendChild(d);
	}

	myVol = '50';
	if(mutebool == true) myVol = '0';

	var flashvars = '';

	if(duration != undefined && duration != '' ){
	//alert('file:'+myfile);
	flashvars = {
	    screencolor: "#1D5C87",
	    controlbar: "none",
	    icons: "false",
	    provider:type,
	    duration:duration,
	    file:myfile,
	    volume:myVol
		}
	}else{
	//alert(' normal mp3 file:'+myfile);
		flashvars = {
		    screencolor: "#1D5C87",
		    controlbar: "none",
		    icons: "false",
		    provider:type,
		    bufferlength:'0',
		    file:myfile,
		    volume:myVol,
		}
	}
	var params = {
		menu: "false",
		scale: "noScale",
		allowFullscreen: "false",
		allowScriptAccess: "always",
		bgcolor: "#FFFFFF",
		wmode: "transparent"
	};

	var attributes = {
		id:"JWPlayer",
		name:"JWPlayer"
	};

	swfobject.embedSWF("/fileadmin/SWF/player.swf", "jwPlayerStream", "540", "311", "9.0.0", "/fileadmin/SWF/expressInstall.swf", flashvars, params, attributes);
	switchLivePlayer('jwplayer');
}

function playerReady(obj) {

	sendJWPlayerEvent('PLAY', 'true');
	sendJWPlayerEvent('VOLUME', myVol);

};



/*
    Send an event to the silverlight player
*/
function sendSilverlightEvent(event, val) {
	if(myPly != undefined && typeof(myPly) == 'object') {
        if(val != '') {

        	myPly.sendEvent(event, val);
        } else {
            myPly.sendEvent(event);

        }
    }
}

/*
    Send an event to the silverlight player
*/
function sendJWPlayerEvent(event, val) {
    var player = document.getElementById('JWPlayer');

    if(player != undefined && (typeof(player) == 'object' || typeof(player) == 'function')) {
        if(val != '') {
            player.sendEvent(event,val);
        } else {

            player.sendEvent(event);
        }
        player.addModelListener('STATE','stateMonitor');
    }
}


function stateMonitor(event){
	if(event.newstate == 'IDLE'){
		var radioplayer = document.getElementById('Radioteaser');
		radioplayer.flashcontrol('idle');
	}
}

/*
	playfunction
*/


function removeAll(){
	//REMOVE
	swfobject.removeSWF("JWPlayer");
	
	document.getElementById('slContent').innerHTML = '';
	
	$('#flContentStream').css('display', 'none');
    $('#slContent').css('display', 'none');
}


function mute(volume){
	sendSilverlightEvent('VOLUME', volume);
	sendJWPlayerEvent('VOLUME', volume);
}


function play(myFile,myState,fileType,myType,muteBool){
    //console.log(myFile);
		
	//FIRST REMOVE
	removeAll();

	switch(myType){

		case 'audiostream':
			loadJW(myFile,fileType,'9999',muteBool);
		break;

		case 'videostream':
			loadSilverlight(myFile,muteBool);
		break;

		case 'video':
			loadSilverlight(myFile,muteBool);
		break;

		case 'broadcast':
			loadJW(myFile,fileType,'9999',muteBool);
		break;
		case 'audio':
			loadJW(myFile,fileType,'9999',muteBool);
		break;

	}

}

/**
SIMPLE PIE BEGIN ==========================
*/



/**
 *
 * Update RSS/ATOM feed and display it using SimplePie and Ajax
 *
 *
 * LICENSE: This source file is subject to the BSD license
 * that is available through the world-wide-web at the following URI:
 * http://www.opensource.org/licenses/bsd-license.php.
 *
 * @author     Michael P. Shipley <michael@michaelpshipley.com>
 * @copyright  2008 Michael P. Shipley
 * @license    http://www.opensource.org/licenses/bsd-license.php BSD
 * @version    1.0
 * @link       http://www.michaelpshipley.com Michael Shipley
 */

/*
	Global variables
*/

/**
	Use ajax to call  SimplePie to get feed data
	@param: feedUrl  string  feed link
	@param: scriptUrl string php script url
	@param: cacheDuration integer SimplePie cache duration in seconds
	@param: divId string id of div to output html to
*/
function updateFeed(feedUrl,scriptUrl,cacheDuration,divId, itemCount)
{
   var div = $('#' + divId);
   $('#' + divId).html('<div class="feed-loading"><img src="/fileadmin/GFX/ajax-loader.gif" /></div>');

   var end = new Date();

   $('#' + divId).load(scriptUrl + '&mode=ajax&rand=' + end.getTime(), {url : feedUrl, cacheduration: cacheDuration, itemCount : itemCount}  );

   return true;
}



/**
SIMPLE PIE END ==========================
*/

/*
 * jQuery UI Resizable 1.7.2
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Resizables
 *
 * Depends:
 *	ui.core.js
 */



