$(document).ready(function() {
			
	$('.channel').livequery(function(){
        $(this).each(function() {
            $(this).bt({
				  fill: '#F7F7F7', 
				  strokeStyle: '#B7B7B7', 
				  spikeLength: 10, 
				  spikeGirth: 10, 
				  padding: 8, 
				  cornerRadius: 0, 
				  ajaxPath: ["$(this).attr('itemid')"],
				  positions: ['right', 'left'],
				  cssStyles: {
					fontFamily: '"lucida grande",tahoma,verdana,arial,sans-serif', 
					fontSize: '11px',
					color: '#000'
				  }
			});
        });
	});

	
	$('#info').livequery(function(){
        $(this).each(function() {
    		$(this).bt({
				contentSelector: "$(this).attr('text')",
				fill: '#F7F7F7', 
				strokeStyle: '#B7B7B7', 
				spikeLength: 10, 
				spikeGirth: 10, 
				padding: 8, 
				cornerRadius: 0, 
				positions: ['bottom', 'left', 'right'],
				cssStyles: {
				fontFamily: '"lucida grande",tahoma,verdana,arial,sans-serif', 
					fontSize: '11px',
					color: '#000'
				  }
				});
			});
		});	
	
	$('#centerban_content').show();
		$("#centerban_content").showcase({
		css: { width: "920px", height: "220px", border: "1px black solid"},
		animation: { type: "fade", interval: 6000 },
		titleBar: { autoHide: false }, 
		navigator: { position: "top-right", orientation: "vertical", autoHide: false,
                 css: { padding:"6px", margin: "4px 0px 0px 0px", "z-index": 99999 },
                 item: {
                     css: { height:"8px", width:"8px", "-moz-border-radius": "8px", "-webkit-border-radius": "8px",
                            backgroundColor: "Transparent", borderColor:"#878787" },
                     cssHover: { backgroundColor: "#ababab" },
                     cssSelected: { backgroundColor: "#dadada", borderColor: "#dadada" }
                 }		
			},
		titleBar: { autoHide: false, css: { backgroundColor: "#000000", height: "20px", color: "White", fontSize: "1em", opacity: "0.5" } }
	}); 
	
$('#' + when).css('color', '#990088');
$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});		

window.setInterval(function() {
    getstreg();
}, 60000);

	//start scrollpane
	
		//scrollpane parts
		var scrollPane = $('.scroll-pane');
		var scrollContent = $('.scroll-content');
		
		//build slider
		var scrollbar = $(".scroll-bar").slider({
			slide:function(e, ui){
				if( scrollContent.width() > scrollPane.width() ){$( "#scroll-bar1" ).slider({ value: ui.value }); $( "#scroll-bar2" ).slider({ value: ui.value }); scrollContent.css('margin-left', Math.round( ui.value / 100 * ( scrollPane.width() - scrollContent.width() )) + 'px'); }
				else { scrollContent.css('margin-left', 0); }
			}
		});
		
		//append icon to handle
		var handleHelper = scrollbar.find('.ui-slider-handle')
		.mousedown(function(){
			scrollbar.width( handleHelper.width() );
		})
		.mouseup(function(){
			scrollbar.width( '100%' );
		})
		.append('<span class="ui-icon ui-icon-grip-dotted-vertical"></span>')
		.wrap('<div class="ui-handle-helper-parent"></div>').parent();
		
		//change overflow to hidden now that slider handles the scrolling
		scrollPane.css('overflow','hidden');
		
		//size scrollbar and handle proportionally to scroll distance
		function sizeScrollbar(){
			var remainder = scrollContent.width() - scrollPane.width();
			var proportion = remainder / scrollContent.width();
			var handleSize = scrollPane.width() - (proportion * scrollPane.width());
			scrollbar.find('.ui-slider-handle').css({
				width: handleSize,
				'margin-left': -handleSize/2
			});
			handleHelper.width('').width( scrollbar.width() - handleSize);
		}
		
		//reset slider value based on scroll content position
		function resetValue(){
			var remainder = scrollPane.width() - scrollContent.width();
			var leftVal = scrollContent.css('margin-left') == 'auto' ? 0 : parseInt(scrollContent.css('margin-left'));
			var percentage = Math.round(leftVal / remainder * 100);
			scrollbar.slider("value", percentage);
		}
		//if the slider is 100% and window gets larger, reveal content
		function reflowContent(){
				var showing = scrollContent.width() + parseInt( scrollContent.css('margin-left') );
				var gap = scrollPane.width() - showing;
				if(gap > 0){
					scrollContent.css('margin-left', parseInt( scrollContent.css('margin-left') ) + gap);
				}
		}
		
		//change handle position on window resize
		$(window)
		.resize(function(){
				resetValue();
				sizeScrollbar();
				reflowContent();
		});
		//init scrollbar size
		setTimeout(sizeScrollbar,10);//safari wants a timeout
	

	$( ".scroll-bar" ).bind( "slidechange", function(event, ui) {
				if( scrollContent.width() > scrollPane.width() ){ scrollContent.css('margin-left', Math.round( ui.value / 100 * ( scrollPane.width() - scrollContent.width() )) + 'px'); }
				else { scrollContent.css('margin-left', 0); }			
		});
	saetwidth();
});

