﻿/* Player scripts */

scrollTicker = false;
scrollTicker2 = false;
function scrollLeft() {
    $("#songstertext").animate({right:-$("#songstertext").width()+$("#songstertextwrap").width()-5 },3000,function(){  setTimeout("scrollRight()",2000); });
}
function scrollRight() {
    if ($("#songstertextwrap").width() < $("#songstertext").width()) {
        $("#songstertext").animate({right:0 },2000,function(){ setTimeout("scrollLeft()",3000);});
        scrollTicker = true;
    } else {
        scrollTicker = false;
    }
}

function BrowserCheckEnh() {
        	var o = navigator.userAgent;
        	if (o.indexOf("Opera")>=0) { this.b = "Opera"; this.v = o.substring(o.indexOf("Opera")+6, o.indexOf(" ",o.indexOf("Opera")+6)); }
        	else if (o.indexOf("MSIE")>=0) { this.b = "IE"; this.v = o.substring(o.indexOf("MSIE")+5, o.indexOf(";",o.indexOf("MSIE")+5)); }
        	else if (o.indexOf("Netscape6")>=0) { this.b = "Netscape"; this.v = o.substring(o.indexOf("Netscape")+10, o.length); }
        	else if (o.indexOf("Netscape")>=0) { this.b = "Netscape"; this.v = o.substring(o.indexOf("Netscape")+9, o.indexOf(" ",o.indexOf("Netscape")+9)); }
        	else if (o.indexOf("Firefox")>=0) { this.b = "Firefox"; this.v = o.substring(o.indexOf("Firefox")+8, o.length); }
        	else if (o.indexOf("Gecko")>=0) { this.b = "Mozilla"; this.v = o.substring(o.indexOf("rv:")+3, o.indexOf(")",o.indexOf("rv:")+3)); }
        	this.v = (this.v.indexOf(" (") != -1)? this.v.substring(0,this.v.indexOf(" (")) : this.v;
        	this.op = (this.b=="Opera" && this.v>=5);
        	this.ns = (this.b=="Netscape" && this.v>=4);
        	this.ns4 = (this.b=="Netscape" && parseInt(this.v)==4);
        	this.ns6 = (this.b=="Netscape" && parseInt(this.v)==6);
        	this.ns7 = (this.b=="Netscape" && parseInt(this.v)==7);
        	this.ff = (this.b=="Firefox");
        	this.mo = (this.b=="Mozilla" && parseInt(this.v)>=1);
        	this.ie = (this.b=="IE" && this.v>=4);
        	this.ie4 = (this.b=="IE" && parseInt(this.v)==4);
        	this.ie5 = (this.b=="IE" && parseInt(this.v)==5);
        	this.ie6 = (this.b=="IE" && parseInt(this.v)==6);
        	this.min = (this.op||this.ns||this.mo||this.ie);
}
var isbr = new BrowserCheckEnh();

function scrollLeft2() {
    $("#songstertext2").animate({right:-$("#songstertext2").width()+$("#songstertextwrap2").width()-5 },3000,function(){  setTimeout("scrollRight2()",2000); });
}
function scrollRight2() {
    if ($("#songstertextwrap2").width() < $("#songstertext2").width()) {
        $("#songstertext2").animate({right:0 },2000,function(){ setTimeout("scrollLeft2()",3000);});
        scrollTicker2 = true;
    } else {
        scrollTicker2 = false;
    }
}

function PlayWM() {
      try {
        document.getElementById('MediaPlayer').play();
         
    } catch(e) {
        try {
             document.getElementById('MediaPlayer').controls.play();
        } catch(e) {}
    }
    
    
 
    $("#stop").show();
    $("#play").hide();
}

function StopWM() {
    try {
        document.getElementById('MediaPlayer').stop();
        
    } catch(e) {
        try {
             document.getElementById('MediaPlayer').controls.stop();
        } catch(e) {}
        }
    $("#stop").hide();
    $("#play").show();
     
}



function SetBitRate(bitrate) {
    url = "http://rlcast.lide.cz/fm-bonton-"+bitrate+".m3u";
         try {
            document.getElementById('MediaPlayer').URL = url;
            document.getElementById('MediaPlayer').Filename = url;
        } catch(e) {}
    $('#bitrate').removeClass().addClass("bitrate-"+bitrate);
}

