$(document).ready(function() {
  
    // Mainmenu
    $('li[id*="mm-item"]').hover(
	function() {
	    if($(this).attr('class').search(/active/) == -1) {
		$(this).children().stop()
		.animate({
		    'color':'#93589b'
		}, 500, 'easeOutCubic');
	    }
	},
	function() {
	    if($(this).attr('class').search(/active/) == -1) {
		$(this).children().stop()
		.animate({
		    'color':'#414141'
		}, 500, 'easeOutCubic');
	    }
	});

    // Submenu
    $('li[id*="sm-item"]').hover(
	function() {
	    if($(this).attr('class').search(/active/) == -1) {
		$(this).children().stop()
		.animate({
		    'color':'#93589b'
		}, 800, 'easeOutCubic');
	  		
	    }
	},
	function() {
	    if($(this).attr('class').search(/active/) == -1) {
		$(this).children().stop()
		.animate({
		    'color':'#414141'
		}, 800, 'easeOutCubic');
	    }
	});

    // Metamenu
    $('li[id*="am-item"]').hover(
	function() {
	    if($(this).attr('class').search(/active/) == -1) {
		$(this).stop()
	    //.animate({'paddingLeft':'15px','backgroundPosition':'4px 7px'}, 800, 'easeOutCubic')
	    //.children('a').stop().animate({'color':'#9e1622'}, 500);
	    }
	},
	function() {
	    if($(this).attr('class').search(/active/) == -1) {
		$(this).stop()
	    //.animate({'paddingLeft':'0px','backgroundPosition':'-11px 7px'}, 800, 'easeOutCubic')
	    //.children('a').stop().animate({'color':'#999'}, 500);
	    }
	});

    if($('#core_logout').length == 0)
    {
	$('.slideshow').show();
	if($.browser.msie && $.browser.version=="6.0")
	{
	    Galleria.loadTheme('core_base/js/src/themes/classic_ie6/galleria.classic.js');
	}else{
	    Galleria.loadTheme('core_base/js/src/themes/classic/galleria.classic.js');
	}
	
	$('.slideview').galleria({
	    height: 600,
	    autoplay: 7000,
	    preload: 1,
	    image_crop: true,
	    image_position: 'center',
	    on_image: function(image, thumbnail) {
		alert("image");
	    }
	});
    }

    $('#arrow_up').css('visibility','hidden');

    $('#arrow_down').click(function() {
	var divOffset = $('#sidecontent').offset().top;
	var pOffset = 600;
	var pScroll = pOffset - divOffset;
	$('#sidecontent').animate({
	    scrollTop: '+=' + pScroll + 'px'
	}, 800, 'easeOutCubic', checkButton);
    });

    $('#arrow_up').click(function() {
	var divOffset = $('#sidecontent').offset().top;
	var pOffset = 120;
	var pScroll = pOffset - divOffset;
	$('#sidecontent').animate({
	    scrollTop: '+=' + pScroll + 'px'
	}, 800, 'easeOutCubic', checkButton);
    });

    if($('.slideview_port').length > 0 )
    {
	$('.slideview_port').galleria({
	    height: 791,
	    autoplay: 7000,
	    preload: 1,
	    keep_source: true,
	    image_crop: false,
	    extend: function(options) {
		$('.galleria-stage').hide();
		if($.browser.msie && $.browser.version=="8.0")
		{
		    $('.galleria-container').css('marginTop','-156px');
		}else{
		    $('.galleria-container').css('marginTop','-181px');
		}
	    }
	});
		
	$('.galleria-image').live('click', function() {
	    $('.galleria-stage').show();
	    $('#column-22').css('visibility','hidden');
	});
    }

    function checkButton()
    {
	if(($('#sidecontent').children().height()-290)*(-1) >= $('#sidecontent').children().position().top) $('#arrow_down').css('visibility','hidden'); else $('#arrow_down').css('visibility','visible');
	if(10 <= $('#sidecontent').children().position().top) $('#arrow_up').css('visibility','hidden'); else $('#arrow_up').css('visibility','visible');
    }

    if($('#sidecontent').children('div').height() < 300)
    {
	$('#arrow_down').css('visibility','hidden');
	$('#arrow_up').css('visibility','hidden');
    }
	
    $('.item-body img').each(function() {
	$(this).wrap('<a href="'+$(this).attr('src')+'"></a>');
    });

    $('#column-22 a').lightBox();
	
    window.setTimeout("$('.slideview').fadeIn(500)", 750);

    $('#core-login-name').live('click', function() {
	if($(this).val() == 'Benutzername') $(this).val('');
    });

    $('#core-login-pass').live('click', function() {
	if($(this).val() == 'Passwort') $(this).val('');
    });

	/*if($.browser.msie && $.browser.version=="6.0")
	{*/
		$('.galleria-images').children('div').each(function() {
			$(this).children('img').attr('style','width:20%');
		});
	/*}*/
	
});
