// Select Menu oben rechts
function Spring() {
    var welcherLink = document.Springen.URLs.selectedIndex;
    document.Springen.URLs.selectedIndex = "0";
    if(welcherLink > "0"){
        top.location.href = document.Springen.URLs.options[welcherLink].value;
    }
}
// Dropdown-Menu...
$(document).ready(function(){
    $("#link li").hover(
        function(){
            $("ul", this).fadeIn("fast");
        },
        function() { }
        );
    if (document.all) {
        $("#link li").hoverClass ("sfHover");
    }
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover(
            function() {
                $(this).addClass(c);
            },
            function() {
                $(this).removeClass(c);
            }
            );
    });
};

// Slider-Funktion when the DOM is ready...

$(document).ready(function () {
    jQuery(window).hashchange(function()
    {
        // location hash has been updated
        // ...
        trigger({
            id : window.location.hash.substr(1)
        });
    });
    var $panels = $('#slider .scrollContainer > div');
    var $container = $('#slider .scrollContainer');

    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = true;
    // float the panels left if we're going horizontal
    if (horizontal) {
        $panels.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
        // calculate a new width for the container (so it holds all panels)
        $container.css('width', $panels[0].offsetWidth * $panels.length);
    }

    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll = $('#slider .scroll').css('overflow', 'hidden');

    // apply our left + right buttons
         
    $scroll
    .before('<div id="left"><img class="scrollButtons left" id="left" onmouseover="this.src=\'/dms/templating-kit/themes/eMag/img/btn_prevA.gif\'"onmouseout="this.src=\'/dms/templating-kit/themes/eMag/img/btn_prevA.gif\'" src="/dms/templating-kit/themes/eMag/img/btn_prevA.gif" alt="prev" /></div>')
    .after('<div id="right"><img class="scrollButtons right" id="right" onmouseover="this.src=\'/dms/templating-kit/themes/eMag/img/btn_nextA.gif\'" onmouseout="this.src=\'/dms/templating-kit/themes/eMag/img/btn_nextA.gif\'" src="/dms/templating-kit/themes/eMag/img/btn_nextA.gif" alt="next" /></div>');

    // handle nav selection
    function selectNav() {        
        $(this)
        .parents('ul:first')
        .find('a')
        .removeClass('selected')
        .end()
        .end()
        .addClass('selected');
        if (
            $(this).hasClass("empty")) {
            $("img.left").hide();
            $("img.right").show();
        }
        else if (
            $(this).hasClass("last") )
            {
            $("img.left").show();
            $("img.right").hide();
                
        }
        else {
            $("img.left").show();
            $("img.right").show();
        }
    }
    function selectFooterNav(element) {
        $(element)
        .parents('ul:first')
        .find('li')
        .removeClass('aktiv')
        .end()
        .end()
        .addClass('aktiv');
    }
    $('#slider .navigation').find('a').click(selectNav);
    // go find the navigation link that has this target and select the nav
    function trigger(data) {

        window.location.hash = '#' + data.id;  //PerS: add curent hash to url

        //PerS: show the "active" video
        // $("#" + data.id + ".").show();

        var prefixId = data.id;
        var idnew = "nav-" + prefixId.split("-")[0];
        var id_footer_nav = "li-tooltip-" + prefixId.split("-")[0];
        var el = $('#slider .navigation').find('a[id$="' + idnew + '"]').get(0);
        var el2 = $('#footer #'+id_footer_nav).get(0);
		
        selectNav.call(el);
        selectFooterNav(el2);

    //PerS: dynamic change/fit height to content
    // TAG:auskommentiert - da keine resize H�he!! var sc = $("#" + data.id).get(0);
    //$('.scroll').animate({height: Math.max(sc.scrollHeight, sc.clientHeight)});
    // TAG:auskommentiert - da keine resize H�he!! $('.scroll').height(Math.max(sc.scrollHeight, sc.clientHeight));
    }

    if (window.location.hash) {
        trigger({
            id : window.location.hash.substr(1)
        });
    } else {
        $('ul.navigation a:first').click();
    }

    // offset is used to move to *exactly* the right place, since I'm using
    // padding on my example, I need to subtract the amount of padding to
    // the offset.  Try removing this to get a good idea of the effect
    var offset = parseInt((horizontal ? 
        $container.css('paddingTop') : 
        $container.css('paddingLeft')) 
    || 0) * -1;


    var scrollOptions = {
        target: $scroll, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels,

        navigation: '.navigation a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left', 
        next: 'img.right',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback


        offset: offset,

        // duration of the sliding effect
        duration: 500,


        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };

    // apply serialScroll to the slider - we chose this plugin because it 
    // supports// the indexed next and previous scroll along with hooking 
    // in to our navigation.
    $('#slider').serialScroll(scrollOptions);
    // now apply localScroll to hook any other arbitrary links to trigger
    // the effect
    $.localScroll(scrollOptions);
    scrollOptions.duration = 1;
    $.localScroll.hash(scrollOptions);
    function manageControls(position){
        // Hide left arrow if position is first slide
        if(position==0){
            $('#before').hide()
        } else{
            $('#before').show()
        }
        // Hide right arrow if position is last slide
        if(position==numberOfSlides-7){
            $('#after').hide()
        } else{
            $('#after').show()
        }
    }
});