function SetBitRateStandard(bitrate) {
    url = "http://rlcast.lide.cz/fm-bonton-"+bitrate+".m3u";
    makeStandardPlay(url);
    $('#bitrate').removeClass().addClass("bitrate-"+bitrate);
}

function SetVolume(x) {
        try {
            document.getElementById('MediaPlayer').settings.volume = x;
        } catch(e) {}
    $('#volume').removeClass().addClass("volume-"+x);
}  

function hideSilverlight() {
    $('#player-content').slideUp();
}

function makePlay() {
/*    	var cnt = document.getElementById("player-content");
    	var src = 'u/wmvplayer.xaml';
    	var cfg = {
    		file:'http://rlcast.lide.cz/fm-bonton-64.m3u',
    		width:'200',
    		height:'200',
    		autostart:'true'
    	};
    	ply = new jeroenwijering.Player(cnt,src,cfg);
*/
		
}






    
    function countDown() {
        
        lastsDuration++;
        
        if (lastsDuration > 59) {
            lastsDuration = 0;
            lastmDuration++;
        }
        if (lastsDuration < 10) {
            $('#sduration').text("0"+lastsDuration);
        } else {
            $('#sduration').text(lastsDuration);
        }
        $('#mduration').text(lastmDuration);
    }
function wmpCreate(url) {
    var str = "";
    if (isbr.ie) {
        // create the WMP for IE
        str = '<object id="MediaPlayer" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" type="application/x-oleobject" width="1" height="1">';
        str += '<param name="ShowControls" value="0">';
        str += '<param name="ShowDisplay" value="0">';
        str += '<param name="ShowGotoBar" value="0">';
        str += '<param name="ShowPositionControls" value="0">';
        str += '<param name="ShowStatusBar" value="0">';
        str += '<param name="ShowTracker" value="0">';
    } else {
         // create it for FF.
         str = '<object id="MediaPlayer" type="application/x-ms-wmp" data="'+url+'" width="1" height="1">';
    }
    str += '<param name="Enabled" value="1" >';
    str += '<param name="Filename" value="'+url+'">';
    str += '<param name="Url" value="'+url+'">';
    str += '<param name="uiMode" value="none">';
    str += '<param name="AutoStart" value="1">';
    str += '<param name="animationatStart" value="false">';
    str += '<param name="transparentatStart" value="false">';

    str += '</object>';

    return str;
}

function makeStandardPlay(url) {
    var str = "";
    str =  '<OBJECT ID="MediaPlayer" WIDTH=150 HEIGHT=170 CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="bgcolor: #fff">';
    str += '<PARAM NAME="URL" VALUE="'+url+'">';
    str += '<PARAM NAME="Filename" VALUE="'+url+'">';
    str += '<PARAM NAME="Autostart" VALUE="True">';
    str += '<PARAM NAME="UiMode" VALUE="Mini">';
    str += '<PARAM NAME="stretchToFit" VALUE="no">';
    
    str += '<PARAM NAME="EnableContextMenu" VALUE="False">';
    str += '<EMBED TYPE="application/x-mplayer2" SRC="'+url+'" filename="'+url+'" NAME="MediaPlayer" WIDTH="150" HEIGHT="170" ENABLECONTEXTMENU="False">';
    str += '</EMBED>';
    str += '</OBJECT>';

    document.getElementById("player-content-lite").innerHTML=str;
}

var isbr = new BrowserCheckEnh();

