filter = new Array();
filter["TV"] = new Array();filter["radio"] = new Array();filter["news"] = new Array();
filter["TV"]['type'] = "";filter["TV"]['lang'] = "";filter["TV"]['q'] = "";
filter["radio"]['type'] = "";filter["radio"]['lang'] = "";filter["radio"]['q'] = "";
filter["news"]['type'] = "";filter["news"]['lang'] = "";filter["news"]['q'] = "";

var timer = new Array(setTimeout("",1),setTimeout("",1),setTimeout("",1));
var media_db = new Array();
var pl_current,full=false,pl_data;


function gId(id) {return document.getElementById(id);}

function minimize() {
var MC = gId('MC_container');	
var switcher = gId('switcher');		
var MC_parent = top.document.getElementById('6P_MC');	  	  
if (MC.style.visibility) {
	MC_min=false;
	MC.style.visibility = '';
	switcher.className = 'bl_sw_open';
	MC_parent.style.height = '';
} else {
	MC_min=true;
	MC.style.visibility = 'hidden';
	switcher.className = 'bl_sw_closed';
	MC_parent.style.height = '22px';	
} 
}
function fl_fct(n) {
if(n!='radio'&&n!='TV'&&n!='news') clear_all();

switch(n) {
	case 0 :gId('radio').style.display='';load_media("radio");urchinTracker("/MC/radio");break;
	case 1 :gId('TV').style.display='';load_media("TV");urchinTracker("/MC/TV");break;
	case 2 :gId('news').style.display='';load_media("news");urchinTracker("/MC/news");break;
	case 3 :setTimeout("zoomFlash('flash_rbc',290,1)",400);gId('rbc').style.display='';gId('rbc').style.visibility='';urchinTracker("/MC/rbc");break;
	case 4 :gId('lfm').style.display='';gId('lfm').style.visibility='';urchinTracker("/MC/lfm");break;
	default :break;
}
}

function clear_all() {
gId('rbc').style.visibility='hidden';
gId('rbc').style.display=gId('lfm').style.display=gId('playing').style.display=gId('playlist').style.display=gId('radio').style.display=gId('TV').style.display=gId('news').style.display='none';
gId('playlist').innerHTML=gId('radio').innerHTML=gId('TV').innerHTML=gId('news').innerHTML='';
}

function zoomFlash(id,z,x) {
if(gId(id)) gId(id).Zoom(z);
setTimeout("zoomFlash('"+id+"',"+z+")",50);
if(x==1) gId('rbc').style.visibility='';
}

function quit()
{
MC_lite();
top.frames[2].location.href="include/noMC.php";
top.document.getElementById("6P_MC").style.display = 'none';
}

function open_ddl(id) {
	list = new Array(gId('lang_ddl'),gId('type_ddl'));
	if(list[id].style.display == 'none') {
		list[0].style.display = 'none';
		list[1].style.display = 'none';
		//list[2].style.display = 'none';
		list[id].style.display = '';   
	}
	else close_ddl(id);
	reset_timer(id);
}

function close_ddl(id) {
	list[id].style.display = 'none';
}
function reset_timer(id) {
	clearTimeout(timer[id]);
	timer[id] = setTimeout("close_ddl("+id+")",1500);
}

function update_media(type,cat,v) {
elm_list="";

if(cat=="type" || cat=="lang") {
	gId(cat+"_"+filter[type][cat]).style.background="";
	gId(cat+"_"+v).style.background="#76c5e6";
}

if(cat && cat!="") filter[type][cat]=v;

q_test = new RegExp(".*"+filter[type]['q']+".*","i");
md=media_db[type];

for(var i in md.media) {
	if((filter[type]['type']=="" || filter[type]['type']==md.media[i].category) && (filter[type]['lang']=="" || filter[type]['lang']==md.media[i].lang) && (filter[type]['q']=="" || q_test.test(md.media[i].name))) {
		if(md.media[i].extra=="") launch='open_media(\''+type+'\',\''+md.media[i].URL+'\')';
		else launch='clear_all();open_media(\'channel\',\''+md.media[i].URL+'\',\''+md.media[i].extra+'\')';
	elm_list+='<tr class="MC_media_row" onClick="'+launch+'" onMouseOver="this.className=\'MC_media_row MC_media_row_over\'" onMouseOut="this.className=\'MC_media_row\'"><td width=30><img src="images/flags/'+md.media[i].lang+'.gif" style="margin-left:6px"/></td><td width=80>'+window.cat[type][md.media[i].category]+'</td><td><b>'+md.media[i].name+'</b></td></tr>';
	}
}

gId("media_list").innerHTML='<table width=100%>'+elm_list+'</table>';
}

