

$(function() {
    function slidePanel( newPanel, direction ) {
        // define the offset of the slider obj, vis a vis the document
        var offsetLeft = $slider.offset().left;

        // offset required to hide the content off to the left / right
        var hideLeft = -1 * ( offsetLeft + $slider.width() );
        var hideRight = $(window).width() - offsetLeft;

        // change the current / next positions based on the direction of the animation
        if ( direction == 'left' ) {
            currPos = hideLeft;
            nextPos = hideRight;
        }
        else {
            currPos = hideRight;
            nextPos = hideLeft;
        }

        // slide out the current panel, then remove the active class
        $slider.children('.slide-panel.active').animate({
            left: currPos
        }, 500, function() {
            $(this).removeClass('active');
			$infoPanel.css("display", "none");
        });

        // slide in the next panel after adding the active class
        $( $sliderPanels[newPanel] ).css('left', nextPos).addClass('active').animate({
            left: 0
        }, 500 );
    }

    var $slider = $('#full-slider');
    var $sliderPanels = $slider.children('.slide-panel');

    var $navLeft = $("#nav-left");
    var $navRight = $("#nav-right");
	
	var $dotBrain = $("#nav-dots .nav-dot");
	var $dotActive = $("<div></div>").appendTo($dotBrain[0]);
	
	var $infoButton = $("#info-nav");
	var $infoPanel = $(".slide-panel.active .info-panel");

	var $reHide = $(".re-hide");
	var $frontHidey = $("#front-hidey.active");
	
    var currPanel = 0;

    $navLeft.click(function() {
        currPanel--;
		
		$dotActive.remove();
		$infoButton.removeClass("inUse");
		
        // check if the new panel value is too small
        if ( currPanel < 0 ) currPanel = $sliderPanels.length - 1;
		
		$dotActive = $("<div></div>").appendTo($dotBrain[currPanel]);
		// check to see if the info panel is active - if not, just go to the next panel.
		if ($infoPanel.css("display") == "block") {
			$infoPanel.slideToggle("slow", function() {
				slidePanel(currPanel, 'right');
			});
		} else {
			slidePanel(currPanel, 'right');
		};
    });

    $navRight.click(function() {
        currPanel++;
		
		$dotActive.remove();
		$infoButton.removeClass("inUse");
		
        // check if the new panel value is too big
        if ( currPanel >= $sliderPanels.length ) currPanel = 0;
		
		$dotActive = $("<div></div>").appendTo($dotBrain[currPanel]);
		
		// check to see if the info panel is active - if not, just go to the next panel.
		if ($infoPanel.css("display") == "block") {
			$infoPanel.slideToggle("slow", function() {
				slidePanel(currPanel, 'left');
			});
		} else {
			slidePanel(currPanel, 'left');
		};
				
    });
	
	$dotBrain.easyTooltip();
	$dotBrain.click(function() {
		var index = $dotBrain.index(this)
		var oldPanel = currPanel;
		currPanel = index;
		if (currPanel == oldPanel) return;
		
		$dotActive.remove();
		$infoButton.removeClass("inUse");
		
		// if the active dot is clicked, nothing happens - otherwise advance or go to the previous page.
		
		if (currPanel > oldPanel) {
			// check to see if the info panel is active - if not, just go to the next panel.
			if ($infoPanel.css("display") == "block") {
				$infoPanel.slideToggle("slow", function() {
					slidePanel(currPanel, 'left');
				});
			} else {
				slidePanel(currPanel, 'left');
			};
		};
		if (currPanel < oldPanel) {
			// check to see if the info panel is active - if not, just go to the next panel.
			if ($infoPanel.css("display") == "block") {
				$infoPanel.slideToggle("slow", function() {
					slidePanel(currPanel, 'right');
				});
			} else {
				slidePanel(currPanel, 'right');
			};
		};
		$dotActive = $("<div></div>").appendTo($dotBrain[index]);	
		
	});
	$infoButton.click(function() {
		$infoPanel = $(".slide-panel.active .info-panel");
		$infoPanel.slideToggle("slow")
		makePanel();
		$(this).toggleClass("inUse");
	});
		
	function makePanel() { // this is finding the height of the paragraph and centering it vertically.
		var $infoHeight = $(".slide-panel.active .info-panel .info").height();
		var $spacerBotMarg = -1 * ($infoHeight/2);
		$(".slide-panel.active .info-panel .info").css("height", $infoHeight);
		$(".info-spacer").css("margin-bottom", $spacerBotMarg);
	};
	
	$frontHidey.click(function() {
		$frontHidey.slideToggle("slow");
	});
	$reHide.click(function() {
		$frontHidey.slideToggle("slow");
	});
});

$(document).ready(function(){
	$(".page").hide();
	$(".page:first").show();
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		if (trgt != "main") {
			$(".page").hide();
		};
		var target_show = $("#"+trgt);
		$(target_show).show();
		
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
	});
});

$(function() {
    $('.contact').attr('href', $.rotate13('znvygb:vasb@wrerzlxvefpu.pbz')).text($.rotate13('vasb@wrerzlxvefpu.pbz'));
});



