jQuery.noConflict();
jQuery(document).ready(function() {
	jQuery('#background_image').fullscreenr({
		width: 1280,
		height: 800,
		bgID: '#background_image',
	});
    
    jQuery('.mod_newslist .more,.mod_newsarchive .more').click(function(){
        jQuery('.layout_latest').not(jQuery(this).parent('.layout_latest')).each(function() {
            jQuery(this).children('.teaser').slideUp();
            jQuery(this).children('.more').html('weiterlesen &raquo;').fadeIn();
        });
        jQuery(this).parent().children('.teaser').slideToggle('slow');
        if(jQuery(this).html() == 'x schließen'){
            jQuery(this).html('weiterlesen &raquo;');
        }
        else {
            jQuery(this).html('x schließen');
        }

    });

    jQuery(".runway_point").hover(function(){
        jQuery("#km0").next('.tooltip_content').fadeOut();
        jQuery(this).css('cursor','pointer');
        jQuery(this).animate({
            width: '50px',
            height: '45px',
            opacity: '0.8',
            paddingTop: '+=5px'
        },300);
        jQuery(this).css('border','5px dotted #9D003C');
    },function(){
        jQuery(this).css('border','none');
        jQuery(this).animate({
            width: '40px',
            height: '40px',
            opacity: '1.0',
            paddingTop: '-=5px'
        },300);
    });
    
    jQuery(".img_partner").tooltip({
        tipClass: 'tooltip_content',
        offset: [-10, 8],
        relative: true
    });
    
    jQuery(".runway_point").tooltip({
        tipClass: 'tooltip_content',
        offset: [-10, 8],
        relative: true
    });
    jQuery("#watch_bg_list li img").hover(function(){
    	jQuery(this).attr('src','/tl_files/mockenhaupt/img/watch_bg_white_hover.png');
        jQuery("#realBody").fadeOut();
    },
    function(){
    	jQuery(this).attr('src','/tl_files/mockenhaupt/img/watch_bg_white.png');
        jQuery("#realBody").fadeIn();
    });
    
    jQuery("#km0").next('.tooltip_content').fadeIn();
    
    jQuery("a[rel*=lightbox]").fancybox();
    
    jQuery("#new_comment_link").click(function(){
        
        jQuery('.form').slideDown('slow');
        jQuery("#new_comment_link").slideUp('slow');
    });

    //jCarousel Plugin
    jQuery('#carousel').jcarousel({
        vertical: true, //display vertical carousel
        scroll: 1,  //auto scroll
        auto: 0,    //the speed of scrolling
        size: Math.ceil(jQuery('#carousel li').size()/3),
        wrap: 'last',   //go back to top when reach last item
        initCallback: mycarousel_initCallback   //extra called back function
    });
 
    //Front page Carousel - Initial Setup
    //set all the item to full opacity
    jQuery('div#slideshow-carousel a img').css({'opacity': '0.5'});
     
    //readjust the first item to 50% opacity
    jQuery('div#slideshow-carousel a img:first').css({'opacity': '1.0'});
     
    //append the arrow to the first item
    jQuery('div#slideshow-carousel li a:first').append('<span class="arrow"></span>')
 
  
    //Add hover and click event to each of the item in the carousel
    jQuery('div#slideshow-carousel li a').hover(
        function () {
             
            //check to make sure the item is not selected
            if (!jQuery(this).has('span').length) {
                //reset all the item's opacity to 50%
                jQuery('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '0.5'});
                 
                //adust the current selected item to full opacity
                jQuery(this).stop(true, true).children('img').css({'opacity': '1.0'});
            }      
        },
        function () {
                 
            //on mouse out, reset all the item back to 50% opacity
            jQuery('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '0.5'});
             
            //reactivate the selected item by loop through them and look for the one
            //that has the span arrow
            jQuery('div#slideshow-carousel li a').each(function () {
                //found the span and reset the opacity back to full opacity
                if (jQuery(this).has('span').length) jQuery(this).children('img').css({'opacity': '1.0'});
 
            });
                 
        }
    ).click(function () {
 
        //remove the span.arrow
        jQuery('span.arrow').remove();
         
        //append it to the current item       
        jQuery(this).append('<span class="arrow"></span>');
         
        //remove the active class from the slideshow main
        jQuery('div#slideshow-main li').removeClass('active');
         
        //display the main image by appending active class to it.       
        jQuery('div#slideshow-main li.' + jQuery(this).attr('rel')).addClass('active');  
             
        return false;
    });



    
});

function mycarousel_initCallback(carousel) {
    
    // Pause autoscrolling if the user moves with the cursor over the clip.
    // resume otherwise
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}
