jQuery.fn.extend( {
	setKasten : function() {
        var h = '';
        var w = '';
		if ($.browser.msie) {
			h = document.documentElement.clientHeight;
			w = document.documentElement.clientWidth;
		} else {
			h = window.innerHeight;
			w = window.innerWidth;
		}
		return this.css( {
			height : h,
			width : w
		});
	}
});

jQuery(function($) {
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo,
	 * check it's demo for an example of each option.
	 * 
	 * @see http://flesler.demos.com/jquery/scrollTo/ You can use EVERY single
	 *      setting of jQuery.ScrollTo, in the settings hash you send to
	 *      jQuery.LocalScroll.
	 */

	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	$.localScroll.defaults.axis = 'xy';

	// Scroll initially if there's a hash (#something) in the url
	$.localScroll.hash( {
		target : '.innercontent', // Could be a selector or a jQuery object
		queue : true,
		duration : 1500,
		onBefore: function(e, anchor, $target){
			if($(anchor).attr('id') != 'p3'){
				$('.startseite').removeClass('startseite');
			}
			$('a[href="#'+ $(anchor).attr('id') + '"]').addClass('active');
			
		}
	});
    
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to
	 * scroll.
	 */
	$.localScroll( {
		target : '.innercontent', // could be a selector or a jQuery object
									// too.
		queue : true,
		duration : 2000,
		hash : true,
		onBefore : function(e, anchor, $target) {
			if($(anchor).attr('id') != 'p3'){
				$('.startseite').removeClass('startseite');
			}
			
			$('.eineseite').css('overflow', 'hidden');
			
		},
		onAfter : function(anchor, settings) {
			$('.eineseite').css('overflow', 'auto');

            var menuList =  $('a[href="#'+ $(anchor).attr('id') + '"]').parents('ul');

            switch($(menuList).attr('class')){
                case 'hauptnav':
                case 'sysnav':
                        $('.active').removeClass('active');
                    break;
                case 'unternav':
                        $('.sysnav').find('.active').removeClass('active');
                        $('.unternav').find('.active').removeClass('active');
                    break;
            }

            $('a[href="#'+ $(anchor).attr('id') + '"]').addClass('active');
            
			if($(anchor).attr('id') == 'p3'){
				if(!$('body').hasClass('startseite')){
					$('body').addClass('startseite');
				}
			}
		}
	});
});

$(document).ready(function() {
	
	if(!$.browser.msie || parseInt($.browser.version.substr(0,1)) >= 8){
		$('h1').css({
			color: '#195DA4',
			textTransform: 'uppercase'
		});
		Cufon.replace('h1');
	}
	
	$('.news-latest-container').find('a').click(function(){
		$.get($(this).attr('href'), function(data){
			$.modal(data, {
				containerCss:{
					width:800,
					height:400
				},
				overlayClose:true
			})
		});
		return false; 
	});
	
	
	
	$('#newssearch')
		.submit(function(){
			$.post($(this).attr('action'), $(this).serializeArray(), function(data){
				$('.news-search-emptyMsg').html($(data)[2]);
			});
			return false; 
		})
		.find('input[type="submit"]').click(function(){
			$(this).parent().submit();
			return false; 
		});
		
	//MS: Anfahrt auch in einer Kiste oeffnen:
	$('.anfahrtsskizze').find('a').click(function(){
		$.get($(this).attr('href'), function(data){
			$.modal(data, {
				containerCss:{
					width:800,
					height:"auto"
				},
				overlayClose:true
			})		
		});
		return false; 
	});
		
		
	$('.internal-link').click(function(){

		$.get($(this).attr('href'), {modal: '1'}, function(data){
			$.modal(data, {
				containerCss:{
					width:800,
					height:"auto",
					minHeight: 450
				},
				overlayClose:true
			})

		});

		return false;
		
	})

	$('#mailform').live('submit', function(){

		$.get($(this).attr('action'), {modal: '1'}, function(data){
			$.modal(data, {
				containerCss:{
					width:800,
					height:"auto",
					minHeight: 450
				},
				overlayClose:true
			})
		});

		return false;
	})
		
});