function embed(url){
	return '<embed type="application/x-shockwave-flash" src="http://gameland.tv/mediaplayer.swf" style="" id="PlayerID" name="PlayerID" quality="high" allowfullscreen="true" flashvars="file='+url+'&width=490&height=420&displayheight=420&overstretch=none&stretching=none&shuffle=false&thumbsinplaylist=false&autostart=true" width="490" height="420">';
}
function embed1(url){
		p=$$('.archive')[0];
		e=$$('#'+p.id+' .embed_area')[0];
		//$$('#'+p.id+' .video')[0].innerHTML
		e.innerHTML='<textarea style="width:480px;height:200px">'+embed(url)+'</textarea>';
	}
function embed2(m,url){
	p=$(m);
	e=$$('#'+p.id+' .embed_area')[0];
	e.innerHTML='<textarea style="width:480px;height:200px">'+embed(url)+'</textarea>';
}

function clear_html(ar){
	for(i=0;i<ar.length;i++){
		ar[i].innerHTML='';
	}
}


window.addEvent('domready', function() { 
	
	if($$('.archive')[0]){
		p=$$('.archive')[0];
		cont=$$('#'+p.id+' .video')[0];
        url=$$('#'+p.id+' .flv')[0].innerHTML;
        createplayer(cont,url,1);
        
        e_l=$$('#'+p.id+' .embed_link')[0];
        e_l.innerHTML='<a href="#" onclick="embed1('+"'"+url+"'"+');return false;">Получить код видео</a>';
	}
	
	$$('.archive h4').addEvent('click',function () {
		/*
		$$('.video').set('html','');
		$$('.embed_link').set('html','');
		$$('.embed_area').set('html','');/**/
		
		clear_html($$('.video'));
		clear_html($$('.embed_link'));
		clear_html($$('.embed_area'));
		
		p=this.getParent();
		cont=$$('#'+p.id+' .video')[0];
		url=$$('#'+p.id+' .flv')[0].innerHTML;
		createplayer(cont,url,1);
		
		e_l=$$('#'+p.id+' .embed_link')[0];
        e_l.innerHTML='<a href="#" onclick="embed2('+"'"+p.id+"'"+','+"'"+url+"'"+');return false;">Получить код видео</a>';
	});
	
	/*
	if($('flvplayer')){
		createplayer('flvplayer','http://home5.inet.tele.dk/nyboe/flash/mediaplayer/video.flv',0);
	}
	/*
	if($$('.content a img')[0])
		$$('.content a img')[0].addEvent('click',function (e){
			e=new Event(e);
			e.stop();
			show();
		});/**/
	
	var cover  = new Element('div', {id: 'cover',
		styles: {
	        position: 'absolute',
	        top:0,
	        left:0
	    }
	});
	var player  = new Element('div', {id: 'player', html:'<span id="close">close</span><div id="player_div"></div> ',
		styles: {
	        width: 490,
	      height: 400,
	        border: '1px solid #ccc',
	        background: 'black',
	        color: 'white'
	    }
	});
	
	cover.setStyle('width','100%');
	cover.setStyle('text-align','center');
	player.setStyle('text-align','left');
	
	cover.addEvent('mouseover',function(){
		document.getElementById('p472').style.display='none';
		document.getElementById('p471').style.display='none';
	});
	cover.fade('hide');
	

	player.setStyle('margin-left','auto');
	player.setStyle('margin-right','auto');
	player.setStyle('margin-bottom','20px');
	
	player.inject(cover);
	//cover.inject($('htmlbody'));
	cover.inject(document.body);
	
	$('close').addEvent('click',function (e){
		e=new Event(e);
		e.stop();
		c=$('cover');
		c.fade(0);
		$('player_div').set('html','');
		$$('div.moduls_container')[0].fade(1);
	});
	// window.addEvent
});

function show(){
	$$('div.moduls_container')[0].fade(0.2);
	
	createplayer('player_div','http://home5.inet.tele.dk/nyboe/flash/mediaplayer/video.flv',1);
	
	c=$('cover');
	c.setStyle('top',$$('div.moduls_container')[0].offsetTop+14);
	c.setStyle('padding-top',20);
	c.setStyle('height',$$('div.moduls_container')[0].offsetHeight );
	c.fade(1);
}

function createplayer(div,theFile, go) {
	var s = new SWFObject("http://gameland.tv/mediaplayer.swf","PlayerID","490","420","7");
	s.addParam("allowfullscreen","true");
	s.addVariable("file",theFile);
	s.addVariable("width","490");
	s.addVariable("height","420");
	s.addVariable("displayheight","420");
	//s.addVariable("overstretch","fit");
	s.addVariable("overstretch","none");
	s.addVariable("stretching","none");
	s.addVariable("shuffle","false");
	s.addVariable("thumbsinplaylist","false");
	if (go) { s.addVariable("autostart","true"); }
	s.write(div);
}