function open_media(type,url,pl) {
gId('playing').style.background=gId('playing').innerHTML='';

w=h="100%"
if(!full && type=="yt") {w="340px";h="285px";}

vid_tag='<embed style="width:'+w+';height:'+h+';z-index:1500" type="application/x-shockwave-flash" wmode="transparent" allowFullScreen="false" allowScriptAccess="always" ';
aud_tag='<embed type="application/x-shockwave-flash" allowFullScreen="false" allowScriptAccess="always" ';
aud_st=' style="width:340px;height:80px;z-index:1500" ';
wmp_tag='<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" enableContextMenu="0" showdisplay="0" showgotobar="0" showcaptioning="0" enabletracker="0" autostart="true" loop="true" showstatusbar="1" showcontrols="1" volume="50" ';
pl_tag='<table width="100%" style="background:#F3F3F3;border-bottom:1px solid #D1D1D1;font-size:11px;height:30px"><tr><td id="pl_hd"></td></tr></table><div id="pl_items" class="'+pl+'_items"><img src="images/ld.gif" style="margin:20px 0 0 20px" /></div>';
nav_tag='<table><tr height=20 style="font-size:11px;border-bottom:1px solid #D1D1D1"><td width=80 style="text-align:center"><b><a style="display:block" href="javascript:pl_shift(-1)">◄ '+text['prev']+'</a></b></td><td width=180 style="text-align:center"><b id="pl_num">1/12</b></td><td width=80 style="text-align:center"><b><a style="display:block" href="javascript:pl_shift(1)">'+text['next']+' ►</a></b></td></tr></table>';

if(type=="playlist" || type=="channel") {gId('playlist').innerHTML=gId('playlist').style.display=''};
if((type=="yt"||type=="dm"||type=="kw"||type=="my") && !full) gId('playlist').style.display='none';

switch(type) {
	case "yt":gId('playing').innerHTML=vid_tag+'src="http://www.youtube.com/v/'+url+'&rel=1&autoplay=1" id="yt"></embed>';break;
	case "dm":gId('playing').innerHTML=vid_tag+'src="http://www.dailymotion.com/swf/'+url+'" autoplay=1></embed>';break;
	case "kw":gId('playing').innerHTML=vid_tag+'src="http://www.kewego.com/swf/p.swf?sig='+url+'&autoStart=true"></embed>';break;
	case "my":gId('playing').innerHTML=vid_tag+'src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m='+url+'&v=2&type=video&a=1"></embed>';break;
	case "dz":gId('pl_aud').innerHTML=aud_tag+'src="http://www.deezer.com/embedded/small-widget.swf?idSong='+url+'&colorBackground=0x525252&colorButtons=0xDDDDDD&textColor1=0xFFFFFF&autoplay=1" id="dz" style="width:220px;height:40px;margin-top:25px;z-index:1500"></embed>';setTimeout("zoomFlash('dz',100,1)",400);break;
	case "rb":gId('pl_aud').innerHTML=aud_tag+'src="http://stat.radioblogclub.com/radio.blog/skins/mini/player.swf" width="340" height="23" style="z-index:1500;margin-top:30px" flashVars="id=-1&filepath=http://www.radioblogclub.com/listen?u='+url+'&colors=body:#d3edf7;border:#36a1c3;button:#36a1c3;player_text:#5171B1;playlist_text:#5171B1;"></embed>';break;
	case "sz":gId('pl_aud').innerHTML=aud_tag+'src="http://songza.com/e/listen" FlashVars="zName=%20&zId='+url+'" style="width:300px;height:80px;z-index:1500" id="songza"></embed>';setTimeout("zoomFlash('songza',200,1)",400);break;	
	case "sr":gId('pl_aud').innerHTML=aud_tag+aud_st+'src="http://skreemr.com/audio/player.swf" flashvars="playerID=1&bg=0xCDDFF3&leftbg=0x36a1c3&lefticon=0xF2F2F2&rightbg=0x36a1c3&rightbghover=0x73c5e5&righticon=0xF2F2F2&righticonhover=0xFFFFFF&text=0x5171B1&slider=0x5171B1&track=0xFFFFFF&border=0xFFFFFF&loader=0xBBBBBB&soundFile='+url+'"></embed>';break;	
	case "sp":gId('pl_aud').innerHTML=aud_tag+aud_st+'src="http://www.seeqpod.com/cache/seeqpodSlimlineEmbed.swf" flashvars="playlistXMLPath=http://www.seeqpod.com/api/music/getPlaylist?playlist_id='+url+'"></embed>';break;
	case "TV":gId('playing').innerHTML=wmp_tag+'src="http://www.6pages.com/special/6P_MC/stream.php?u='+url+'" filename="'+url+'" autosize="1" stretchtofit="1" style="width:100%;height:100%;z-index:1500"></embed>';break;
	case "radio": gId('mp_radio').innerHTML=wmp_tag+'width="340" height="60" src="'+url+'"></embed>';break;
	case "news":gId('playing').style.background='#FFF';gId('playing').innerHTML='<table width="100%" style="background:#F3F3F3;border-bottom:1px solid #D1D1D1;font-size:11px;height:30px"><tr><td id="feed_img" width=130 height=30></td><td id="search_list"></td></tr></table><div id="news_items"><img src="images/ld.gif" style="margin:20px 0 0 20px" /></div>';url1 = url.replace(/=/g,"%3D");url2 = url1.replace(/&/g,"%26");new net.ContentLoader('special/6P_MC/getXML.php?url='+url2, parse_media, ['news']);break;
	case "playlist":gId('playlist').innerHTML=pl_tag; if(pl!="url") gId('playlist').innerHTML+=nav_tag; if(pl=="audio") gId('playlist').innerHTML+='<div id="pl_aud" style="width:340px;height:80px;text-align:center;background:#f9f9f9">';new net.ContentLoader('include/backend/getMediaInPlaylist.php?listid='+url, load_ext, ['playlist',pl]);break;
	case "channel":gId('playlist').innerHTML=pl_tag;url1 = url.replace(/=/,"%3D");url2 = url1.replace(/&/,"%26");new net.ContentLoader('special/6P_MC/getXML.php?url='+url2, load_ext, ['channel',pl]);break;	
	default:break;
}
if(type!="playlist"&&type!="channel"&&type!="radio"&&type!="dz"&&type!="sz"&&type!="sr"&&type!="sp"&&type!="rb") {gId('playing').style.display=""; gId('playing').style.visibility='visible';}

pl_current=pl;
if(gId('pl_num') && pl_data) gId('pl_num').innerHTML=(pl+1)+"/"+pl_data.length;
}

