/////////////////////////
/* GENERAL FUNCTIONS   */
/////////////////////////
slideShow = function(timeOut){
	
   var $activeImage;
   var $nextImage;
   var $activeNav;
   var $nextNav;
     
	play = setInterval(function() {

	   	$activeImage =  $('#images img.active');
	   	$activeNav = $('#slideshowNavigation a.active');
	   	
	   	$nextImage =  $activeImage.next(); 	
	   	$nextNav =  $activeNav.next();
	   	
	   	if ( $nextImage.length === 0) { //If paging reaches the end...
            $nextImage = $('#images img:first'); //go back to first
        }
	   
	   	if ( $nextNav.length === 0) { //If paging reaches the end...
            $nextNav = $('#slideshowNavigation a:first'); //go back to first
        }
	   
	   
	   	$activeImage.fadeOut().removeClass('active');
	   	$nextImage.fadeIn().addClass('active');
	   
	   	$activeNav.removeClass('active');
		$nextNav.addClass('active');

 	}, timeOut || 3000);
  
};


/////////////////////////
/* DOM-READY           */
/////////////////////////

$(function() {

    //HIDE ALL THAT SHOULD BE HIDDEN
	//$(".hidden").hide();

    // External Links Wrapper for Valid XHTML
    $('a[rel*=external]').live("click", function(event) {
		window.open(this.href);
		return false;
	});



	// open and close content of boxes
	$("a.jobShowDetails").click(function(event) {

	    event.preventDefault();
		$(this).prev("div.jobDetails").slideToggle('slow');

		var htmlStr = $(this).html();
      
      	if (htmlStr == 'mehr') {
      		$(this).text('minimieren');
      	} else {
      		$(this).text('mehr');
      	}
      
	});


	// open and close content of boxes
	$("a.projectShowDetails").click(function(event) {
		
	    event.preventDefault();
		$(this).prev("div.projectDetails").slideToggle('slow');

		var htmlStr = $(this).html();
      
      	if (htmlStr == 'mehr') {
      		$(this).text('minimieren');
      	} else {
      		$(this).text('mehr');
      	}
      
	});


















	//Slideshow
	$('#images img:gt(0)').hide();
		
	//Show the paging and activate its first link
	$("#slideshowNavigation").delay(500).fadeIn('slow');
	$("#slideshowNavigation a:first").addClass("active");
	$("#images img:first").addClass("active");
	
	slideShow(5000);
	
	$("#slideshowNavigation a").click(function() {
		
		clearInterval(play); //Stop the slideshow
		
		//FadeOut current Image and Pager
		$activeImage =  $('#images img.active');
	   	$activeNav = $('#slideshowNavigation a.active');
	   	$activeImage.fadeOut().removeClass('active');
	   	$activeNav.removeClass('active');

		//Get index    
	    var indexNr = $(this).index();
	    	    
	    $nextImage =  $("#images img").eq(indexNr);
	   	$nextNav =  $("#slideshowNavigation a").eq(indexNr);
	    
	    $nextImage.fadeIn().addClass('active');
		$nextNav.addClass('active');
		
	    //Start Slideshow
	   	slideShow(5000);
	    return false; //Prevent browser jump to link anchor
	});
	
	

});


