// Global Vars

var tweetHolder = $('#twitterbox');
//var tweetBox = $('.tweet');
var tweetLength = 2;
var tweetHeight = '160';
var currentPosition = 0;

function slideTweets()
{
    if(currentPosition == tweetLength-1){
        currentPosition = 0;
    }
    else
    {
        currentPosition = currentPosition+1;    
    }
    $('.tweetstart').stop().animate({
        'marginTop': -tweetHeight*currentPosition
        
    }, 1000, 'swing')
    
//$('.firsttweet').css('margin-left', tweetHeight*currentPosition );
}    


$(document).ready(function(){
    

    
    setInterval("slideTweets()", 6000);
    
    // Menu Dropdown
    $('#menu li').each(function(){
        
        
        $(this).hover(function(){
            
            $('ul', this).slideDown('fast');
            
        }, function(){
            $('ul', this).css('display', 'none');
        });
        
        
    })
    
    var intervalSave = setInterval(function(){
        autoSlideImage();
        
        fmanageControls(fcurrentPosition);
        
    }, 10000);
        
    
    // Front Slideshow
    
    var fcurrentPosition = 0;
    var fslideWidth = 900;
    var fslides = $('.slide-holder');
    var fnumberOfSlides = fslides.length;
    
    
    function  fmanageControls(fposition){
        // position==0 is first slide
        if(fposition==0)  {
            $('#fleftControl').hide();
        }
        else {
            $('#fleftControl').show();
        }
        // numberOfSlides-1 is last slides
        if(fposition==fnumberOfSlides-1) {
            
            $('#frightControl').hide();
        }
        else {
            
            $('#frightControl').show();
        }
    }   
    
    fmanageControls(fcurrentPosition);    
    
    $('#front-slider-frame').css('width', fnumberOfSlides*fslideWidth);
    
    $('.control').live('click', function(e){
        e.preventDefault();
        clearInterval(intervalSave);
        intervalSave = setInterval(function(){
            autoSlideImage();
        
            fmanageControls(fcurrentPosition);
        
        }, 5000);
        
        if($(this).attr('id')=='frightControl'){
            
            fcurrentPosition = fcurrentPosition+1;
        } else {
            
            fcurrentPosition = fcurrentPosition-1;
        }
        
        fmanageControls(fcurrentPosition);
                
        $('#front-slider-frame').stop().animate({
            'marginLeft' : fslideWidth*(-fcurrentPosition)
        });   
        
    });
    
    function autoSlideImage(){
        
        if(fcurrentPosition == fnumberOfSlides-1){
            fcurrentPosition = 0
            
        } else {
            fcurrentPosition = fcurrentPosition+1  
            
        }
        
        $('#front-slider-frame').stop().animate({
            'marginLeft' : fslideWidth*(-fcurrentPosition)
        }, 1000, 'swing');
        
         
        
        
    }
    
    
    
    
    
   
    
    // Klanten Slideshow
    var currentPosition = 0;
    var slideWidth = 920;
    var slides = $('.slide-inner');
    var numberOfSlides = slides.length;
    
    function  manageControls(position){
        // position==0 is first slide
        if(position==0)  {
            $('#leftControl').hide();
        }
        else {
            $('#leftControl').show();
        }
        // numberOfSlides-1 is last slides
        if(position==numberOfSlides-1) {
            $('#rightControl').hide();
        }
        else {
            $('#rightControl').show();
        }
    }   
    
    manageControls(currentPosition);    
    
    $('.klanten-slide').css('width', numberOfSlides*slideWidth);
    
    $('.control').live('click', function(e){
        e.preventDefault();
        
        if($(this).attr('id')=='rightControl'){
            currentPosition = currentPosition+1;
        } else {
            currentPosition = currentPosition-1;
        }
        
        manageControls(currentPosition);
                
        $('.klanten-slide').animate({
            'marginLeft' : slideWidth*(-currentPosition)
        });       
    });
});
