﻿$(function () {
    /**AGE GATE**/
    $('#AgeGate').jqm({
        trigger: 'a.agegatetrigger',
        modal: true,
        onHide: function (h) {
            // Clear Content HTML on Hide.
            h.o.remove(); // remove overlay
            h.w.fadeOut(888); // hide window
            //create cookie;
            $.cookie('oldEnough', true, { path: '/', expires: 1 });
            autoOpenHome();
        },
        onShow: function (h) {

            h.o.css('opacity', 0.88);
            h.w.show();
        }

    });
    if ($.cookie('oldEnough') == null) {
        //show age gate here:
        $('#AgeGate').jqmShow();

    }
    else {
        autoOpenHome();
    }
    $('#LoginDialog').jqm({ 
    	trigger: 'a.logintrigger',    
	onShow: function (h) {
            h.o.css('opacity', 0.88);
            h.w.show();
        } 
    });
    $('#SignUpDialog').jqm({ 
    	trigger: 'a.signuptrigger',
	onShow: function (h) {
            h.o.css('opacity', 0.88);
            h.w.show();
        } 
    });

    $('#AgeGate').click(function () {
    	$('.ageEnter .jqmClose').click();
    });
    $('.review-answers').buttonset();

    $('.arrow-home img').click(function () {


        $('#ContentPane').animate({ height: 'toggle' });

        if ($('.arrow-home').hasClass('open')) {
            $('.arrow-home img').attr('src', '/Content/Images/closed-arrow.png');
            $('.arrow-home').animate({ height: '45px' }, '500');
            $('.arrow-home').removeClass('open');

        }
        else {
            $('.arrow-home img').attr('src', '/Content/Images/open-arrow.png');
            $('.arrow-home').animate({ height: '479px' }, '500');
            $('.arrow-home').addClass('open');

        }

        $('#scrollbar1').tinyscrollbar({ sizethumb: 13 });

    });
    function autoOpenHome() {
        if (!$('arrow-home').hasClass('open'))
            setTimeout(function () {
                $('.arrow-home img').click();

            }, 1000)
    }

    $('.slideIcon').click(function () {

        var currentSide = $(this).parent().attr('class');
        var currentJourney = $(this).parent().parent().attr('id');
        $('#' + currentJourney + ' .' + currentSide + ' .contentPane').animate({ width: 'toggle' }, '400');
        $('.leftSide').tinyscrollbar({ sizethumb: 13 });
        $('#' + currentJourney + ' .' + currentSide + ' .slideIcon img').toggleClass('open');

    });

    function closeTabs() {
        $('.contentPane').animate({ width: '0px' }, '400');
    }
    /*Our Journey Bottom Icons*/
    $('.icon').hover(function () {

        $(this).toggleClass('active');
    });
    var currentContent = 'TheLand';
    $('.icon').click(function () {
        $('.icon').removeClass('selected');
        $(this).addClass('selected');
        var id = $(this).attr('id');

        switch (id) {
            case 'LandIcon':
                switchGraphic("/Content/Images/the-land-bkgd.jpg", 'TheLand');
                currentContent = 'TheLand';
                break;
            case 'BarrelingIcon':
                switchGraphic("/Content/Images/barreling-bkgd.jpg", 'Barreling');
                currentContent = 'Barreling';
                break;
            case 'OakIcon':
                switchGraphic("/Content/Images/oak-tree-bkgd.jpg", 'OakTree');
                currentContent = 'OakTree'; ;
                break;
            case 'BourbonIcon':
                switchGraphic("/Content/Images/the-bourbon-bkgd.jpg", 'theBourbon');
                currentContent = 'theBourbon';
                break;
        }


    });

    function closeIcons(currentContentArea) {



        $('#' + currentContentArea + ' .contentPane').hide();
        $('#' + currentContentArea + ' .slideIcon img').toggleClass('open');

    }

    function switchGraphic(imagePath, content) {
        var fadeSpeed = 'slow';

        //$('#' + currentContent + ' .slideIcon .open').click();
        $('#' + currentContent).css('filter', 'alpha(opacity=1)');
        $('#' + currentContent).fadeOut(fadeSpeed, function () {
            closeIcons(currentContent);
            $('#' + currentContent).css('filter', 'none');
        });

        $('#FullOverlayJourney').fadeOut(fadeSpeed, function () {

            $('#FullOverlayJourney').css('background', 'url("' + imagePath + '") no-repeat top center');
            $('#FullOverlayJourney').fadeIn(fadeSpeed, function () {
            });


            if ($.browser.msie) {
                //IE creates a weird filter around the images. 
                $('#' + content).css('filter', 'alpha(opacity=1)');
                $('#' + content).fadeIn(fadeSpeed, function () {
                    $('#' + content).css('filter', 'none');
                    //slide containers on 2 second delay delay
                    delayedSlide(currentContent);
                });
            }
            else {
                $('#' + content).fadeIn(fadeSpeed, function () {
                    delayedSlide(currentContent);
                });
            }

        });


    }

    function delayedSlide(currentContent) {
        setTimeout(function () {
            $('#' + currentContent + ' .leftSideWrapper .slideIcon .open').click();
        }, 2000);
        setTimeout(function () {
            $('#' + currentContent + ' .rightSideWrapper .slideIcon .open').click();
        }, 2800);
    }




    $('.login-remember').buttonset();
    $('.closeLogin').click(function () {
        $('#LoginDialog').jqmHide();
    });

    setTimeout(function () {
        try {
            delayedSlide(currentContent);
        } catch (err) { }
    }, 250);

    function loadContent(id) {

    }

});
function preload() {

    image = new Image();
    image2 = new Image();
    image3 = new Image();
    image4 = new Image();
    image5 = new Image();
    image.src = '/Content/Images/the-bourbon-bkgd.jpg';
    image2.src = '/Content/Images/barreling-bkgd.jpg';
    image3.src = '/Content/Images/the-land-bkgd.jpg';
    image4.src = '/Content/Images/oak-tree-bkgd.jpg';
}
