 
function Webusr(webroot) {
	webThis = this;
	this.so = null;
	this.server = webroot;
	this.css_images = webroot+'styles/images/';
	this.initialize();
}

function getArgs(){
	passedArgs=new Array();
	search = self.location.href;
	search = search.split('?');
	if(search.length>1){
		argList = search[1];
		argList = argList.split('&');
		for(var i=0; i<argList.length; i++){
			newArg = argList[i];
			newArg = argList[i].split('=');
			passedArgs[unescape(newArg[0])] = unescape(newArg[1]);
		}
	}
	
	return passedArgs;
}

Webusr.prototype.initialize = function() {
	var node = "rtmp://n0"+ Math.round(Math.random()) +".mc2.sk/";
	//var node = "rtmp://n00.mc2.sk/";

	webThis.so = new SWFObject(webThis.server+'player/player.swf', 'player', '720', '465', '9.0.45', '#000000');
	webThis.so.addParam("allowFullScreen","true");
	webThis.so.addVariable("node", node)
	webThis.so.addVariable("mode", "modeLive");
	webThis.so.addVariable("age", "age18");
	webThis.so.addVariable("autoPlay", "1"); 
	webThis.so.addVariable("basePath", "http://mc2.sk/");

	//mc2 vysielanie
	webThis.so.addVariable("v", "mc2-hi");

	//live zo scientifictv
	//webThis.so.addVariable("v", "mc2-bcc-std-002");
		
	
	//check, if HD is required from start
	var args = getArgs();
	if (args['quality'] == 'HD') {
		//todo: odkomentovat
		webThis.so.addVariable("v", "mc2-hd");
	}	
	
	webThis.so.write('flashcontent');
	
	//zmena kvality
	$$('#quality a').addEvent('click', function(event) {
		if(this.rel == 'mc2-hi' || this.rel == 'mc2-lo' || this.rel == 'mc2-hd'){
			var node = "rtmp://n0"+ Math.round(Math.random()) +".mc2.sk/";
			//var node = "rtmp://n00.mc2.sk/";
			webThis.so.addVariable("node", node)
			webThis.so.addVariable("mode", "modeLive");
			
			$('low').removeClass('qual_low_a');
			$('high').removeClass('qual_high_a');
			$('hd').removeClass('qual_hd_a');
			if (this.rel == 'mc2-lo') {
				$(this).addClass('qual_low_a');
			}
			else if (this.rel == 'mc2-hi') {
				$(this).addClass('qual_high_a');
			}
			else {
				$(this).addClass('qual_hd_a');
			}
		}
		else {
			var node = "rtmp://n00.mc2.sk/";
			webThis.so.addVariable("node", node)
			webThis.so.addVariable("mode", "modeFile");
			$('low').removeClass('qual_low_a');
			$('high').removeClass('qual_high_a');
			$('hd').removeClass('qual_hd_a');
			
			if (this.rel.contains('lo')) {
				$(this).addClass('qual_low_a');
			}
			else if (this.rel.contains('hi')) {
				$(this).addClass('qual_high_a');
			}
			else {
				$(this).addClass('qual_hd_a');
			}
		}
		
		//mc2 vysielanie
		webThis.so.addVariable("v", this.rel);
		
		//scientific live
		//webThis.so.addVariable("v", "mc2-bcc-std-002");
		
		webThis.so.write('flashcontent');
		
		event.preventDefault();
		event.stop();
		
		return false;

	});
	
	//prepni na normalne vysielanie
	$('archive').addEvent('click', function(event) {
		$('archive').addClass('disable');		
		$('online').innerHTML = 'Aktuálne vysielanie';
		
		$('low').setProperty('rel','mc2-lo');
		$('high').setProperty('rel','mc2-hi');
		$('hd').setProperty('rel','mc2-hd');
		
		$('low').removeClass('qual_low_a');
		$('high').removeClass('qual_high_a');
		$('hd').removeClass('qual_hd_a');
		
		$('high').addClass('qual_high_a');

		var node = "rtmp://n0"+ Math.round(Math.random()) +".mc2.sk/";
		//var node = "rtmp://n00.mc2.sk/";
		webThis.so = new SWFObject(webThis.server+'player/player.swf', 'player', '720', '465', '9.0.45', '#000000');
		webThis.so.addParam("allowFullScreen","true");
		webThis.so.addVariable("node", node)
		webThis.so.addVariable("mode", "modeLive");
		webThis.so.addVariable("age", "age18");
		webThis.so.addVariable("autoPlay", "1"); 
		webThis.so.addVariable("basePath", "http://mc2.sk/");
			
		//mc2 vysielanie
		webThis.so.addVariable("v", "mc2-hi");
		
		//scientific live
		//webThis.so.addVariable("v", "mc2-bcc-std-002");
		
		webThis.so.write('flashcontent');
		
		$$('#mc2_archiv_div div a').removeClass('active');
		
		event.preventDefault();
		event.stop();
		return false;
	});
	
}

function play(llo, lhi, lhd, ttext, uid) {
		
		$('archive').removeClass('disable');
		
		$('online').innerHTML = 'Archív: ' + ttext;
		
		
		$('low').setProperty('rel',llo);
		$('high').setProperty('rel',lhi);
		$('hd').setProperty('rel',lhd);
		
		
		var node = "rtmp://n00.mc2.sk/";
		
		webThis.so = new SWFObject(webThis.server+'player/player.swf', 'player', '720', '465', '9.0.45', '#000000');
		webThis.so.addParam("allowFullScreen","true");
		webThis.so.addVariable("node", node)
		webThis.so.addVariable("mode", "modeFile");
		webThis.so.addVariable("age", "age18");
		webThis.so.addVariable("v", $('high').getProperty('rel'));
		webThis.so.addVariable("autoPlay", "1");
		webThis.so.addVariable("basePath", "http://mc2.sk/");
		webThis.so.write('flashcontent');
		
		$('low').removeClass('qual_low_a');
		$('high').removeClass('qual_high_a');
		$('hd').removeClass('qual_hd_a');
		
		$('high').addClass('qual_high_a');
		
		$$('#mc2_archiv_div div a').removeClass('active');
		$(lhi).addClass('active');
		
		//zapis ze dana relacia sa pozrela
		var countreq = new Request({method: 'get',url: 'index.php'});
		countreq.send('id=1&tx_mc2archiv_pi1[count]='+uid);
		
		//event.preventDefault();
		//event.stop();
		return false;
}