$(document).ready(function() {
        
        window.onfocus=pageload;
    //tc-fm Streamwindow
        $("#tcfmbox .cover a, #tcfmbox .tcfmico.hear, a.fmtitle").live('click',function(){
            newWindow('http://tc-fm.de/tcfmStreamwindow.html', 400, 572);
            return false;
        });
    //tc-fm Voting
        $("a.tcfmvote, img.playlistvote").live('click',function(){
            if(isNaN( $(this).attr("rel") )){
                songid = $("#tcfmsongid").text();
                vote = 0;
            }else{
                songid = $(this).attr("rel");
                vote = $(this).attr("id");
            }
            url = "/api.php?songvote&vote=" + $(this).attr("id") +"&id=" + songid  + "&voteid=" + vote;
            $("#" + songid).css("display","none");
            $.getJSON(url,function(data) {
                alert(data.msg, data.title);
            });          
        });        
        
});
/** GLOBAL VAR **/
    var last;                   //TC-FM
    var aktive;                 //TC-FM
    var popupDefWidth	= 570;  //PopUp  
    var popupDefHeight	= 700;  //PopUp
//PopUp
    function newWindow (url) {
    	var width = !newWindow.arguments[1]		? popupDefWidth		: newWindow.arguments[1];
    	var height = !newWindow.arguments[2]	? popupDefHeight	: newWindow.arguments[2];
    	var add		= newWindow.arguments[3];
    	popup = window.open(url,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+width+',height='+height);
    	return false;
    }
//TC-FM
    function date(){ 
        return ( new Date().getTime() / 1000 ) - last;
    }       
    function lastreq(){
        last = new Date().getTime() / 1000;
    }
    function pageload(){
        
        if( date() > 15 ){
            $("#tcfmbox").load("/api.php?song=tcfm", function(){ lastreq(); } );
        }
        aktive = setInterval('$("#tcfmbox").load("/api.php?song=tcfm", function(){ lastreq(); } );',15000);
        window.onblur=function(){
            window.clearInterval(aktive);
        }
    }


