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

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


// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [] ;

if (window.location == 'http://www.tourhouse.com/Default.aspx?Idm=en-US' || window.location == 'http://tourhouse.com/Default.aspx?Idm=en-US') {
    photos = [ {
        "title": "Corporativo",
        "image": "../img/layout/fotocorp.jpg",
        "url": "",
        "firstline": "<span class=\"lng3\">TRAVEL MANAGEMENT TOUR HOUSE CORPORATIVO</span><br /><br /> <span class=\"lng4\"> Flexibility and accurately translated in corporate travel in comfort, economy and ease.</span>",
        "secondline": "",
        "href": "corporativo/default.aspx"
    }, {
        "title": "Eventos",
        "image": "../img/layout/fotoevent.jpg",
        "url": "",
        "firstline": "<span class=\"lng5\">FOR US, EVERY EVENT IS SPECIAL</span> <span class=\"lng6\"> We handle all the logistics and details of your event to make it a great happening. </span>",
        "secondline": "",
        "href": "eventos/default.aspx"
    }, {
        "title": "Incentivos",
        "image": "../img/layout/fotoini.jpg",
        "url": "",
        "firstline": "<span class=\"lng1\">INCENTIVE TRAVEL</span> <span class=\"lng2\"> Motivation and results in your promotion campaign.  <br />We create unique moments that stimulate and transform those who participate. </span>",
        "secondline": "",
        "href": "incentivos/default.aspx"
    }, {
        "title": "Lazer",
        "image": "../img/layout/fotolz.jpg",
        "url": "",
        "firstline": "<span class=\"lng7\">ENJOY THE SUMMER PACKAGES</span><br /><br /> <span class=\"lng8\"> The best offers with the lowest prices you find at <b>Tour House Lazer</b>. </span>",
        "secondline": "",
        "href": "lazer/default.aspx"
    }, {
        "title": "VIP House",
        "image": "../img/layout/fotovip.jpg",
        "url": "",
        "firstline": "<span class=\"lng9\">EXCLUSIVE SERVICE FOR TOP EXECUTIVES</span> <span class=\"lng10\"> Time saving, differentiation and confidentiality <br />are key factors in <b>VIP House</b> service for presidents and directors. </span>",
        "secondline": "",
        "href": "vip/default.aspx"
    }, {
        "title": "Institucional",
        "image": "../img/layout/fotoinif.jpg",
        "url": "",
        "firstline": "",
        "secondline": "",
        "href": "institucional/default.aspx"
    }
];
}
else if (window.location == 'http://www.tourhouse.com/Default.aspx?Idm=es-ES' || window.location == 'http://tourhouse.com/Default.aspx?Idm=es-ES') {
    photos = [ {
        "title": "Corporativo",
        "image": "../img/layout/fotocorp.jpg",
        "url": "",
        "firstline": "<span class=\"lng3\">GESTI&Oacute;N DE VIAJES TOUR HOUSE CORPORATIVO</span><br /><br /> <span class=\"lng4\"> Flexibilidad y precisi&oacute;n en los viajes corporativos traducidos en comodidad, econom&iacute;a y tranquilidad. </span>",
        "secondline": "",
        "href": "corporativo/default.aspx"

    }, {
        "title": "Eventos",
        "image": "../img/layout/fotoevent.jpg",
        "url": "",
        "firstline": "<span class=\"lng5\">PARA NOSOTROS, CADA EVENTO ES ESPECIAL</span> <span class=\"lng6\">Cuidamos de toda la log&iacute;stica y detalles de su evento para convertirlo en un gran acontecimiento.</span>",
        "secondline": "",
        "href": "eventos/default.aspx"
    }, {
        "title": "Incentivos",
        "image": "../img/layout/fotoini.jpg",
        "url": "",
        "firstline": "<span class=\"lng1\">VIAJES DE INCENTIVO</span> <span class=\"lng2\"> Motivaci&oacute;n y resultado en su campa&ntilde;a de incentivo.<br />Creamos momentos &uacute;nicos, que estimulan y transforman al que participa.</span>",
        "secondline": "",
        "href": "incentivos/default.aspx"
    }, {
        "title": "Lazer",
        "image": "../img/layout/fotolz.jpg",
        "url": "",
        "firstline": "<span class=\"lng7\">DISFRUTE LOS PAQUETES DE VERANO</span><br /><br /> <span class=\"lng8\"> Las mejores ofertas con los menores precios usted encuentra en <b>Tour House Lazer</b>. </span>",
        "secondline": "",
        "href": "lazer/default.aspx"
    }, {
        "title": "VIP House",
        "image": "../img/layout/fotovip.jpg",
        "url": "",
        "firstline": "<span class=\"lng9\">ATENCI&Oacute;N EXCLUSIVA PARA ALTOS EJECUTIVOS</span> <span class=\"lng10\"> Econom&iacute;a de tiempo, diferenciaci&oacute;n y sigilo <br />son factores esenciales del <b>VIP House</b> en la atenci&oacute;n a presidentes y directores. </span>",
        "secondline": "",
        "href": "vip/default.aspx"
    },
    {
        "title": "Institucional",
        "image": "../img/layout/fotoinif.jpg",
        "url": "",
        "firstline": "",
        "secondline": "",
        "href": "institucional/default.aspx"
    }
];
}

