/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/
// Speed of the automatic slideshow
var slideshowSpeed  = 15000;
var index           = 0;
var wdl             = window.document.location;
//var host          = 'http://' + wdl.host + '/' + wdl.pathname.split('/')[1] ;
var host            = 'http://' + wdl.host + '/' + wdl.pathname.split('/')[1] ;
//host               += '/site';

// alert(host);

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [ /*{
    "image" : "BG_FABASA.jpg"
}, */{
    "image" : "BG_familia_gramado_1.jpg"
    //"frase" : "Um amanhã muito melhor."
}, {
    "image" : "BG_familia_negra_1.jpg"
    //"frase" : "15 anos pensando no futuro."

}, {
    "image" : "BG_coroas_negros_1.jpg"
    //"frase" : "Invista em sua tranquilidade."
}
];

$(document).ready(function() {

    var activeContainer = 1;
    var currentImg = 0;
    var animating = false;
    var goTo = function(number) {
        // Check if no animation is running. If it is, prevent the action
        if(animating) {
            return;
        }
		
        currentImg = number;
		
        // Check which container we need to use
        var currentContainer = activeContainer;
        if(activeContainer == 1) {
            activeContainer = 2;
        } else {
            activeContainer = 1;
        }
		
        showImage(photos[currentImg], currentContainer, activeContainer);

        if(index == photos.length-1)
            index = 0;
        else
            index++;
		
    };
	
    var currentZindex = -1;
    var showImage = function(photoObject, currentContainer, activeContainer) {
        animating = true;
		
        // Make sure the new container is always on the background
        currentZindex--;
		
        // Set the background image of the new active container
        $("#headerimg" + activeContainer).css({
            "background-image" : "url("+host+"/wp-content/themes/simplixity/img/" + photoObject.image + ")",
            "display" : "block",
            "z-index" : currentZindex
        });

        // Hide the header text
        //$("#fraseheader").css({"display" : "none"});

        // Set the new header text
	//$("#fraseheader span").html(photoObject.frase);
		
        // Fade out the current container
        // and display the header text when animation is complete
        $("#headerimg" + currentContainer).fadeOut(5000, function() {
            setTimeout(function() {
                //$("#fraseheader").css({"display" : "block"});
                animating = false;
            }, 500);
        });
    };

    goTo(index);

    // Start playing the animation
    interval = setInterval(function() {
        goTo(index);
    }, slideshowSpeed);

        
});