function stripTags(x) {
    return x.replace(/<\/?[^>]+>/gi, '');
}

function parse_media(type,q) {

bl=gId("news_items");
bl.innerHTML='';

if(!q) {
feed = 0;
if(this.req.responseXML.getElementsByTagName("rss")[0]) {root = this.req.responseXML.getElementsByTagName("rss")[0]; feed=0; }
else if(this.req.responseXML.getElementsByTagName("feed")[0]) {root = this.req.responseXML.getElementsByTagName("feed")[0]; feed=2; }
else {root = this.req.responseXML.documentElement; feed=1;}

if(feed==2) tree = root;
else tree = root.getElementsByTagName("channel")[0];

if(feed==0)logo_node="url";
else logo_node="image";

if(tree.getElementsByTagName("link")[0].firstChild && tree.getElementsByTagName("link")[0].firstChild.nodeValue && tree.getElementsByTagName(logo_node)[0]) {
	if(feed==0) logo_url=tree.getElementsByTagName(logo_node)[0].firstChild.nodeValue;
	else logo_url=tree.getElementsByTagName(logo_node)[0].attributes.getNamedItem("rdf:resource").value;
	gId('feed_img').innerHTML='<a href="'+tree.getElementsByTagName("link")[0].firstChild.nodeValue+'" target="_blank"><img src="'+logo_url+'" class="MC_rss_logo" onMouseOver="this.className=\'MC_rss_logo_over\'" onMouseOut="this.className=\'MC_rss_logo\'"/></a>';
}
gId("search_list").innerHTML = '<input class="field" style="width:190px;height:17px;font-size:11px" type="text" value="'+text['search']+'" tabindex="1" onFocus="this.className = \'field field_focus\';if(this.value==\''+text['search']+'\') this.value=\'\';" onblur="this.className = \'field\';if(this.value==\'\') this.value=\''+text['search']+'\';parse_media(\''+type+'\',this.value);" onKeyUp="parse_media(\''+type+'\',this.value)">';
}

q_test = new RegExp(".*"+q+".*","i");

if(feed==0) items = tree.getElementsByTagName("item");
else if(feed==2) items = root.getElementsByTagName("entry");
else items = root.getElementsByTagName("item");

if(type=="channel") bl.innerHTML+='<table width="100%" class="MC_playlist">';
i=0;
while(items[i]) {

	if(items[i].getElementsByTagName("description") && items[i].getElementsByTagName("description")[0] && items[i].getElementsByTagName("description")[0].firstChild) desc = items[i].getElementsByTagName("description")[0].firstChild.nodeValue;
	else if(items[i].getElementsByTagName("content") && items[i].getElementsByTagName("content")[0].firstChild) desc = items[i].getElementsByTagName("content")[0].firstChild.nodeValue;	
	else desc = "";

	desc = stripTags(desc);
	title = items[i].getElementsByTagName("title")[0].firstChild.nodeValue;	
	if(q=="" || !q || q==text['search'] || q_test.test(title) || q_test.test(desc)) {
		img_tag="";
		audio_tag="";
		if(items[i].getElementsByTagName("enclosure")[0] && items[i].getElementsByTagName("enclosure")[0].attributes.getNamedItem("url")) {
			enc=stripTags(items[i].getElementsByTagName("enclosure")[0].attributes.getNamedItem("url").value);
			if(enc.indexOf(".gif") !=-1 || enc.indexOf(".jpg") !=-1 || enc.indexOf(".png") !=-1) img_tag='<img src="'+enc+'" width=60 height=50 style="float:left;margin:3px 3px 3px 0">';
			if(enc.indexOf(".mp3") !=-1) audio_tag='<br/><embed src="flash/dewplayer.swf?mp3='+enc+'&amp;showtime=1&amp;volume=70" quality="high" bgcolor="FFFFFF" width="200" height="20" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>';			
		}
		if(items[i].getElementsByTagName("link")[0].firstChild) item_url=items[i].getElementsByTagName("link")[0].firstChild.nodeValue;
		else item_url=items[i].getElementsByTagName("link")[0].attributes.getNamedItem("href").value;
		bl.innerHTML+='<div style="position:relative;float:left;border-bottom:1px solid #DDD;margin:1px 0 3px 0;padding:0 0 3px 0;width:100%"><a href="'+item_url+'" target="_blank"><b>'+img_tag+title+'</b></a><br/>'+desc.substring(0,150)+' ...'+audio_tag+'</div>';
	}
	i++;
}
}