else {
    photos = [{
        "title": "Corporativo",
        "image": "../img/layout/fotocorp.jpg",
        "url": "",
        "firstline": "<span class=\"lng3\">GEST&Atilde;O DE VIAGENS TOUR HOUSE CORPORATIVO</span><br /><br /> <span class=\"lng4\"> Flexibilidade e precis&atilde;o nas viagens corporativas traduzidas em conforto, economia e tranquilidade. </span>",
        "secondline": "",
        "href": "corporativo/default.aspx"

    }, {
        "title": "Eventos",
        "image": "../img/layout/fotoevent.jpg",
        "url": "",
        "firstline": "<span class=\"lng5\">PARA N&Oacute;S, CADA EVENTO &Eacute; ESPECIAL</span> <span class=\"lng6\"> Cuidamos de toda a log&iacute;stica e detalhes<br /> do seu evento para torn&aacute;-lo um grande acontecimento. </span>",
        "secondline": "",
        "href": "eventos/default.aspx"
    }, {
        "title": "Incentivos",
        "image": "../img/layout/fotoini.jpg",
        "url": "",
        "firstline": "<span class=\"lng1\">VIAGENS DE INCENTIVO</span> <span class=\"lng2\"> Motiva&ccedil;&atilde;o e resultado em sua campanha de incentivo. <br />Criamos momentos &uacute;nicos, que estimulam e transformam quem participa. </span>",
        "secondline": "",
        "href": "incentivos/default.aspx"
    }, {
        "title": "Lazer",
        "image": "../img/layout/fotolz.jpg",
        "url": "",
        "firstline": "<span class=\"lng7\">APROVEITE OS PACOTES DE VER&Atilde;O</span><br /><br /> <span class=\"lng8\"> As melhores ofertas com os menores pre&ccedil;os voc&ecirc; encontra na <b>Tour House Lazer</b>. </span>",
        "secondline": "",
        "href": "lazer/default.aspx"
    }, {
        "title": "VIP House",
        "image": "../img/layout/fotovip.jpg",
        "url": "",
        "firstline": "<span class=\"lng9\">ATENDIMENTO EXCLUSIVO PARA ALTOS EXECUTIVOS</span> <span class=\"lng10\"> Economia de tempo, diferencia&ccedil;&atilde;o e sigilo <br />s&atilde;o fatores essenciais do <b>VIP House</b> no atendimento de presidentes e diretores. </span>",
        "secondline": "",
        "href": "vip/default.aspx"
    }, {
        "title": "Institucional",
        "image": "../img/layout/fotoinif.jpg",
        "url": "",
        "firstline": "",
        "secondline": "",
        "href": "institucional/default.aspx"
    }
];
}


