var OsVideoWidget = {
	rewriteurls: function(link){
		var urlParts = link.href.split("/");		
		link.href = "/2.127185/live?videoId=" + urlParts[4];
	}
};

function eventPlayerOpenPopup(contentpath, videoId, serverTime){
    var w = window.open(contentpath + "popup.html?videoId=" + videoId + "&amp;serverTime=" + serverTime, "popupplayer", "scrollbar=0,resizable=1,status=0,toolbar=0,width=665,height=743");
    w.focus();
}

function tableauNewsTickerCacheFix() {
    var ct = new Date();
    var d = ct.getFullYear().toString() + ct.getMonth().toString() + ct.getDate().toString() + ct.getHours().toString() + ct.getMinutes().toString();
    return d;
}


$(document).ready(function() {
	
	$("div.SgWidget").livequery(function(){
		$(this).each(function(){
			$("div.widget-videos ul.list li a").each(function(){
				OsVideoWidget.rewriteurls(this);
			});
		});
	});
	
	$("a.broadcastLink").livequery(function(){
		$(this).each(function(){
			OsVideoWidget.rewriteurls(this);
		});
	});
	
	/* Senaste video */
	$("div#SgPlayVideos1882835").livequery(function(){
		$(this).each(function(){
			$("div#SgPlayVideos1882835 div.gPlayVideoList div.browser div.content div.show-tab-container div.tab ul.list li a").each(function(){
				this.href = '/2.128236/senaste_video';
			});
		});
	});
	
	/* Höjdpunkter */
	$("div#SgPlayVideos1887561").livequery(function(){
		$(this).each(function(){
			$("div#SgPlayVideos1887561 div.gPlayVideoList div.browser div.content div.show-tab-container div.tab ul.list li a").each(function(){
				this.href = '/2.128482/hojdpunkter';
			});
		});
	});
	
	/* Vinterstudion */
	$("div#SgPlayVideos1887615").livequery(function(){
		$(this).each(function(){
			$("div#SgPlayVideos1887615 div.gPlayVideoList div.browser div.content div.show-tab-container div.tab ul.list li a").each(function(){
				this.href = '/2.128486/vinterstudion';
			});
		});
	});
	
	/* Uppvarmningen */ 
	$("div#SgPlayVideos1889678").livequery(function(){
		$(this).each(function(){
			$("div#SgPlayVideos1889678 div.gPlayVideoList div.browser div.content div.show-tab-container div.tab ul.list li a").each(function(){
				this.href = '/2.127100/kontakta_oss';
			});
		});
	});
	
	/* Hela tävlingar */ 
	$("div#SgPlayVideos1893170").livequery(function(){
		$(this).each(function(){
			$("div#SgPlayVideos1893170 div.gPlayVideoList div.browser div.content div.show-tab-container div.tab ul.list li a").each(function(){
				this.href = '/2.128678/hela_sandningar';
			});
		});
	});
	
	/* Just-nu-ticker */
	$("div#OSJustNu").hide();

	$("ul.newsticker").each(function() {
	    var newstickerUrl = $(this).metadata().url;
        var timeCache = tableauNewsTickerCacheFix();
          $.ajax({
            url: newstickerUrl,
            data: { included: true, columnWidth: 254, isEventTicker: true, timeCache: timeCache },
	        success: function(data) {
            $("ul.newsticker").html(data);
          }
        }); 
	});
		
    /* OS Twitter */
	//$("#twitter_update_list li.result_full:gt(2)").css("display", "none");
   // $("#twitter_update_list li.result_full:first").css("border", "none");
  //  $("#twitter_showmore").click(function() {
   // 	$("#twitter_update_list li").show();
  //  	$(this).hide();
   // });

});


	