function saetwidth() {
	var w = $('#guidecontainer').width()-150;
	$('.scroll-pane').width(w);
	
}

function play(id) {
	$.prettyPhoto.open($('#'+id).attr("youtube"),'','');
}

function makeTall(){  $(this).animate({"height":75},200);}
function makeShort(){ $(this).animate({"height":50},200);}
	
function cleartable() {
$('div.bla_new').each(function() {
        $(this).fadeOut(500, function() {
                $(this).remove();
				});
				});
				
$('div.tvimg_new').each(function() {
        $(this).fadeOut(500, function() {
                $(this).remove();
				});
				});				
	getstreg();
	return false;
}	
	
function fjernclick(object, showid) {
        $('#guide' + showid).slideUp('slow', function() {;
        $('#guide' + showid).remove();
		getstreg(this);
        });
return false;
}
	

function confirm_del() {
	if (confirm ("Sikker på at du ønsker at slette denne?")) {
		return true;
	}else{
		return false;
	} 
}

function getstreg(object, h) {
var hoej = $("#guide").height();
hoej = hoej - 10;
$.ajax({
                type: 'get',
                url: 'getinfo.php',
                data: 'type=streg&start=' + startvar + '&ie=' + ie,
                success: function(result) {
				result = result.replace(/^\s+|\s+$/g, '');
          		if (result=='false') {
				$("#streg").css('display', 'none');
			}
			else
			{
				$("#streg").css('display', 'inline');
               	$("#streg").css('margin-left', result);
				var bar = result.replace('px','');
				
				var barpercent = bar / 7180;
				barpercent = barpercent * 100;
				$("#scroll-bar1").slider("value", barpercent);
				$("#scroll-bar2").slider("value", barpercent);
				if (h) {
					$("#streg").css('height', h);
				}
				else
				{
                	$("#streg").css('height', hoej);
				}
			}
	        }
        });
}

function getklok(object) {
$('#kloklist').remove();
$.ajax({
                type: 'get',
                url: 'getinfo.php',
                data: 'type=klok&start=' + startvar,
                success: function(result) {
                $('<div id="kloklist">' + result + '</div>').appendTo('#klok').fadeIn(1000);
		}
        });
}
getklok(this);


function checkses() {
	setTimeout("checkses()", 5000);
	$.ajax({
		type: 'get',
		url: 'tjekses.php',
		success: function(result) {
			if (result == "1") {
				location.href = "index.php";
			} else if(result == "2") {	
			//	setTimeout("checkses()", 10000);
			} else if(result == "") {
			//	setTimeout("checkses()", 5000);
			} else {
				location.href = result;
			}
		}
	});
}
setTimeout("checkses()", 5000);

function startchan(showid, ikon) {
if (startvar == "24") { startvar = "00"; when++; }
if (startvar > "21") { startvar = "21"; }
$('#guide' + showid).slideUp('slow', function() {;
      $('#guide' + showid).remove();
	});
	$.ajax({
                type: 'get',
                url: 'addonechan.php',
                data: 'id=' + showid + '&start=' + startvar + '&stop=24&when=' + when,
                success: function(result) {
					var output = result.split('¤');
                    $('<div id="guide' + showid +'" class="bla"><div id="img' + showid +'" class="tvimg"><a href="#" onclick="hideall(this,' + showid  + ',' + when + ', \'getall\'); return false;"><img border="0" src="' + output[0] + '"></a><br><a href="#" onclick="fjernclick(this,' + showid + '); return false">fjern</a></div>' + output[1] + '</div>').appendTo('#guide').fadeIn(1000);
                	getstreg(this);
		}

        });
return false;
}