function load_ext(orig,t) {

if(t!="url") tmp='<table width="100%" class="MC_playlist">';
else tmp='<center>';
k=0;
gId('pl_items').innerHTML="";
if(orig!="channel") {d=eval('('+this.req.responseText+')'); 
	n=d.name;
	pl=d.media;
	for (var i in pl) { 
		k++; 
		if(t!="url") tmp+=item_gen(pl[i].Name,pl[i].Src,pl[i].Url,k);
		else tmp+=url_gen(pl[i].Name,pl[i].Src,pl[i].Url);
	}
} else {
	root=this.req.responseXML.getElementsByTagName("rss")[0];
	tree=root.getElementsByTagName("channel")[0];
	n=tree.getElementsByTagName("title")[0].firstChild.nodeValue;
	items=tree.getElementsByTagName("item");
	pl=new Array();
	while(items[k]) {
		pl[k]=new Array();
		pl[k].Name=items[k].getElementsByTagName("title")[0].firstChild.nodeValue;			
		url=items[k].getElementsByTagName("link")[0].firstChild.nodeValue.split("?v=");
		pl[k].Url=url[1];
		pl[k].Src=t;
		tmp+=item_gen(pl[k].Name,t,pl[k].Url,k+1);
		k++;
	}
	t='video';
}
window.pl_data=pl;
if(t!="url") tag='</table>';
else tag='</center>';
gId('pl_items').innerHTML=tmp+tag;
gId('pl_hd').innerHTML='<img src="images/icons/6m_'+t+'.gif" class="fl_L" style="margin:0 5px"/><b style="line-height:24px;font-size:13px">'+n+'</b>';	
if(gId('pl_num')) gId('pl_num').innerHTML="-/"+pl.length;
}

function pl_shift(x) {
if(!isFinite(pl_current)) pl_current=-1;
l=pl_data.length;
k=(pl_current+x)%l;
if(k<0) k=l-1;
open_media(pl_data[k].Src,pl_data[k].Url,k);
}

