$(document).ready( function() {
	// PNG FIX für IE6
	$(document).pngFix();

	// Link text conversion
	$("a[href*='we_object']").each(function() {
		var href = $(this).attr('href');
		var id = href.match(/\d+/);
		var text = $(this).text();
		var text = text.replace(/ /g,'-');
		var text = text.replace(/Ä/g,'Ae');
		var text = text.replace(/Ö/g,'Oe');
		var text = text.replace(/Ü/g,'Ue');
		var text = text.replace(/ä/g,'ae');
		var text = text.replace(/ö/g,'oe');
		var text = text.replace(/ü/g,'ue');
		var newHref = '/k/'+id+'/'+text;
		$(this).attr('href',newHref);
	});

	// Erste Hilfe Link Hilfe
	$("a[href^='/k/51/'], a[href^='/k/23/']").each( function () {
		var vHref = $(this).attr('href');
		var navID = $(this).attr('alt');
		var newHref = vHref+'?n='+navID;
		$(this).attr('href',newHref);
	});

	// Fancybox
	$("div > a[target='_blank'][href^='/']").fancybox({
		'showNavArrows'	:	true,
		'onStart'	:	function() {
			$('iframe').fadeOut(100);
		},
		'onClosed'	:	function() {
			$('iframe').fadeIn(100);
		}
	});

	//IMG ohne alt Text füllen
	$("img[alt='']").attr('alt','Kika - Travel Dog');


	//Slider für Kika Shots
	var newWidth = $('#galerieAuto > div').length;
	$('#galerieAuto').css('width',newWidth*250+'px')

	$("#boxGaleriePrev").click(function() {
		var container = $("#galerieAuto");
		var entry = $("div.galerieCropped:last");
		entry.css('margin-left','-250px');
		container.prepend(entry);
		container.find("div.galerieCropped:first").animate({marginLeft: '0px'},500);
	});

	$("#boxGalerieFwd").click(function() {
		var container = $("#galerieAuto");
		var entry = $("div.galerieCropped:first");
		entry.animate({marginLeft: '-250px'},500, function() {
			var cont = $(this);
			$(this).css('margin-left','0').remove();
			container.append(cont);
		});
	});


	// Inputfeld für Suche focus/unfocus
	var textInput = $('#search').val();
	$('#search').blur(function() {
		if($(this).val()=='') {
			$(this).val(textInput);
		}
	}).focus(function() {
		if($(this).val()==textInput) {
			$(this).val('');
		}
	});


	//Umwandlung bei Tagebucheinträgen
	if($("div.entry").length>0) {
		$('div.boxInnerLarge').removeClass('boxInnerLarge');
		$('#leftContent').css({'border':'0','background-color':'transparent'});
	}

	$('a.viewFranziska').fadeTo(1,0.4).find('img.entryViewCheck').hide();

	// View Switch bei tagebuch
	$('a.viewDog').click(function() {
		var container = $(this).parent().parent();
		if(container.find('div.cView_Franziska:visible').length>0) {
			container.find('div.cView_Franziska:visible').hide();
			container.find('div.cView_Beide:hidden').show();
			$(this).fadeTo(1,1);
			$(this).find('img.entryViewCheck').show();
		} else if(container.find('div.cView_Beide:visible').length>0) {
			container.find('div.cView_Beide:visible').hide();
			container.find('div.cView_Franziska:hidden').show();
			$(this).fadeTo(1,0.4);
			$(this).find('img.entryViewCheck').hide();
		}
	});

	$('a.viewFranziska').click(function() {
		var container = $(this).parent().parent();
		if(container.find('div.cView_Kika:visible').length>0) {
			container.find('div.cView_Kika:visible').hide();
			container.find('div.cView_Beide:hidden').show();
			$(this).fadeTo(1,1);
			$(this).find('img.entryViewCheck').show();
		} else if (container.find('div.cView_Beide:visible').length>0) {
			container.find('div.cView_Beide:visible').hide();
			container.find('div.cView_Kika:hidden').show();
			$(this).fadeTo(1,0.4);
			$(this).find('img.entryViewCheck').hide();
		}
	});


	//Tipps versenden container slideIn und schicken
	$('#imgTippsSenden').toggle(function() {
		$('#tippsContainer').animate({right:'0'});
	}, function() {
		$('#tippsContainer').animate({right:'-248px'});
	});

	$('#tippBeenden').click(function() {
		$('#tippsContainer').animate({right:'-248px'});
	});
	
	$("#closeTipp").live('click', function () {
		$('#tippsContainer').animate({right:'0'});
	});

	// LINKS umbauen welche nach außen gehen => _blank
	$("a[href^='http']").attr("target","_blank");
	
	
	// Letzter Beistrich weg
	$("p[alt='kategorien']").each(function() {
		$(this).find('span:last').remove();
	});

});


function contact(form) {
	var formData = $(form).serializeArray();
	$('#formTippsSenden').load('/_include/site/tipps.php', ({data: formData}));
}

