$(document).ready(function(){

	jQuery('.menuitem').hover(function(){
		var length = jQuery(this).children('ul').children('li').length;
		if (length!=0)
		jQuery(this).children('ul').stop(true,true).fadeIn(400);
	}, function(){
		jQuery(this).children('ul').stop(true,true).fadeOut(400);
	});
	
	function position(){
		var contTop = (jQuery('.refe_content').height() / 2) + 0;
		var contLeft = (jQuery('.refe_content').width() / 2) + 30;
		
		jQuery('.refe_content').css({
			'margin-top': '-' + contTop + 'px',
			'margin-left': '-' + contLeft + 'px'
		});
		jQuery('.refe_overlay').fadeIn('slow');
		jQuery('.refe_content').animate({
			'top': '50%'
		}, 1500);
	}
	
	jQuery('.refe_hover, .start_presse, .start_aktuell, .latest_news_item').click(function(){
		if ((jQuery('.refe_hover').length) || (jQuery('.start_presse').length)){
			if (jQuery(this).children('.page').length) {
				var link = jQuery(this).children('.page').html();
				location.href=link;
			}
			else {
				var inhalt = jQuery(this).prev('.refe_details').html();
				var width  = jQuery(this).prev('.refe_details').width()+30;
				var bildgröße = jQuery(this).prev('.tx-pagephpcontent-pi1-refe_image').css('width');
				var bodyheight = jQuery('body').height();
				jQuery('body').append('<div class="refe_overlay" style="height:' + bodyheight + 'px"></div><div class="refe_content" style="width:'+width+'px;"><div class="refe_close" title="Fenster schließen (ESC)"><img class="refe_x" src="fileadmin/images/close.png" titel="Detailansicht schließen" border="0"></div><div class="refe_innercontent"></div></div>');
				jQuery('.refe_innercontent').append(inhalt);
				setTimeout(position,500);
				var bilder = jQuery('.refe_innercontent').find('img');
				var bildnr = jQuery(bilder).length;
				if (bildnr>1)
					jQuery(bilder[0]).css('display','none');
			} 
		}
	});

	/*var chec = $('#jfmulticontent_c8').children('.ui-tabs-nav').children('li')[3];
	$(chec).css({backgroundColor: '#005DA8'}).css({"paddingLeft":"15px"}).css({width:'75px'}).children('a').css({color:'#FFF'});*/
	
	/*jQuery('.cat').click(function(){
			var bodyheight = jQuery('body').height();
			jQuery('body').append('<div class="cat_overlay" style="height:'+bodyheight+'px"><div class="cat_content"></div><div class="refe_close" title="Fenster schließen (ESC)"><img class="refe_x" src="fileadmin/images/close.png" titel="Detailansicht schließen" border="0"></div></div>');
			jQuery.get('fileadmin/flashcat/Default.html', function(data) {
				console.log(data);
  				jQuery('.cat_content').html(data);
			});
			
			jQuery('.cat_overlay').fadeIn('slow');
	});*/
	jQuery('.cat').click(function(){
		window.open("fileadmin/flashcat/Default.html","child","");
	});
	
	jQuery('.refe_overlay').live('click',function(){
		jQuery('.refe_content').animate({
				'top':'150%'
		},800,function(){
			jQuery('.refe_content').css({
				'top':'-50%'});
		}); 
		jQuery('.refe_overlay').fadeOut('slow',function(){
			jQuery(this).remove();
			jQuery('.refe_content').remove();
		});
	});

	jQuery('.refe_close').live('click',function(){
		jQuery('.refe_content').animate({
				'top':'150%'
		},800,function(){
			jQuery('.refe_content').css({
				'top':'-50%'});
		}); 
		jQuery('.refe_overlay').fadeOut('slow',function(){
			jQuery('.refe_overlay').remove();
			jQuery('.refe_content').remove();
		});
	});
	
	window.onkeyup = function (event) {
	  if (event.keyCode == 27) {
	   	jQuery('.refe_content').animate({
				'top':'150%'
		},800,function(){
			jQuery('.refe_content').css({
				'top':'-50%'});
		}); 
		jQuery('.refe_overlay').fadeOut('slow',function(){
			jQuery('.refe_overlay').remove();
			jQuery('.refe_content').remove();
		});
	  }
	}

	var accitems = jQuery('.accordion').parent('.csc-default').find('h1');
	if (accitems.length>0){
		$(accitems).addClass('accordion_h1');
		$(accitems).click(function(){
			var acc = $(this).parents('.csc-default').find('.accordion');
			var hide= $(acc).css('display');
			if (hide=='none'){
				$('.accordion').slideUp();
				$(acc).slideDown();
			}else{
				$(acc).slideUp();
			}
		});
	}

	jQuery('.BildLinks').click(function(){
		var klasse = jQuery(this).attr('class').split(' ');	
		var id     = klasse[1];
		console.log(klasse);
		self.location.href='index.php?id='+id;
	});
	
	var id = location.search;
	var idraw = id.split('=');
	if (idraw[1]==2){
		if ($('.login_link').length)
		$('.login_link').css({'display':'block'});
	};
	
	/*jQuery('#gal2').click(function(e){
		var xPos = $(this).offset();
		console.log(xPos);
	})*/
	
	/*
    // letzte UL der Jeweiligen Box
    $('.mainSubNavBox').find('ul:last').addClass('last');

    $('.mainSubNavBox').css('position', 'absolute');
    $('.mainSubNavBox').hide();
    $('#mainUndermenueBox #mainNavBox #mainNav li a').click(function(e){
        e.preventDefault();
    });

    $('#mainUndermenueBox #mainNavBox #mainNav li a').mouseenter(function(e){
        if(!$.browser.msie){
            task = setTimeout(openMenu, 100, e, this);
        } else {
            openMenu(e, this);
        }
    });
    $('#mainUndermenueBox').mouseleave(function(e){
        clearTimeout(task);

        $('#mainUndermenueBox #mainNavBox #mainNav li').removeClass('active')

        $('#mainUndermenueBox #mainNavBox #mainNav .activetree').addClass('active');

        e.stopPropagation();
        //if($('#FoldoutMenues').height() >= 298){
        $('#FoldoutMenues').stop(true,true).fadeOut(500, function(){
            $('.mainSubNavBox').hide();
        });
    //}
    });
    
		
	/*var endcol = '#828282';
	jQuery('.desc').css({backgroundColor:'#000000',opacity:'0.5'});
	jQuery('.BildLinks').hover(function(){
		jQuery(this).children('.desc').stop(false,false).animate({ 
				   backgroundColor: endcol,
				   opacity:'1.0'
				}, '150');
	},function(){
		jQuery(this).children('.desc').css({backgroundColor:'#000000',opacity:'0.5'});
	})
	
	jQuery(".desc").each(function(){
			var bgstart = '#ffffff';
			var bgend = '#fff2cc';
			var transstart = 1;
			var transend = 1;
			var colrel = jQuery(this).attr('rel');
			if(colrel){
				colattr = colrel.split("-");
				splitstart = colattr[0].split(",");
				bgstart = splitstart[0];
				if(splitstart[1]){
					transstart = splitstart[1];
					jQuery(this).css({'opacity':transstart});
				}
				splitend = colattr[1].split(",");
				bgend = splitend[0];
				if(splitend[1]){
					transend = splitend[1];
				}
				jQuery(this).css({'background-color':bgstart});
			}
			jQuery('.desc').hover(function(){
				jQuery(this).stop().animate({ 
					backgroundColor: bgend,
					opacity: transend
				}, 'fast');
			},function(){
				jQuery(this).stop(false,true).animate({ 
					backgroundColor: bgstart,
					opacity: transstart
				}, 'slow');
			});
	});*/
});

