
var debugString = "";
var debug = true;

if(location.href.indexOf("print=1") == -1) {
	//Cufon
	//Cufon.replace('#topnavigation a', { fontFamily: 'FFMaxTFSemiBold', hover: true });
	Cufon.replace('.shortcuts h3', { fontFamily: 'FFMaxTFSemiBold' });
	
	Cufon.replace('.appetizer_large h1', { fontFamily: 'FFMaxTFLight' });
	Cufon.replace('.appetizer_large h2', { fontFamily: 'FFMaxTFSemiBold' });
	Cufon.replace('.appetizer_small h1', { fontFamily: 'FFMaxTFLight' });
	
	
	//Cufon.replace('.news h3', { fontFamily: 'FFMaxTFSemiBold' });
	
	Cufon.replace('.shortcuts_items li a', { fontFamily: 'FFMaxTFLight', hover: true });
	
	Cufon.replace('.box h3', { fontFamily: 'FFMaxTFLight' });
	
	//Cufon.replace('.linkfooter h3', { fontFamily: 'FFMaxTFLight' });
	
	//Cufon.replace('.article h1', { fontFamily: 'FFMaxTFLight' });
	//Cufon.replace('.article span.article_digest', { fontFamily: 'FFMaxTFLight' });
	//Cufon.replace('.article_related h3', { fontFamily: 'FFMaxTFLight' });

	Cufon.replace('#forside_temp', { fontFamily: 'FFMaxTFSemiBold' });
	
	Cufon.replace('.tab_content h2', { fontFamily: 'FFMaxTFSemiBold' });
	Cufon.replace('.tab_content h3', { fontFamily: 'FFMaxTFSemiBold' });	
	Cufon.replace('.appetizer_contact h3', { fontFamily: 'FFMaxTFSemiBold' });
	Cufon.replace('.appetizer_contact h4', { fontFamily: 'FFMaxTFSemiBold' });
}
else {
	//ingen Cufon i print
}



$().ready(function () {
	$('.appetizers_small .appetizer_text:lt(3)').css({ 'height': '130px'});
	$('.appetizers_small .appetizer_text:gt(3)').css({ 'height': '100px'});

var location = document.location.href.toString();

if (location.indexOf("formuepleje.dk") != -1 && $(".appetizer_small:nth-child(2) .appetizer_image a").length > 0){
	 	//kort fortalt
	 	$(".appetizer_small:nth-child(4) .appetizer_image a").fancybox({
					'type': 'iframe',
					'overlayOpacity' : '0.8',
					'overlayColor' : '#222',
					'href' : 'http://www.youtube.com/embed/_1gd14mhGKE?autoplay=1'
		});
		/*$(".appetizer_small:nth-child(4) .appetizer_link a").fancybox({
					'type'	: 'iframe',
					'overlayOpacity' : '0.8',
					'overlayColor' : '#222',
					'href' : 'http://www.youtube.com/embed/_1gd14mhGKE?autoplay=1'
		});*/
		$(".appetizer_small:nth-child(4) .appetizer_title h2 a").attr('href','http://www.youtube.com/embed/_1gd14mhGKE?autoplay=1');
		$(".appetizer_small:nth-child(4) .appetizer_title h2 a").fancybox({
					'type'	: 'iframe',
					'overlayOpacity' : '0.8',
					'overlayColor' : '#222',
					'href' : 'http://www.youtube.com/embed/_1gd14mhGKE?autoplay=1'
		});
		
		//aarsstatus
	 	$(".appetizer_small:nth-child(8) .appetizer_image a").fancybox({
					'type': 'iframe',
					'overlayOpacity' : '0.8',
					'overlayColor' : '#222',
					'href' : 'http://www.youtube.com/embed/QI6uJ2eguhw?autoplay=1'
		});
		
		$(".appetizer_small:nth-child(8) .appetizer_title h2 a").attr('href','http://www.youtube.com/embed/_1gd14mhGKE?autoplay=1');
		$(".appetizer_small:nth-child(8) .appetizer_title h2 a").fancybox({
					'type'	: 'iframe',
					'overlayOpacity' : '0.8',
					'overlayColor' : '#222',
					'href' : 'http://www.youtube.com/embed/QI6uJ2eguhw?autoplay=1'
		});
		
}

/*
if ($(".appetizer_large .appetizer_image a").length > 0){
	$(".appetizer_large .appetizer_image a").fancybox({
				'type'	: 'iframe',
				'overlayOpacity' : '0.8',
				'overlayColor' : '#222',
				'href' : 'http://www.youtube.com/embed/_1gd14mhGKE?autoplay=1'
	});
}
*/

	$("div.page_header input:text").blur(function() {
		if ($(this).val() != '')
			$(this).addClass("typing");
		else
			$(this).removeClass("typing");
	}).focus(function () {
		$(this).addClass("typing");
	});
});

