var currentPic = 1;
var maxPics = 0;

$(document).ready(function(){
	
	$(".featured_text").each(function(){
		$(this).find("p").each(function(){
			$(this).replaceWith("<h3>"+$(this).html()+"<h3>");
		});
		$(this).find("h2").each(function(){
			$(this).replaceWith("<h3>"+$(this).html()+"<h3>");
		});
	});
	
	$(".box").wrap('<div class="box_head" />');
	$(".box").wrap('<div class="box_bottom" />');

	if($("#submenu").length == 0)
		{
			$("#menu_big #mainmenu").css({"padding-top": "40px"});
		}

	$("#mainmenu ul:first").prepend('<li style="width: 68px; height: 26px; padding: 0px; background-image: url(tl_files/images/menu_left.png);">&nbsp;</li>');

	if($("#submenu").is('*'))
	{
		$("#content").css({"border-top": "1px solid #0099d5"});
	}

	
	$("img").each(function(){
		var a = $(this).attr('src');
		if(a.substring(0,7) != "http://")
			a = "http://seilstattgeruest.de/"+a;
			
		$(this).attr('src', a);
	});
		
	maxPics = $(".imagecontainer").children("img").size();
	$(".projectdescription .text").jScrollPane({scrollbarWidth: 7});
	
	$(".event:last").css({"border-bottom": "none"});
	$(".single_col:last").css({"padding-right": "0px"});
	$(".project_list_item:last").css({"border-bottom": "none"});
	
	$(".event img").each(function(){
		var oldwidth = $(this).width();
		$(this).css({width: 162+"px", height: $(this).height()*(162/oldwidth) +"px"});
	});
	
	$(".project_list_item").mouseover(function(){
		$(".popup").hide();
		$(this).find(".popup").show();
	});
	
	$(".project_list_item").mouseout(function(){
		$(".popup").hide();
		$(this).find(".popup").hide();
	});
	
	$(".project_list_item").mousemove(function(e){
		
		var xp, yp = -100;
		if (navigator.appName.indexOf("Internet Explorer") != -1)
			{
				yp = 0;
			}		
		$(this).find(".popup").css({"top": $(this).offset().top-$(this).height()/2+yp+"px", "left": "50%", "margin-left": "337px"});
	});
	
	$(".project_detailed .infolist").css({"position": "relative", "top": 230-$(".project_detailed .infolist").height()+"px"});
	
	// Bilder in der Feature-Box mittig positionieren
//	$(".featured_image").css({top: -$(".featured_image").height()/2+208/2+"px", left: -$(".featured_image").width()/2+875/2+"px"})
	$(".featured_container").hide();
	fade_content();
	
	showImage(1);	
	
	if($(".featured").html())
	{
		var faderInterval = setInterval(fade_content, 7000);	
	}	
	
	if(document.URL.indexOf("schulungen-sicherheit") == -1)
	{
		$(".row").hide();
	}
	
	Cufon.replace('h1', {hover: true}); // Works without a selector engine
	Cufon.replace('h2', {hover: true}); // Works without a selector engine
	Cufon.replace('.mod_navigation ul li', {hover: true}); // Requires a selector engine for IE 6-7, see above	
	Cufon.replace('.project_list_item a', {hover: true}); // Requires a selector engine for IE 6-7, see above	
});


function fade_content()
{	
	
	$('.featured_container:last').fadeOut(1000, function(){		
		$(this).remove();
		$(".featured").prepend($(this));
		$(".featured_container:first").hide();
		$('.featured_container:last').fadeIn(1000, function(){
		});
	});
	
}

function showImage(id)
{
	$(".projimg").hide();
	$(".projectimages a").css({color: "#bbbbbb"});
	$("#img_"+id).fadeIn("slow");
	$("#link_"+id).css({color: "#000000"});
	currentPic = id;
}

function showImageInc()
{
	if (currentPic < maxPics) {
  		currentPic++;
  		showImage(currentPic);
	}
}

function showImageDec()
{
	if (currentPic > 1) {
  	currentPic--;
  	showImage(currentPic);
  }
}