function item_gen(n,t,u,k) {
	return '<tr onclick="open_media(\''+t+'\',\''+u+'\','+(k-1)+')" class="MC_media_row" onMouseOver="this.className=\'MC_media_row MC_media_row_over\'" onMouseOut="this.className=\'MC_media_row\'"><td width="30"><img src="images/icons/mc_'+t+'.gif" style="margin-left:6px"/></td><td><b>'+k+'. </b>'+n+'</td></tr>'
}

function url_gen(n,t,u) {
m=n;
if(n.length > 11) n=n.substr(0,8)+"...";
else if(n.length > 14) n=n.substr(0,11)+"...";
if(t=="rss") {img='<img width=80 height=60 src="../images/rss.gif"/>';a='href="javascript:open_media(\'news\',\''+u+'\')"';}
else {img='<img width=80 height=60 src="../images/no_thumb.gif"/><img width=80 height=60 src="http://open.thumbshots.org/image.pxf?url='+u+'" style="position:absolute;top:3px;left:3px"/>';a='href="'+u+'" target="_blank"';}
return '<table style="float:left;font-size:11px;margin-left:3px"><tr><td><a '+a+' title="'+m+'" class="bl_img" style="width:80px;height:80px">'+img+'<div style="margin-top:5px">'+n+'</div></a></td></tr></table>';
}

function lfm_launch(x,y) {
gId('lfm_player').innerHTML = "";
if(y) x='lastfm%3A%2F%2Fartist%2F'+x+'%2Fsimilarartists';
else x='globaltags%2F'+x;
gId('lfm_player').innerHTML = '<embed name="flash_lfm" src="http://cdn.last.fm/webclient/74/lfmPlayer.swf" wmode="opaque" quality=high bgcolor=#FFFFFF width="340" height="123" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW" type="application/x-shockwave-flash" FlashVars="lang='+text['lang']+'&autostart=true&lfmMode=radio&radioURL='+x+'" swLiveConnect="true" allowScriptAccess="always" style="z-index:1500"></embed>';
}

function MC_full() {
if(gId('yt')) {gId('yt').style.width=gId('yt').style.height="100%";}
x = gId('playing');
var MC = gId('MC_container');
if (MC.style.visibility) {minimize(); MC_min=true;}
gId('loader').style.display='none';
top.gId('6P_MC').className="iframe_6P_MC MC_full";
top.gId('6P_MC').style.height='';
MC.className="MC_container MC_cont_full";
gId('MC_body').style.width="100%";
gId('top_lite').style.display = "none";
gId('cf_bg').style.display=gId('full_nav').style.display=gId('full_B').style.display=gId('full_T').style.display="";
gId('TV').className=gId('radio').className=gId('news').className=gId('playlist').className="MC_media MC_media_full";
if(gId('playlist').innerHTML!="")gId('playlist').style.display='';
x.style.visibility='visible';
x.className="MC_playing MC_playing_full";
gId('MC_center').style.width="1001px";
gId('rbc').style.left=gId('lfm').style.left="652px";
gId('lfm_list').className="MC_lfm MC_lfm_full";
full=true;
}

function MC_lite() {
if(gId('yt')) {gId('yt').style.width="340px";gId('yt').style.height="285px";}
x = gId('playing');
top.gId('6P_MC').className="iframe_6P_MC";
gId('MC_container').className="MC_container";
gId('MC_body').style.width="";
gId('top_lite').style.display = "";
gId('cf_bg').style.display=gId('full_nav').style.display=gId('full_B').style.display=gId('full_T').style.display="none";
gId('TV').className=gId('radio').className=gId('news').className=gId('playlist').className="MC_media";
x.style.visibility='visible';
x.className="MC_playing";
if(!gId('pl_aud')) gId('playlist').style.display='none';
gId('MC_center').style.width="";
gId('rbc').style.left=gId('lfm').style.left="0";
gId('lfm_list').className="MC_lfm";
if(nav.indexOf("MSIE")!= -1 && !MC_min) {minimize(); setTimeout("minimize()",5);}
else {if (MC_min) minimize();}
full=false;
}

function sw_film() {
x = gId('playing');
y = gId('playlist');
if(x.style.visibility=='hidden') {x.style.visibility='visible';if(!full) y.style.display='none';}
else {x.style.visibility='hidden'; if(y.innerHTML.length>1) y.style.display='';}
}

function load_6m(id,type) {
clear_all();document.flash_MC.GotoFrame(12);open_media('playlist',id,type);
}