/* Songster AJAX request */
function updateSongster() {
    clearInterval(refreshSongster);
     if (scrollTicker == false) {
        scrollRight();
        
    }
    
    if (scrollTicker2 == false) {
        scrollRight2();
        
    }
    var xmlhttp=false;

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	var rDate = new Date();
	xmlhttp.open("GET", "/cs/inc/songster.xml?"+rDate.getTime(),true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		    if (xmlhttp.responseText.search(/<addmduration>(.+?)<\/addmduration>/) > -1) {
		        $('#mduration').text(xmlhttp.responseText.match(/<addmduration>(.+?)<\/addmduration>/)[1]);
            }
            if (xmlhttp.responseText.search(/<addsduration>(.+?)<\/addsduration>/) > -1) {
                if (xmlhttp.responseText.match(/<addsduration>(.+?)<\/addsduration>/)[1] == 0) {
			      $('#sduration').text("0"+xmlhttp.responseText.match(/<addsduration>(.+?)<\/addsduration>/)[1]);
			    } else {
                  $('#sduration').text(xmlhttp.responseText.match(/<addsduration>(.+?)<\/addsduration>/)[1]);
                }
                if (xmlhttp.responseText.search(/<mduration>(.+?)</) > -1) {
                    $('#timer').show();
                } else {
                     $('#timer').hide();
                }
		      
            }
            if (xmlhttp.responseText.search(/<addsduration>(.+?)/) > -1) {
                        lastsDuration = xmlhttp.responseText.match(/<addsduration>(.+?)<\/addsduration>/)[1];
                        lastmDuration = xmlhttp.responseText.match(/<addmduration>(.+?)<\/addmduration>/)[1];
                    }
    
	 if (xmlhttp.responseText.search(/<title>(.+?)/) > -1) {
	         try {
			   document.getElementById("track").innerHTML = xmlhttp.responseText.match(/<title>(.+?)<\/title>/)[1];
               document.getElementById("author").innerHTML = xmlhttp.responseText.match(/<artist>(.+?)<\/artist>/)[1];
               
                var testLastSong = xmlhttp.responseText.match(/<title>(.+?)<\/title>/)[1];
            
			    if (lastSong != testLastSong) {
			        lastSong = testLastSong;
                    //alert(lastSong);
                    if (xmlhttp.responseText.search(/<addsduration>(.+?)/) > -1) {
                        lastsDuration = xmlhttp.responseText.match(/<addsduration>(.+?)<\/addsduration>/)[1];
                        lastmDuration = xmlhttp.responseText.match(/<addmduration>(.+?)<\/addmduration>/)[1];
                    }
                } else {
                    if (xmlhttp.responseText.search(/<addsduration>(.+?)/) > -1) {
                        $('#sduration').text(xmlhttp.responseText.match(/<addsduration>(.+?)<\/addsduration>/)[1]);
                        if (xmlhttp.responseText.match(/<addmduration>(.+?)<\/addmduration>/)[1] < 10) {
                            $('#mduration').text("0" + xmlhttp.responseText.match(/<addmduration>(.+?)<\/addmduration>/)[1]);
                        } else {
                            $('#mduration').text(xmlhttp.responseText.match(/<addmduration>(.+?)<\/addmduration>/)[1]);
                        }
                    }
                }
                if (xmlhttp.responseText.search(/<mduration>(.+?)</) > -1) {
                    $('#timer').show();
                } else {
                     $('#timer').hide();
                }
                } catch (e) {}
			   } else {
                    document.getElementById("author").innerHTML = "Rádio Bonton";
                    document.getElementById("track").innerHTML = "Pop-rock nezastavíš";
                }
			if (xmlhttp.responseText.search(/<cover>(.+?)<\/cover>/) > -1) {
			   var cover = xmlhttp.responseText.match(/<cover>(.+?)<\/cover>/)[1];
			   
               if (cover != "NULL") {
			
                document.getElementById("cover").innerHTML = '<img src="http://songster.rmc.fg.cz/img/u/' + cover + '.jpg" width="60" height="60" alt=""/>';
		        $('#cover').fadeIn('normal');
               } else {
                $('#cover').hide();
               }

            } else {
                //document.getElementById("cover").innerHTML = '<img src="/img/u/player-max.jpg"/>';
               //$('#cover').fadeIn('normal');
               $('#cover').hide();
                document.getElementById("author").innerHTML = "Rádio Bonton";
                document.getElementById("track").innerHTML = "Pop-rock nezastavíš";
       } 
       
                
       refreshSongster = setInterval("countDown()", 1000);
            setTimeout("updateSongster()",15000);
	     }
	}
	xmlhttp.send(null);
}

