/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/

// Speed of the automatic slideshow
var slideshowSpeed = 10000;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [
	{
		"image" : "bg_01.jpg"
	},
	{
		"image" : "bg_02.jpg"
	},
	{
		"image" : "bg_03.jpg"
	},
	{
		"image" : "bg_04.jpg"
	},
	{
		"image" : "bg_05.jpg"
	},
	{
		"image" : "bg_06.jpg"
	},
	{
		"image" : "bg_07.jpg"
	}
];

jQuery.preloadImages = function() {
	$(arguments).each(function() {
		jQuery("<img/>").attr("src", this.image);
	});
};


$(document).ready(function() {

	$.preloadImages(photos);
	
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {
		// Check if no animation is running. If it is, prevent the action
		if(animating) {
			return;
		}
		
		// Check which current image we need to show
		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			}
		} else {
			currentImg--;
			if(currentImg == 0) {
				currentImg = photos.length;
			}
		}
		
		// Check which container we need to use
		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		
		showImage(photos[currentImg - 1], currentContainer, activeContainer);
		
	};
	
	var currentZindex = -1;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		
		// Set the background image of the new active container
		$("#headerimg" + activeContainer).css({
			"background-image" : "url(2011/img/" + photoObject.image + ")",
		}).fadeIn("normal");

		// Fade out the current container
		// and display the header text when animation is complete
		$("#headerimg" + currentContainer).fadeOut("normal", function() {
			animating = false;
		});
	};
	
	// We should statically set the first image
	navigate("next");
	
	// Start playing the animation
	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);
	
});

$(document).ready(function(){
    $('#tabs .planBox').hide();
    $('#tabs .planBox:first').show();
    var planlength = $('#tabs .planBox:first .plan').length > 3 ? $('#tabs .planBox:first .plan').length : 3;
    var h = planlength * 150;
    $('#tabs').css('height', (h + 10 + 18) + 'px');
    $('#tabs .planBox:first .planBoxbg').css('height', h + 'px');

    $('#tabs ul li:first').addClass('active');
    $('#tabs ul li a').click(function(){ 
        $('#tabs ul li').removeClass('active');
        $(this).parent().addClass('active'); 
        var currentTab = $(this).attr('href'); 
        $('#tabs .planBox').hide();
        $(currentTab).show();
        var planlength = $(currentTab).find('.plan').length > 3 ? $('#tabs .planBox:first .plan').length : 3;
        var h = planlength * 150;
        $(currentTab).find('.planBoxbg').css('height', h + 'px');
        $('#tabs').animate(
            {
                'height': (h + 10 + 18) + 'px'
            },
            1000,
            "linear",
            function() {}
        );
        return false;
    });
});
