$(document).ready(function()
{
	// in order to support ie6
	$("li:last-child").addClass("lastChild");
	$("li:first-child").addClass("firstChild");
	$(".infiniteCarousel").infiniteCarousel();
	
	$("a[rel]").overlay();
	
    /**
     * Slider
     */
	$(".coda-slider").codaSlider();
	
	$(".tab.inactive").hide();
	
	$(".tabButton.inactive").children(".tabButtonBorder").css("visibility", "hidden");
	
	$(".tabButton.active a").addClass("active");
	
	$(".tabButton a").click(function(event)
	{
		event.preventDefault();
		
		var className = $(this).text().replace(" ","").replace(" ","");
		
		if ($(".tab."+className).css("display") != "block")
		{
			$(".tab").hide();
			$(".tabButtonBorder").css("visibility", "hidden");
			$(".tabButton .active").removeClass("active");
			
			$(".tab."+className).show();
			$("."+className+" .tabButtonBorder").css("visibility","visible");
			$("."+className+".tabButton a").addClass("active")
		}
	});
	
	
	
	/**
	 * Slider Tab Navigation
	 */
	$(".sliderEntryArrow a").click(function(event)
	{
		event.preventDefault();
		
		// right arrow should result in a movement into the opposite direction
		if ($(this).parent().hasClass("arrowRight"))
		{
			var addClassToItem=$(".tab:not(:hidden) .coda-nav ul li:not(.invisible):first");
			var removeClassFromItem=$(".tab:not(:hidden) .coda-nav ul li:not(.invisible):last").next();
			if(removeClassFromItem.length){
				addClassToItem.addClass("invisible");
				removeClassFromItem.removeClass("invisible")
			}
		}else{
			if(!$(".tab:not(:hidden) .tab1").hasClass("invisible")){
				return
			}
			var addClassToItem=$(".tab:not(:hidden) .coda-nav ul li:not(.invisible):last");
			var removeClassFromItem=$(".tab:not(:hidden) .coda-nav ul li:not(.invisible):first").prev();
			addClassToItem.addClass("invisible");
			removeClassFromItem.removeClass("invisible")
		}
	});
	
	
	
	/**
     * Slider Tab Navigation
     */
    $('.sliderEntryArrow a').click(function(event)
    {
        event.preventDefault();
        // left arrow movement ist default:
        var addClassToItem      = 'last';
        var removeClassFromItem = 'first';

        // right arrow sould result in a movement into the opposite direction
        if ($(this).parent().hasClass('arrowRight'))
        {
            addClassToItem      = 'first';
            removeClassFromItem = 'last';
        }

        $('.tab:not(:hidden) .coda-nav ul li:not(.invisible):'+addClassToItem).addClass('invisible');
        $('.tab:not(:hidden) .coda-nav ul li.invisible:'+removeClassFromItem).removeClass('invisible');
       
    });

     /**
      * faqs:
      */

    $('.question').click(function(event)
    {
        event.preventDefault();

        var answer = $(this).next().next();
        /*
        if (answer.css('display') == 'block')
        {
            answer.slideUp('fast');
        }
        else
        {
            $('.answer').slideUp('fast');
            answer.slideToggle('fast');
        }
        */
       $('.answer').each(function()
       {
           $(this).hide();
       })
       answer.toggle();
    });


    /**
     * carousels
     */
    $('.infiniteCarousel ul li a img').hover(
    function()
    {
        // over
        $(this).attr('src', $(this).attr('src').replace('.jpg', '_omo.jpg'));
    },
    function()
    {
        // out
        $(this).attr('src', $(this).attr('src').replace('_omo.jpg', '.jpg'));
    });
	
    $('a.readon.arrow.question.right').click(function(event)
    {
        resizeWidgetMedium();
    });
    resizeWidgetMedium();
});

function resizeWidgetMedium()
{
    if ($('.frontpage').length > 0)
    {
        return;
    }
    if ($('.widgetMedium').length > 0)
        {
            // height of press submenu is just widgetMedium height (left side widget)
            // less the height of the lower right box
    	
    		// left widget
            var leftHeight = $('.widgetMedium .boxBody').height() + $('.widgetMedium h1').height();
            
            // lower right small widget
            var lowerRightBoxHeight = 0;
            if ($('.boxGreen').length > 0)
            {
            	// is a green box
            	lowerRightBoxHeight = $('.boxGreen').height() + 15;
            } else {
            	// is a white box
            	lowerRightBoxHeight = $('.widgetSmall .box').last().height() + 23;
            }
            
            // upper right widget small size must be calculated
            var upperRightWidgetSmallHeight = leftHeight - lowerRightBoxHeight;
            
            if ($('#rightBoxSubmenu').length > 0)
            {
            	// small widget with submenu
            	upperRightWidgetSmallHeight = upperRightWidgetSmallHeight + 11;
            }
            $('.widgetSmall .boxBody').first().height(upperRightWidgetSmallHeight);
        }
}
