
function countdown(){
	var millisecs_per_day=86400000;
	// set countdown time in milliseconds
	// put desired day as arguments to Date.UTC in the order:
	// Universal Coordinated Time (UTC) --> Greenwich Mean Time (GMT)
	// year, month (remember January is 0), day of month, offset from GMT
	// NOTE: we are using the offset because that represents midnight
	// (beginning of the day) in a specific timezone
	// offset: 2 try and error - 2009,1 is FEBRUARY!
	
	var countdown_time=Date.UTC(2009,1,9,-2);
	// get the current time and convert to milliseconds
	var now=new Date();
	var now_millisecs=now.valueOf();	
	var day_cnt= Math.ceil(( countdown_time - now_millisecs)/86400000 );
	return day_cnt;	
} 
 
 
 function create_icon(icon)
 {
	return ' <img src="fileadmin/KNTB/layout/img/'+icon+'.gif" class="link-icon" />';
 }
 
 $.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

 
 $(document).ready(function(){	
							
		// preload css hover images
	$.preloadImages('fileadmin/KNTB/layout/img/presse_hover.jpg', 'fileadmin/KNTB/layout/img/termine_hover.jpg',
	'fileadmin/KNTB/layout/img/unterschreiben_hover.jpg', 'fileadmin/KNTB/layout/img/close.gif', 'fileadmin/KNTB/layout/img/close_hover.gif', 'fileadmin/KNTB/layout/img/close_active.gif');						
							

		// show thickbox popUp Layer - width special windows like close button						
	if($('#popupcontent').length == 1 ){		
		
		tb_show('', '#TB_inline?height=450&width=400&inlineId=popupcontent&modal=true', '');
		
		$('#TB_window:has(div.TB_modal)').addClass('TB_window_modal');
								
		var close_button = '<a class="aclose" title="Infofenster schließen"></a>';
		//b970 - b977
		$('#TB_ajaxContent.TB_modal h2').append(close_button);			 
		$('#TB_ajaxContent.TB_modal p:last').append(' <a class="aclose" title="Infofenster schließen">mehr...</a>');				
		
		 $('#TB_ajaxContent.TB_modal a.aclose').click(tb_remove).click(function() {
				$('#popupcontent').hide();
		 });
	}	
	
	
		//zebra table
	$("tr:odd").addClass("odd");
	// $("td:nth-child(1)").addClass("td1");	
	$("td:first-child").addClass("td1");  	
	//
	$('table.result tr td:last-child').addClass("tdlast");
	$('table.result tr:last').addClass("trlast");
	
	/*								
	var day = countdown();
	if (day > 7) {
		$('#b970 #content h2').append(' <br />Das Volksbegehren läuft noch '+day+' Tage.');
	}
	else if (day == 7) {
		$('#b970 #content h2').append(' <br />Das Volksbegehren läuft noch eine Woche.');
	}
	else if(day > 1 && day < 7) {
		$('#b970 #content h2').append(' <br />Das Volksbegehren läuft nur noch '+day+' Tage.');
	}
	else if (day == 1) {
		$('#b970 #content h2').append(' <br />Das Volksbegehren läuft noch heute und morgen.');
	}
	else if (day == 0) {
		$('#b970 #content h2').append(' LETZTE CHANCE - das Volksbegehren endet heute.');
	}
	else  {
		$('#b970 #content h2').hide();
	}
	
	// alert ('Tag: '+day);
    */
							

	
	$("a:has(img)").addClass("img");
	$("a[href^='javascript:linkTo_UnCryptMailto']").addClass("email");
	$("a[href^='javascript:linkTo_UnCryptMailto']").attr("title","E-Mail");	
	
	$("div.tx-kntbmeld-pi1-listrow a").attr("title","Adresse und Öffnungszeiten anzeigen");
	
		// link icons: because of the IE multiline problem do not use css classes
	$("a[href$='.rtf']").append(create_icon('doc'));
	$("a[href$='.doc']").append(create_icon('doc'));
	$("a[href*='.pdf'], a[href*=':PDF']").append(create_icon('pdf'));		
	
	// INERNAL LINK
	if($("div.tx-kntbmeld-pi1-listrow").length == 0 && $("body#b975").length == 0 )
	{
		$("#content a[href*='/']").not("[href^=http]").not("[href^=index.php?eID]").not("[href^=#]").not("[class='email']").not("[href$='.pdf']").not("[href$='.doc']").not("[id^='c']").not("[class*='img']").prepend("» ");
	}
	
	 // EXTERNAL LINK		
	$("a[href^='http']").not("[class='img']").not("[class='noicon']").not("[href*='.pdf'], [href*=':PDF']").each(function(){	
		// external link with » at the begining looks like an internal link.				
		if($(this).html().indexOf('»') == -1){
			 $(this).append(create_icon('link_extern'));		   
		}
	});

	
	// if there follows a , or a . or a ) the link, img will get class link-icon2, so it gets a nicer padding
    // IE has it's own html() 
	$("p a img.link-icon").parents('p').each(function(){
		// alert($(this).html());
        var expr = /link-icon([^>]*)><\/a>([,\.\)]{1})/gi;
		var repl = 'link-icon2$1></a>$2';
		$(this).html($(this).html().replace(expr,repl));	
	});	
	
	// alert($("a[href^='http']:not('GMP')").html());	
	
	// open external links with target _blank	
	$("a[href^='http']").attr('target','_blank');
	$(".search_result a[href^=http]").attr('target','_self');	
	
	
	
	$(".ortstreffer").each(function(){
		// alert($(this).html());
		var text = $(this).html().replace(/\n/gi,'<br />');
		text = text.replace(/Zuständig für:<br( \/)?><br( \/)?>/gi, 'Zuständig für:<br />');
		$(this).html(text);	
	});	


	$(".showhidecontent").hide(); 	

	var showhideLinkTitle = 'Text anzeigen';	
	var showhideLinkStart = '<a href="#" class="showhide" title="'+showhideLinkTitle+'" onfocus="this.blur();">';
	var showhideLinkEnd = ' <span>[&raquo; mehr]</span></a>';
	
	$(".showhidecontentwrap h4").each(function(){
			$(this).html(showhideLinkStart + $(this).html() + showhideLinkEnd);			  
	});		
	$(".showhidecontentwrap h4 a").click(function(){
		$(this).parents("h4").next("div").toggle();		
		 if ($(this).attr("title") == 'Text anzeigen')
		 {
		   $(this).parents("h4").addClass('show');
		   $(this).attr("title","Text ausblenden");
		   $(this).children("span").html("[&raquo; ausblenden]");
		 } 
	    else
		 {
		   $(this).attr("title","Text anzeigen");
		   $(this).children("span").html("[&raquo; mehr]");
		   $(this).parents("h4").removeAttr('class');
		 }
		 return false;
	});
		
});