$(function(){	
	$("li.suche a").click(function(event){
		$("li.suche").append('<form method="post" action="96-Suchausgabe.html" id="inline-suche" style="margin-left: -3px"><input id="suche" class="text" type="text" name="rexsearch" /><input type="submit" value="Suche" /></form>');
		event.preventDefault();
		$("#inline-suche #suche").focus();
		$("#inline-suche #suche").blur(function(){
			$("#inline-suche").remove();
		});
	});
	
	$('#navigation_left a').each(function() {
		var ul = $(this).next();
		if (ul.length > 0) {
			if (ul.css('display') == 'block') {
				var toggle = '<span class="open toggles"></span>';
			} else {
				var toggle = '<span class="close toggles"></span>';
			}
			$(this).after(toggle);
		}
	});
	$('#navigation_left a').mouseover(function() {
		var span = $(this).next();
		var ul = $(this).next().next();
		if (ul.length > 0) {
			t = setTimeout(function(){
				ul.slideDown('fast');
				span.removeClass('close').addClass('open');
			}, 600);
		}
	});
	$('#navigation_left a').mouseout(function(){
		clearTimeout(t);
	});
	$('#navigation_left .close, #navigation_left .open').live('click', function(event){
		event.preventDefault();
		if ($(this).hasClass('close')) {
			$(this).removeClass('close').addClass('open');
		} else {
			$(this).removeClass('open').addClass('close');
		}
		$(this).next().slideToggle('fast');
	});	
	$('#navigation_left .closeAll').click(function(){
		$('#navigation_left ul.rex-navi2, #navigation_left ul.rex-navi3').slideUp();
		$('#navigation_left span.toggles').removeClass('open').addClass('close');
	});
	
	$('#navigation_left .lev1 > a:contains("Referenzen")').each(function(){
		$(this).parent().css({
			'margin-top': '40px',
			'border-color': '#aaa'
		}).nextAll().css('border-color', '#aaa');
	});
	
	$('.beschreibungsbox').mouseenter(function(){
		var id = '#' + $(this).attr('id');
		$(id + '_beschreibung').show();
	});	
	$('.beschreibungsbox').mouseleave(function(){
		var id = '#' + $(this).attr('id');
		$(id + '_beschreibung').hide();
	});	
	
	$('#center_content').hover(
	function() {
		$('.description',this).fadeIn(150);
	},
	function() {
		$('.description',this).fadeOut(150);
	});
	
	$('.tabs').tabs();
	$('.thickbox').fancybox({
		'padding'		:	0,
		'titlePosition' :	'inside'
	});
	$('#video_cookie').live('click', function(e) {
		e.preventDefault();
		days = $(this).attr('time');
		$.ajax({
			type	:	"POST",
			data	:	"what=video_cookie&days="+days,
			url		:	"ajax.php",
			success	:	function(src){
				if (src == 'true') {
					$('#video_cookie').replaceWith('Das Video wird Ihnen ab sofort nicht mehr angezeigt!');
				} else {
					alert('Der Cookie konnte leider nicht gesetzt werden.');
				}
			}
		});
	});
	
	$('abbr').hover(
		function(){
			var offset = $(this).offset();
			left = offset.left - 15;
			top = offset.top - 45;
			title = $(this).attr('title');
			$(this).attr('title','');
			$(this).after('<div class="abbr_title" style="left:'+left+'px;top:'+top+'px;">'+title+'<div class="description_arrow"></div></div>');
		},
		function(){
			$(this).attr('title',title);
			$(this).next('.abbr_title').remove();
		}
	);
	
	$('.material .more_info').click(function(){
		var parent = $(this).parent().parent();
		$('.bottom_box, .long_description', parent).slideToggle();
		$('.material .small_images img:first').click();
	});
	$('.material .small_images img').hover(function(){
		filename = $(this).attr('filename');
		resize = 'index.php?rex_resize=250a__';
		
		id = $(this).parent().attr('id');
		id = id.split('_');
		
		old_image = $('#big_image_'+id[2]+' img').attr('src');
		
		$('#big_image_'+id[2]+' img').attr('src', resize+filename);
	}, function() {
		actual_href = $('#big_image_'+id[2]+' a').attr('href');
		if (actual_href != '/files/'+filename) {
			$('#big_image_'+id[2]+' img').attr('src', old_image);
		}
	});
	$('.material .small_images img').click(function(){
		var filename = $(this).attr('filename');
		var resize = 'index.php?rex_resize=250a__';
		
		var id = $(this).parent().attr('id');
		id = id.split('_');
		
		$('#big_image_'+id[2]+' a').attr('href', '/files/'+filename);
		$('#big_image_'+id[2]+' img').attr('src', resize+filename);
	});
	$('.material .big_image a').jqzoom({
		zoomWidth: 250,
		zoomHeight: 250,
		title: false,
		xOffset: 21,
		yOffset: -1,
		showPreload: false
	});
});