/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var Slideshow = {

    init: function (){
        var i = 0;
        jQuery('#startslideshow ul#cnt li').each(function(){
            if(i == 0){
                jQuery(this).fadeIn('slow');
                Slideshow.current = jQuery(this);
            }
            i++;
        });
        
        this.count = i;
        this.createNavigation();
        this.start();

    },

    createNavigation: function(){
       var response = '<ul id="startslideshow-nav">';
       var index = 1;
       jQuery('#startslideshow ul#cnt li').each(function(){

           response += '<li class="'+((index == 1)?'first first-active':'')+' '+((index == jQuery('#startslideshow ul#cnt li').length)?'last':'')+'">'+(index)+'</li>';
           index++;
       });
        response += '</ul>';

        jQuery('#startslideshow').append(response);

        jQuery('#startslideshow-nav li').each(function(){
            jQuery(this).click(function(){
                clearInterval(Slideshow.timer);
                var index = jQuery(this).html();
                Slideshow.current.fadeOut('slow');
                
                Slideshow.setNaviItem(jQuery('#startslideshow-nav li:eq('+jQuery('#startslideshow ul#cnt li').index(Slideshow.current)+')'), 'remove');
                Slideshow.setNaviItem(jQuery(this), 'add');

                jQuery('#startslideshow ul#cnt li:eq('+(index -1 )+')').fadeIn('slow');
                Slideshow.current = jQuery('#startslideshow ul#cnt li:eq('+(index -1 )+')');


            });
        });

    },

    setNaviItem: function (item, state){
        if(item.hasClass('first')){
            if(state == 'add'){
                item.addClass('first-active');
            }else{
                item.removeClass('first-active');
            }
        }else if(item.hasClass('last')){
             if(state == 'add'){
                item.addClass('last-active');
             }else{
                 item.removeClass('last-active');
             }
        }else{
            if(state == 'add'){
                item.addClass('active');
            }else{
                item.removeClass('active');
            }
        }
    },

    start: function (){
        Slideshow.timer = setInterval ( "Slideshow.next()", 10000 );
    },

    next: function(){
        if(jQuery('#startslideshow ul#cnt li').index(Slideshow.current.next()) != -1){
            Slideshow.current.next().fadeIn('slow');
            Slideshow.current.fadeOut('slow');
            Slideshow.setNaviItem(jQuery('#startslideshow-nav li:eq('+jQuery('#startslideshow ul#cnt li').index(Slideshow.current)+')'), 'remove');
            Slideshow.current = jQuery(Slideshow.current).next();
            Slideshow.setNaviItem(jQuery('#startslideshow-nav li:eq('+jQuery('#startslideshow ul#cnt li').index(Slideshow.current)+')'), 'add');
        }else{
            Slideshow.current.fadeOut('slow');
            Slideshow.setNaviItem(jQuery('#startslideshow-nav li:eq('+jQuery('#startslideshow ul#cnt li').index(Slideshow.current)+')'), 'remove');
            jQuery('#startslideshow ul#cnt li').first().fadeIn('slow');
            Slideshow.current = jQuery('#startslideshow ul#cnt li').first();
            jQuery('#startslideshow-nav li:eq('+jQuery('#startslideshow ul#cnt li').index(Slideshow.current)+')').addClass('active');
            Slideshow.setNaviItem(jQuery('#startslideshow-nav li:eq('+jQuery('#startslideshow ul#cnt li').index(Slideshow.current)+')'), 'add');
        }
    }

}

var FastAccess = {

    init:function(){
        jQuery('#fastaccess ul li').each(function(){

            bg_image_url = jQuery(this).find('span.fastaccess_element_bg_image img').attr("src");
            if(bg_image_url){
                jQuery(this).css('background', 'url('+bg_image_url+ ')');
            }

            jQuery(this).find('h4').click(function(){

                //console.log(FastAccess.current.get(0));
                //console.log(jQuery(this).parent().get(0));

                // Aktion soll nicht ausgeführt werden, wenn der offene Tab geklickt wird
                if(FastAccess.current.get(0) === jQuery(this).parent().get(0)){
                    //alert('derselbe');
                    
                }else{

                    //
                    // Weiter wie gehabt
                    //

                    // aktuell ausgeklappten verkleinern
                    if(FastAccess.current) {
                        FastAccess.current.animate({height:35},
                          function() {
                              jQuery(this).find('h4').css('background', 'white');
                          }
                        );

                        FastAccess.current.find('a').css('display', 'none');
                        FastAccess.current.find('p').css('display', 'none');

                        FastAccess.current.find('h4').css('color', '#666');
                        
                        // nicht animiert
                        /*FastAccess.current.find('h4').css('background', 'white');*/

                        // animiert
                        /*FastAccess.current.find('h4').animate({
                            backgroundColor: 'white'
                          }, 3000, function() {
                            // Animation complete.
                          });*/

                    }

                    // geklickten vergrößern
                    FastAccess.current = jQuery(this).parent();
                    FastAccess.current.animate({height:150});
                    FastAccess.current.find('a').css('display', 'block');
                    FastAccess.current.find('p').css('display', 'block');

                    FastAccess.current.find('h4').css('background', 'none');
                    FastAccess.current.find('h4').css('color', '#FF9907');


                }

          
            });

            // verlinkung
            jQuery(this).find('p').click(function(){
                if(FastAccess.current.find('a').attr('href') == ""){
                    //alert('leer');
                }else{
                    window.location = FastAccess.current.find('a').attr('href');
                }

            });

            // Mouseover-Hand bei fehlenden Links ausblenden
            if(jQuery(this).find('a').attr('href') == ""){
               jQuery(this).find('p').css('cursor', 'default');
            }
            
        });

        // erstes Element zu Beginn öffnen
        jQuery('#fastaccess ul li h4:first').css('background', 'none');
        jQuery('#fastaccess ul li h4:first').css('color', '#FF9907');


        this.current = jQuery('#fastaccess ul li:eq(0)');
        jQuery('#fastaccess ul li:eq(0)').css('height', 150);
        FastAccess.current.find('a').css('display', 'block');
        FastAccess.current.find('p').css('display', 'block');
    }

}


jQuery(document).ready(function(){

        if(jQuery('#startslideshow ul#cnt li').length > 0){
            Slideshow.init();
            FastAccess.init();
        }
       

});

function show_font_resize_info() {
    var info_div = document.getElementById('font_resize_info');
    var vis = info_div.style;
    // if the style.display value is blank we try to figure it out here
    if(vis.display == '' && info_div.offsetWidth != undefined && info_div.offsetHeight != undefined)
        vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
    vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
}



    