$(document).ready(function () {

    // Backwards navigation
    $("#back").click(function () {
        stopAnimation();
        navigate("back");
    });

    // Forward navigation
    $("#next").click(function () {
        stopAnimation();
        navigate("next");
    });

    //
    //$(".cl1").mouseover(function () {
    //    stopAnimation();    
    //    $("#header").html("<div id='headerimg1' class='headerimg' style='background:url(img/layout/fotoinif.jpg) no-repeat top center;'></div>");
    //});

    //$(".cl2").mouseover(function () {
    //    stopAnimation();
    //    $("#header").html("<div id='headerimg2' class='headerimg' style='background:url(img/layout/fotocorp.jpg) no-repeat top center;'><div id='hdcorp' style='display: block; '><span class=\"lng3\">GEST&Atilde;O DE VIAGENS TOUR HOUSE CORPORATIVO</span><br /><br /> <span class=\"lng4\"> Flexibilidade e precis&atilde;o nas viagens corporativas traduzidas em conforto, economia e tranquilidade. </span></div></div>");
    //});

    //$(".cl3").mouseover(function () {
    //    stopAnimation();
    //    $("#header").html("<div id='headerimg3' class='headerimg' style='background:url(img/layout/fotoevent.jpg) no-repeat top center;'><div id='hdhv' style='display: block; '><span class=\"lng5\">PARA N&Oacute;S, CADA EVENTO &Eacute; ESPECIAL</span><br /><br /><span class=\"lng6\"> Cuidamos de toda a log&iacute;stica e detalhes<br /> do seu evento para torn&aacute;-lo um grande acontecimento. </span></div></div>");
    //});

    //$(".cl4").mouseover(function () {
    //    stopAnimation();
    //    $("#header").html("<div id='headerimg4' class='headerimg' style='background:url(img/layout/fotoini.jpg) no-repeat top center;'><div id='hdhv' style='display: block; '><span class=\"lng1\">VIAGENS DE INCENTIVO</span><br /><br /><span class=\"lng2\"> Motiva&ccedil;&atilde;o e resultado em sua campanha de incentivo. <br />Criamos momentos &uacute;nicos, que estimulam e transformam quem participa. </span></div></div>");
    //});

    //$(".cl5").mouseover(function () {
    //    stopAnimation();
    //    $("#header").html("<div id='headerimg5' class='headerimg' style='background:url(img/layout/fotolz.jpg) no-repeat top center;'><div id='hdhv' style='display: block; '><span class=\"lng7\">APROVEITE OS PACOTES DE VER&Atilde;O</span><br /><br /> <span class=\"lng8\"> As melhores ofertas com os menores pre&ccedil;os voc&ecirc; encontra na Tour House Lazer. </span></div></div>");
    //});

    //$(".cl6").mouseover(function () {
    //    stopAnimation();
    //    $("#header").html("<div id='headerimg6' class='headerimg' style='background:url(img/layout/fotovip.jpg) no-repeat top center;'><div id='hdhv' style='display: block; '><span class=\"lng9\">ATENDIMENTO EXCLUSIVO PARA ALTOS EXECUTIVOS</span><br /><br /><span class=\"lng10\"> Economia de tempo, diferencia&ccedil;&atilde;o e sigilo <br />s&atilde;o fatores essenciais do VIP House no atendimento de presidentes e diretores. </span></div></div>");
    //});


    var interval;
    $("#control").toggle(function () {
        stopAnimation();
    }, function () {
        // Change the background image to "pause"
        $(this).css({ "background-image": "url(images/btn_pause.png)" });

        // Show the next image
        navigate("next");

        // Start playing the animation
        interval = setInterval(function () {
            navigate("next");
        }, slideshowSpeed);
    });


    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;

        // 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(images/" + photoObject.image + ")",
            "display": "block",
            "z-index": currentZindex
        });

        click = document.getElementById('lnkbnn');
        click.onclick = new Function('window.location ="' + photoObject.href + '"');

        // Hide the header text
        $("#headertxt").css({ "display": "none" });

        // Set the new header text
        $("#firstline").html(photoObject.firstline);
        $("#secondline")
			.attr("href", photoObject.url)
			.html(photoObject.secondline);
        $("#pictureduri")
			.attr("href", photoObject.url)
			.html(photoObject.title);


        // Fade out the current container
        // and display the header text when animation is complete
        $("#headerimg" + currentContainer).fadeOut(function () {
            setTimeout(function () {
                $("#headertxt").css({ "display": "block" });
                animating = false;
            }, 500);
        });
    };

    var stopAnimation = function () {
        // Change the background image to "play"
        $("#control").css({ "background-image": "url(images/btn_play.png)" });

        // Clear the interval
        clearInterval(interval);
    };

    // We should statically set the first image
    navigate("next");

    // Start playing the animation
    interval = setInterval(function () {
        navigate("next");
    }, slideshowSpeed);

});
