$(document).ready(function() {
	// jQuery SmoothScroll
    $('a[href*=#]').click(function(){
    
        // duration in ms
        var duration = 1500;
        
        // easing values: swing | linear
        var easing = 'swing';
        
        // make sure it's the same location      
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname && this.hash.replace(/#/, '')) {
            // get parameters
            var hash = this.hash;
            var target = $(hash).offset().top;
            
            // animate to target and set the hash to the window.location after the animation
            $("html:not(:animated),body:not(:animated)").animate({
                scrollTop: target
            }, duration, easing, function(){
                location.hash = hash;
            });
            
            // cancel default click action
            return false;
        }
    });
	
	/*
	 * Social Bookmarks
	 */
	$('.social-bookmarks img').each(function(){
		$(this).css({opacity: 0.6})
		.bind("mouseenter", function(){
			$(this).stop().animate({
	            opacity: '1'
	        }, 'fast');
		})
		.bind("mouseleave", function(){
			$(this).stop().animate({
	            opacity: '0.6'
	        }, 'fast');
		});
	})
	
	/*
	 * Menupunkte
	 */
	$('#col3_content li img').each(function(){
		var $imageHeight = $(this).height();
		if($imageHeight > 23) {
			$(this).parent().parent().height(40);
		}
		else {
			$(this).parent().parent().height(20);
		}
	})
	
	/*
	 * Teaserfce
	 */
    if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	    
    }
    else {
        $('div.teaserfce div.picture').each(function(){
            var $picture = $(this);
            var $imageHeight = $(this).height();
            
            //alert($imageHeight);
            $picture.parent().parent().parent().parent().find('div.subcl').height($imageHeight);
            $picture.parent().parent().parent().parent().parent().find('div.more').css({'position' : 'absolute', 'bottom' : '0', 'width' : '100%'});
            //alert($imageHeight);
        })    
    }
	
    
    var $fceheight = $('div.newsfce').height();
    $('div.newsfce').height(70);

    function newsfce_hoverover(){
        //alert('Over');
        $('div.newsfce').stop().animate({opacity: '+=0'}, 1000).animate({height:($fceheight-8)}, 'slow'); 
        
    };
    function newsfce_hoverout(){
        //alert('Out');
        //$('div.newsfce').stop().animate({height:(70)}, 'slow');      
    };

    $('div.newsfce').hoverIntent({
        sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
        interval: 50, // number = milliseconds for onMouseOver polling interval
        over: newsfce_hoverover, // function = onMouseOver callback (required)
        timeout: 1500, // number = milliseconds delay before onMouseOut
        out: newsfce_hoverout // function = onMouseOut callback (required)
    });

    
    $("#selectnone").click(function(event){
        var checked_status = this.checked;
        $("input[type='checkbox']").each(function()
        {
            this.checked = "";
        });
        return false;
    });
    
    $("#selectall").click(function(event){
        var checked_status = this.checked;
        $("input[type='checkbox']").each(function()
        {
            this.checked = "checked";
        });
        return false;
    });
    

    if ( $("#defaultPopupDatepicker").length > 0 ) {
        //alert('Test!');
        $("#defaultPopupDatepicker").datepick({showOnFocus: true, minDate: 0, onClose: function(value, date) { $('#dateText').text( 
        $.datepick.formatDate('DD, d. MM yy', date)); }, showStatus: true, dateFormat: 'dd.mm.yy', yearRange: '2009:2011', changeMonth: false, changeYear: false, navigationAsDateFormat: true, prevText: '< M', currentText: 'M y', nextText: 'M >',closeAtTop: false, showAnim: 'fadeIn', buttonImageOnly: true, buttonImage: 'fileadmin/templates/img/icons/calendar.gif'});  
    }
    
    $('#defaultPopupDatepicker').focus(function () {
      if($(this).attr('value') == 'TT.MM.JJJJ')
      {
         $(this).attr('value', '');
    }
    }).blur(function () {
        if($(this).attr('value') == 'TT.MM.JJJJ' || $(this).attr('value') == '')
         $(this).attr('value', 'TT.MM.JJJJ');
    });
    
    $('input.filtersubmit').click(function () { 
        if($('#defaultPopupDatepicker').attr('value') == 'TT.MM.JJJJ')
        {
            $('#defaultPopupDatepicker').attr('value','');
        } 
    });

	// Add pdf icons to pdf links
	$("a[href$='.pdf']").addClass("pdf");
 
	// Add txt icons to document links (doc, rtf, txt)
	$("a[href$='.doc'], a[href$='.txt'], a[href$='.rft']").addClass("txt");
    
    
    /* Microsite Slider */
    if($('.slidecontainer').length > 0) {
        $('.slidecontainer').each(function(){
            var self = this;
            var slidecontainer = $(this);
            
            //slidecontainer.;
            console.debug($(this));    
        });        
    }
    
    
    /* User Agent (Browserkennung) auf einen bestimmten Browsertyp prüfen */  
   function checkBrowserName(name){  
        agent = navigator.userAgent.toLowerCase();  
        if (agent.indexOf(name.toLowerCase())>-1) {  
            return true;  
        }  
        return false;  
   }  
    
	
});

