/*

	function library

*/

jQuery.noConflict();



var time_visible = 13000;
var time_duration = 3000;

//onload = startAnimation;
//onunload = stopAnimation;
function changeAnimation(){
        
    //eyecatcher part
    var activeEyecatcher = jQuery('#movie div.current');
    var nextEyecatcher = (jQuery('#movie div.current').next().length > 0) ? jQuery('#movie div.current').next() : jQuery('#movie div:first');
   
    activeEyecatcher.fadeOut(function(){
    activeEyecatcher.removeClass('current');
    nextEyecatcher.fadeIn().addClass('current');
    });
    //link part
    var activeLnk = jQuery('#pagenav a.active');
    var nextLnk = (jQuery('#pagenav a.active').next().length > 0) ? jQuery('#pagenav a.active').next() : jQuery('#pagenav a:first');
   
    activeLnk.removeClass('active');
    nextLnk.addClass('active');
    
    startAnimation();
}
function startAnimation(){
    
    if(!jQuery('#pagenav a').hasClass('active')){
        jQuery('#pagenav a:first').addClass('active');
    }
    if(!jQuery('#movie div').hasClass('current')){
        jQuery('#movie div:first').addClass('current');
        jQuery('#movie div:not(:first)').hide();
    }
    setTimeout("changeAnimation()",time_visible);
}

// zeigt den ausgewählten eyecatcher
function getEyecatcher(el){
    jQuery('#movie div.eyecatcher').hide();
    jQuery('#movie div.eyecatcher:eq('+(el)+')').fadeIn();
    
    //classen anpassen
    jQuery('#movie div.eyecatcher.current').removeClass('current');
    jQuery('#movie div.eyecatcher:eq('+(el)+')').addClass('current');
    jQuery('#pagenav a.active').removeClass('active');
    jQuery('#pagenav a:eq('+(el)+')').addClass('active');
    
    // animation stoppen
    time_visible = 999999999;
}
jQuery(document).ready(function(){
    
    //linsk generieren, jenachdem wieviele eyecatcher da sind
    for(var i = 0; i < jQuery('div.eyecatcher').length;i++){
        var lnkClass = "";
        if(i == 0){lnkClass = "first active";}
        jQuery('<a href="javascript:;" class="'+lnkClass+'" onclick="getEyecatcher('+i+')">0'+(i+1)+'</a>').appendTo('#pagenav');
    }
    
    // Animation starten, wenn es mehr als 1 eyecatcher gibt
    if(jQuery('div.eyecatcher').length > 1){
        startAnimation();
    }
    
   // alert('startseite');
});
