﻿// 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 = [{
    "title": "maintitle.png",
    "image": "ClinicMain.png",
    "url": "http://www.amenclinics.com/amenclinics/clinics/",
    "firstline": "OurPhilo.png",
    "secondline": "learnbtn.png",
    "btnTop": "180px",
    "btnLeft": "760px",
	"thirdline": "audit.png",
	"btnTopAudit": "125px",
	"btnLeftAudit": "760px"
}, {
    "title": "maintitle.png",
    "image": "mainStore1.png",
    "url": "http://store.amenclinics.com/",
    "firstline": "",
    "secondline": "storebtn.jpg",
    "btnTop": "190px",
    "btnLeft": "48px",
	"thirdline": "audit.png",
	"btnTopAudit": "125px",
	"btnLeftAudit": "760px"
},{
    "title": "comunitytitle.png",
    "image": "mainSol1.png",
    "url": "http://www.theamensolution.com/",
    "firstline": "",
    "secondline": "communitybtn.png",
    "btnTop" : "190px",
    "btnLeft" : "200px"
} 
];



$(document).ready(function () {
    var activeContainer = 1;
    var currentImg = 0;
    var animating = false;
    $("#thirdline").hide();
    $("#btn1").click(function() {
		stopAnimation();
		navigate("btn1");
	});
    
    $("#btn2").click(function() {
		stopAnimation();
		navigate("btn2");
	});
    
    $("#btn3").click(function() {
		stopAnimation();
		navigate("btn3");
	});
    
    $("#firstline").click(function() {
		gotoGetStart();
	});
    
    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 if (direction == "btn1") {
            currentImg = 1;
        }  else if (direction == "btn2") {
            currentImg = 2;
        }  else if (direction == "btn3") {
            currentImg = 3;
        } 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
        });

        // Hide the header text
        $("#headertxt").css({ "display": "none" });
        $("#thirdline").hide();

        // Set the new header text
        //$("#firstline").html(photoObject.firstline);
        
        //$("#firstline").removeAttr("style");
        $('#firstline').attr('style','');
        if(photoObject.secondline == "learnbtn.png") {
            $("#firstline").css({
                "background-image": "url(images/" + photoObject.firstline + ")",
                "display": "block",
                "z-index": 99
            });
            
             $("#secondline")
    			.attr("href", "http://theamensolution.com/home_new/get-started-my-brain-type/")
    			.css({
    			    "background-image": "url(images/" + photoObject.secondline + ")",
    			    "display": "block",
    			    "top": photoObject.btnTop,
    			    "left": photoObject.btnLeft,
    			    "z-index": 99
    			});
        } else {
           $("#secondline")
    			.attr("href", photoObject.url)
    			//.attr("href", "http://www.theamensolution.com/home_new/get-started-my-brain-type/")
				.css({
    			    "background-image": "url(images/" + photoObject.secondline + ")",
    			    "display": "block",
    			    "top": photoObject.btnTop,
    			    "left": photoObject.btnLeft,
    			    "z-index": 99
    			});
            $("#firstline")
    			.css({
    			    "background-image": "url(images/learnbtn.png)",
                    "background-repeat" : "no-repeat",
                    "position" : "relative",
                    "cursor" : "pointer",
    			    "display": "block",
    			    "top": "180px",
    			    "left": "760px",
                    "height": "50px",
    			    "z-index": 99
    			});
        }
		
		
//        $("#pictureduri")
//			.attr("href", photoObject.url)
//			.html(photoObject.title);
		$("#pictureduri").css({
		    "background-image": "url(images/" + photoObject.title + ")"
//		    "top": "304px",
//		    "left": "200px",
		});

        // Fade out the current container
        // and display the header text when animation is complete
        $("#headerimg" + currentContainer).fadeOut(function () {
            setTimeout(function () {
                $("#headertxt").css({ "display": "block" });

        		$("#thirdline")
        			.attr("href", "http://www.amenclinics.com/clinics/audit/")
        			.css({
        			    "background-image": "url(images/audit.png)",
        			    "display": "block",
                        "top":"-50px",
                        "left":"760px",
        			    "z-index": 199
        		});
                $("#thirdline").show();
                
                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);

});

function gotoGetStart(){
    window.open('http://www.theamensolution.com/home_new/get-started-my-brain-type/');
}
