$(document).ready(function () {

    if ($("#navigation .collapsed").length > 0) {
        InitNav();
    }

    var qa = $(".print-break-container");
    if (qa.length) {
        qaPrint(qa);
    }

    if ($('.faqContainer').length > 0) {
        EST.FAQ.setup();
    }

    if ($('.youtubeVideo').length > 0) {
        EST.YOUTUBE.init();
    }

    if ($('.btnSignUp').length > 0) {
        EST.FORMS.btnSignUp();
    }
});

var EST = EST || {};

EST.FORMS = {
    btnSignUp: function () {
        $('.btnSignUp').hide();
        $('.inputBtnSignUp').click(function (e) {
            e.preventDefault();
            window.location = "/signup.aspx";
        });
    }
};

EST.FAQ = {
    init: function () {
        $('li.faq_widget').each(function () {
            EST.FAQ.setup($(this));
        });
    },

    setup: function () {
        wfaq = $('.faqContainer');
        var faqSections = wfaq.find('.faqList li');
        var sectionTitle = faqSections.children("h3");
        var faqQuestions = wfaq.find('.faqQuestions li');
        var faqQuestion = faqQuestions.children("h4");

        var wrapper = wfaq.find('.wrapper').hide().filter(':first').show();
        wrapper.parent().addClass('selected');
        var innerWrapper = wrapper.find('.wrapper').hide().filter(':first').show();
        innerWrapper.parent().addClass('selected');

        faqSections.filter(':first').addClass('selected');

        sectionTitle.click(function (event) {
            event.stopPropagation();
            var status = $(this).parent().attr("class");

            if (status == "selected") {
                EST.FAQ.hide($(this), wfaq);
            } else {
                EST.FAQ.show($(this), wfaq);
            }
        });

        faqQuestion.click(function (event) {
            event.stopPropagation();
            var status = $(this).parent().attr("class");

            if (status == "selected") {
                EST.FAQ.hide($(this), wfaq);
            } else {
                EST.FAQ.show($(this), wfaq);
            }
        });
    },

    show: function (current, wfaq) {
        current.parent().parent().children('.selected').children('div.wrapper').slideUp();
        current.parent().parent().children('.selected').removeClass('selected');
        current.parent().addClass("selected");
        current.parent().children('div.wrapper').slideDown();
    },

    hide: function (current, wfaq) {
        current.parent().parent().children('.selected').children('div.wrapper').slideUp();
        current.parent().parent().children('.selected').removeClass('selected');
    }
};

EST.YOUTUBE = {
    init: function () {
        var youtubeDiv = $('.youtubeVideo');
        var hideTrigger = $('.myTravelPlanOverview a');
        var showTrigger = $('#lbMain');
        var showTrigger2 = $('#lbDetailsContainer');
        var showTrigger3 = $('#lbClose');


        hideTrigger.click(function () {
            EST.YOUTUBE.hide(youtubeDiv);
        });

        //hide is triggered within lytebox.js

    },

    show: function (el) {
        el.css("visibility", "visible");
    },

    hide: function (el) {
        el.css("visibility", "hidden");
    }
};

function qaPrint(qa){
    var qaObj = qa;
    var qaHeight=0;
    qaObj.each(function(){
        var qa = $(this);
        qaHeight += qa.height();
        if(qaHeight >= 750){
            qa.addClass("print-break-before");
            qaHeight=qa.height();
        }
    });
}

function InitNav(){
	$("#navigation .collapsed ul").hide();
	$("#navigation .collapsed").prepend("<img class='expand-icon' width='16' height='16' src='images/expand-icon.gif' />");
	
	$("#navigation .collapsed select").change(function(){
		if($(this).val() != 0) {
			$(this).siblings("ul").show();
			$(this).parent().siblings(".expand-icon").hide();
			$(this).parent().parent().removeClass("collapsed");
		}
		if($(this).val() == 0) {
			$(this).siblings("ul").hide();
			$(this).parent().siblings(".expand-icon").show();
			$(this).parent().parent().addClass("collapsed");
		}
	});
}


function CheckAll() {
    var totalCount = 0;
    var checkedCount = 0;

    $(".updateField input[type='checkbox']").each(function() {

        if (this.checked)
            checkedCount = checkedCount + 1;

        totalCount = totalCount + 1;

    });

    if (checkedCount  == 0 || checkedCount < totalCount) {
        $(".updateField input[type='checkbox']").each(function() {
            if (!this.checked)
                $(this).click();
        });
    }

    if (checkedCount  == totalCount) {
        $(".updateField input[type='checkbox']").each(function() {
            if (this.checked)
                $(this).click();
        });
    }

    return false;
}



function SelectAll() {
    $(".pass-checbox input[type='checkbox']").each(function() {
        if (!this.checked)
            $(this).click();
    });

}

