﻿
$(document).ready(function() {

//$('#container').load('http://google.com'); // SERIOUSLY!
/* 
$.ajax({
    url: 'http://news.bbc.co.uk',
    type: 'GET',
    success: function(res) {
        var headline = $(res.responseText).find('a.tsh').text();
        alert(headline);
    }
});
*/

    checkstream();

});


function checkstream(){

    var $j = jQuery.noConflict(); 
    var url = 'http://api.own3d.tv/liveCheck.php?live_id=124011';
    $j.getJSON("http://query.yahooapis.com/v1/public/yql?"+
              "q=select%20*%20from%20html%20where%20url%3D%22"+
               encodeURIComponent(url)+
               "%22&format=xml'&callback=?",
	       function(x){
          if(x.results[0]){
            var data = filterData(x.results[0]);
	    if(data.indexOf("false") != -1){
		$j("#slive").append("<a href='http://www.own3d.tv/Werit#/live/124011'>offline</a>");
	    } else {
		$j("#slive").append("<a href='http://www.own3d.tv/Werit#/live/124011'>ONLINE</a>");
	    }

	  }
	       }

    //$.ajax({
//	    url: url,
//	    type: 'GET',
//	    success: function(x){
 
//	    alert(x);

//	}
    //}
    );

}

 function filterData(data){
    // filter all the nasties out
    // no body tags
    data = data.replace(/<?\/body[^>]*>/g,'');
    // no linebreaks
    data = data.replace(/[\r|\n]+/g,'');
    // no comments
    data = data.replace(/<--[\S\s]*?-->/g,'');
    // no noscript blocks
    data = data.replace(/<noscript[^>]*>[\S\s]*?<\/noscript>/g,'');
    // no script blocks
    data = data.replace(/<script[^>]*>[\S\s]*?<\/script>/g,'');
    // no self closing scripts
    data = data.replace(/<script.*\/>/,'');
    // [... add as needed ...]
    return data;
 }