$(window).load(function () {
	$("#include-from-outside").load("http://formuepleje.dk/files/formuepleje.dk/Exceldata/Forside_temp1.htm");
	
	$("div.informerFeed").each(function () {
		$data = $(this).find(".data");
		var ul = "<table>";
		$data.find("tr").each(function(i) {
			if (i > 14) return false;
				var time = $(this).find("td:first").html().substring(0,5);
				var text = $(this).find("td:eq(1) b:first").html();
				ul += "<tr><td class=\"f\">" + time + "</td><td>" + text + "</td></tr>";
		});
		ul += "</table>";
		$(this).removeClass("hidden").html(ul);
	});
	if ($(".sidebar .outline .frontpageText").length == 1 && $("div.informerFeed").length == 1) {
		$outline = $(".sidebar .outline .frontpageText");
		var pageBodyHeight = $(".page_body").height() - 53;
		$outline.css("margin-bottom", "0");
		var outlineHeight = $outline.height();
//		if (outlineHeight < (pageBodyHeight)) $outline.height(pageBodyHeight);
	}

});

$(function()
{
	// wait for the document to load, 
	// since Webbit browsers loads js and css in parrallel
	if (jQuery.browser.safari){
		$(window).load(function(){
			//setAppetizerHeights();
		});
	}else{
		//setAppetizerHeights();
	}


	if ($("#tickerUL").length > 0) {
		$("#tickerUL").ticker({
			debugMode: true,
			controls: true,
			titleText: ''
		});
	}
	if (debug && !self.console && debugString.length > 0) alert(debugString);
});

function setAppetizerHeights()
{
	if ($(".appetizer_large").length > 0 && $(".appetizers_small").length > 0)
	{
		var maxHeight = $(".page_body").height();
		var appetizerLargeHeight = $(".appetizer_large").height();
		var noBottomHeight = $(".sidebar .noBottom").height();
		var shortcutsHeight = $(".sidebar .shortcuts_container").height();


//		$(".sidebar .last .box").height(maxHeight - noBottomHeight - shortcutsHeight - 10 - 14 - 15 - 4 - 2);
		if ($(".appetizers_small").width() < 750) {
			var tallestSmall = 0;
			$(".appetizers_small .appetizer_small").each(function() {
				if ($(this).find(".appetizer_text").height() > tallestSmall) tallestSmall = $(this).find(".appetizer_text").height();
			});
			$(".appetizers_small .appetizer_small").find(".appetizer_text").height(tallestSmall);
		}
		else
		{
			$(".appetizers_small .appetizer_small").each(function() {
				var imgHeight = 98;
				if ($(this).find("img").height() > 0) imgHeight = $(this).find("img").height();
				if (!(window.ie6HeightOffset === undefined)) imgHeight += ie6HeightOffset;
				$(this).find(".appetizer_text").height(maxHeight - imgHeight - 14 - 38 - 4 - 1 - 15 - 4 - appetizerLargeHeight);
			});
		}
	}
}

function printing()
{
	var u = printurl();
	w = window.open(u,'print','width=650,height=680,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');
	w.focus();
}

function printurl()
{
	var u = document.location.href;
	if(u.indexOf('#') > 0)
	{
		u = u.split('#');
		u = u[0];
	}
	u += (u.indexOf('?') >0) ? '&':'?';
	u += 'print=1';
	return u;
}


function log(s)
{
	var now = new Date();
	var s = (now.getTime() + '').substr(9) + ": " + s;
	if (debug && self.console)
		console.log(s);
	else if (debug)
		debugString += s + "\n";
}

