$(document).ready(function(){
    $("a.new_window").attr("target", "_blank");
    loadBanners();
    loadNieuws();
    switchLuisterLive();
    loadPlaylist();
    loadProgramma();
    setInterval(loadPlaylist, 30000);
    setInterval(loadProgramma, 300000);
    setInterval(loadBanners, 60000);
    $('.colorbox1').colorbox({
	width: "750px",
        // height: "350px",
        inline: true,
        href:"#luisterlive_popup"
        // onOpen:function() { },
        // onLoad:function() { },
        // onComplete:function(){ },
        // onCleanup:function() { },
        // onClosed:function() { }
    });
    $('.nieuws').colorbox();
});


function openwebplayer() {
    window.open('http://www.radioextragold.be/webplayer/aio/index.php', 'livestream', 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=670,height=450');
}

function loadPlaylist() {
    $.ajax({
	url: 'http://www.radioextragold.be/aio-scripts/lastplayed.php',
	data: 'aantal=5&id='+Math.random(),
	type: 'POST',
	dataType: 'html',
	async: true,
	cache: false,
//	beforeSend: function() {
//	    $('.laatstgespeeld').html('<li><a style="text-decoration: none;">Bezig met laden...</a></li>');
//	},
	success: function(data) {
	    $('.laatstgespeeld').html(data);
	}
    });
}

function loadNieuws() {
    $.ajax({
	url: 'http://www.radioextragold.be/aio-scripts/nieuws.php',
	data: '&aantal=10&id='+Math.random(),
	type: 'POST',
	dataType: 'html',
	async: true,
	cache: false,
//	beforeSend: function() {
//	    $('.regionieuws').html('<li><a style="text-decoration: none;">Bezig met laden...</a></li>');
//	},
	success: function(data) {
	    $('.regionieuws').html(data);
	}
    });
}

function loadBanners() {
    $.ajax({
	url: 'http://www.radioextragold.be/aio-scripts/bannerI.php',
	data: '&rand='+Math.round(Math.random()*1000000),
	type: 'POST',
	dataType: 'html',
	async: true,
	cache: false,
//	beforeSend: function() {
//	    $('.regionieuws').html('<li><a style="text-decoration: none;">Bezig met laden...</a></li>');
//	},
	success: function(data) {
	    $('.banners').html(data);
	}
    });
}

function loadProgramma() {
    $.ajax({
	url: 'http://www.radioextragold.be/aio-scripts/epg.php',
	data: 'ajax=true&type=homepage&id='+Math.random(),
	type: 'POST',
	dataType: 'json',
	async: true,
	cache: false,
//	beforeSend: function() {
//	    $('.currentP').html('Bezig met laden...');
//	},
	success: function(data) {
	    $('.currentP').html(data.currentP);
//	    $('.currentI').html(data.currentI);
	    $('.nextP').html(data.nextP);
//	    $('.nextI').html(data.nextI);
	    Cufon.refresh();
	}
    });
}

function loadWeerbericht(code) {
    $.ajax({
	url: 'http://www.radioextragold.be/aio-scripts/weerbericht.php',
	data: 'code='+code+'&id='+Math.random(),
	type: 'POST',
	dataType: 'html',
	async: true,
	cache: false,
//	beforeSend: function() {
//	    $('.currentP').html('Bezig met laden...');
//	},
	success: function(data) {
	    $('#weerbericht').html(data);
	    Cufon.refresh();
	}
    });
}

function switchLuisterLive() {
    var img = $('.luisterlive').attr('src');
    var img1 = "images/luister-live.png";
    var img2 = "images/luister-live2.png";
    if (img == img1) { var image = img2; }
    if (img == img2) { var image = img1; }
    $('.luisterlive').attr('src', image);
    setTimeout('switchLuisterLive()', 3000);
}

function playlistFile(type) {
    var url = 'http://www.radioextragold.be/webplayer/playlist.php';
    var data = 'type='+type+'&id='+Math.random();
    window.location = url+'?'+data;
}

function showFrequentieMap() {
    $('#freqmap').html('Bezig met laden...');
    //var koksijde = "15,106,22,104.8,FM,597,002%C2%B038%2700,51%C2%B007%2700,38,Directief,D036,Westpoint,Koksijde,,,,,";
    //var oostkamp = "119,90,21,104.9,FM,100,003%C2%B014%2709,51%C2%B010%2721,45,Niet-directief,E182,Alive,Oostkamp,,,,,";
    //var ichtegem = "82,116,21,105.8,FM,100,003%C2%B001%2709,51%C2%B004%2739,45,Niet-directief,E109,Extra+Gold+105.8,Ichtegem,,,,,";
    //var torhout  = "102,114,21,106.8,FM,100,003%C2%B008%2713,51%C2%B005%2711,27,Niet-directief,E225,Extra+GoldTorhout,Torhout,,,,,";
    //                                     LENGTEGRAAD      BREEDTEGRAAD    
    var koksijde  = "15,106,70,104.8,FM,597,,,90,Directief,,Radio+Extra+Gold,Koksijde,,,,,";
    var oostkamp  = "119,90,25,104.9,FM,100,,,45,Niet-directief,,Radio+Extra+Gold,Oostkamp,,,,,";
    var koekelare = "82,116,25,105.8,FM,100,,,45,Niet-directief,,Radio+Extra+Gold,Koekelare,,,,,";
    var torhout   = "102,114,25,106.8,FM,100,,,27,Niet-directief,,Radio+Extra+Gold,Torhout,,,,,";
    var content = koksijde + oostkamp + koekelare + torhout;
    $('#freqmap').flash({
	swf: 'http://www.radioextragold.be/themes/eg2011/swf/kaartje.swf',
	height: 198,
	width: 500,
	flashvars: {
	    freqcontent: content
	},
	expressInstaller: 'http://www.radioextragold.be/themes/eg2011/swf/expressInstall.swf'
    });
}