function getallchans(what,uid,id) {
if (startvar == "24") { startvar = "00"; when++; }
if (startvar > "21") { startvar = "21"; }
	$.ajax({
        type: 'get',
        url: 'getchans.php',
        data: 'start=' + startvar + '&stop=24&when=' + when + '&what='  + what + '&uid=' + uid + '&id=' + id,
        success: function(result) {
			cleartable();
			var complete = result.split('|');
			for(i = 0; i < complete.length; i++){
				var output = complete[i].split('¤');
					if (output[1]) {
						$('<div id="img' + output[1] +'" class="tvimg_new"><a href="#" onclick="hideall(this,' + output[1]  + ',' + when + ', \'getall\'); return false;"><img border="0" src="' + output[0] + '"></a><a href="#" onclick="fjernclick(this,' + output[1] + '); return false"></a></div>').appendTo('#chanimglist').fadeIn(1000);
						$('<div id="guide' + output[1] +'" class="bla_new">' + output[2] + '</div>').appendTo('#guide').fadeIn(1000);
						whatplan = what
						cuid = uid
						cid = id
					}
				}	
				getstreg(this);
			}
			
        });
$(this).delay(4000, function() {
	getstreg(this);
	
});
	
return false;
}

function move(sel){
	nexthour("","",when,sel.options[sel.selectedIndex].value);
}

function nexthour(object,move,dag,tid) {

nextactive = "1";



if (dag) {
when = dag;
} else {
dag = when;
}

var stop = 24;

var r1 = dag;
var r2 = dag - 1;
var r3 = dag - 2;
var r4 = dag - 3;
var r5 = dag - 4;
var r6 = dag - 5;
var r7 = dag - 6;
var r8 = dag - 7;
var r9 = dag - 8;
var r10 = dag + 1;
var r11 = dag + 2;
var r12 = dag + 3;
var r13 = dag + 4;
var r14 = dag + 5;
var r15 = dag + 6;
var r16 = dag + 7;
var r17 = dag + 8;

$('#' + r1).css('color', '#ffffff');
$('#' + r2).css('color', '#ffffff');
$('#' + r3).css('color', '#ffffff');
$('#' + r4).css('color', '#ffffff');
$('#' + r5).css('color', '#ffffff');
$('#' + r6).css('color', '#ffffff');
$('#' + r7).css('color', '#ffffff');
$('#' + r8).css('color', '#ffffff');
$('#' + r9).css('color', '#ffffff');
$('#' + r10).css('color', '#ffffff');
$('#' + r11).css('color', '#ffffff');
$('#' + r12).css('color', '#ffffff');
$('#' + r13).css('color', '#ffffff');
$('#' + r14).css('color', '#ffffff');
$('#' + r15).css('color', '#ffffff');
$('#' + r16).css('color', '#ffffff');
$('#' + r17).css('color', '#ffffff');
$('#' + dag).css('color', '#990088');

$("#guide").css('height', $("#guide").height());
	$.ajax({
        type: 'get',
        url: 'getchans.php',
        data: 'start=' + startvar + '&stop=24&when=' + when + '&what='  + whatplan + '&uid=' + cuid + '&id=' + cid,
        success: function(result) {
			cleartable();
			var complete = result.split('|');
			for(i = 0; i < complete.length; i++){
				var output = complete[i].split('¤');
					if (output[1]) {
						$('<div id="img' + output[1] +'" class="tvimg_new"><a href="#" onclick="hideall(this,' + output[1]  + ',' + when + ', \'getall\'); return false;"><img border="0" src="' + output[0] + '"></a><a href="#" onclick="fjernclick(this,' + output[1] + '); return false">fjern</a></div>').appendTo('#chanimglist').fadeIn(1000);
						$('<div id="guide' + output[1] +'" class="bla_new">' + output[2] + '</div>').appendTo('#guide').fadeIn(1000);
					}
				}	
			}
        });
getstreg();

return false;
} 

function update() {
	time = new Date();
	hour = time.getHours();
	mins = time.getMinutes();
	if (mins == "0") { mins = "00"; }
	if (mins == "1") { mins = "01"; }
	if (mins == "2") { mins = "02"; }
	if (mins == "3") { mins = "03"; }
	if (mins == "4") { mins = "04"; }
	if (mins == "5") { mins = "05"; }
	if (mins == "6") { mins = "06"; }
	if (mins == "7") { mins = "07"; }
	if (mins == "8") { mins = "08"; }
	if (mins == "9") { mins = "09"; }
	document.getElementById('visnudato').innerHTML = hour + ':' + mins;
	setTimeout("update()", 20000);
}

function updatestreg() {
	getstreg();
	setTimeout("updatestreg()", 20000);
}



var whatplan = "";
var cuid = "";
var cid = "";

