﻿/***

	Markup guide

***/

(function($) {

    $.blueroom = $.blueroom || {};

    var g_ready = false;
    var g_self = this;

    $.fn.faqs = function() {
        return this.each(function() {

        });
    };

    $.blueroom.faqs = function(options) {
        var c_self = this;
        var c_ready = false;
        c_self.options = $.extend({}, $.blueroom.faqs.defaults, options);


        c_self.functions = {
            initialise: function(context) {
                context.each(function(index) {

                    var currentContext = $(this);
                    $("pre").css("display", "none");
                    c_self.functions.controlPanels();
                    //c_self.functions.addNumbers();

                });

            },
            controlPanels: function() {


                var pathname = window.location.href;


                $('.inner-content').find('.panel').each(function(i) {
                    var maxHeight = $(this).attr('maxHeight', $(this).height());
                    var minHeight = $(this).find(':first-child').height() + 7;
                    $(this).height(minHeight);
                })

                $('.panel h2').css({ cursor: 'pointer' })
                $('.panel h2').hover(
					function() {
					    $(this).css({ color: '#0086C3' });
					},
					function() {
					    $(this).css({ color: '#535353' });
					}
				)

                if (pathname.endsWith('business')) {

                    var position = $('#businessPanel').position().top;
                    var container = $('#businessPanel .question').parent()
                    var buttonText = $('#businessPanel .question').find('.button span span span');
                    var maxHeight = container.attr('maxheight');
                    var minHeight = $('#businessPanel .question').height() + 7;
                    if (container.height() != maxHeight) {
                        container.animate({ height: maxHeight }, 250, function() {
                            window.scroll(0, position + 150); // horizontal and vertical scroll targets
                        })
                        buttonText.css({ padding: "1px 8px 3px 8px" });
                        buttonText.html('&ndash;')
                    } else {
                        container.animate({ height: minHeight }, 250);
                        buttonText.css({ padding: "2px 8px 2px 8px" });
                        buttonText.html('+')
                    }








                }

                $('.panel .question').click(function() {
                    var container = $(this).parent()
                    var buttonText = $(this).find('.button span span span');
                    var maxHeight = container.attr('maxheight');
                    var minHeight = $(this).height() + 7;
                    if (container.height() != maxHeight) {
                        container.animate({ height: maxHeight }, 250);
                        buttonText.css({ padding: "1px 8px 3px 8px" });
                        buttonText.html('&ndash;')
                    } else {
                        container.animate({ height: minHeight }, 250);
                        buttonText.css({ padding: "2px 8px 2px 8px" });
                        buttonText.html('+')
                    }
                })

            },
            addNumbers: function() {
                $("dt").each(function(i) {
                    $(this).prepend((i + 1) + ".&nbsp;&nbsp;");
                });
            },
            debuglog: function(logtext) {
                try {
                    if (console && console.log) {
                        console.log(logtext);
                    }
                }
                catch (err) {
                    //alert(err);
                }
            }
        };

        c_self.functions.initialise($("body"));
        c_self.functions.debuglog("init");
        c_ready = true;
    };

    // defaults
    $.blueroom.faqs.defaults = {
        //TODO:
        easing: "quad",
        animationSpeed: "1000",
        intervalFrequency: "10000"
    };

    // optional - initialise one or more instances of the class
    $(document).ready(function() {
        new $.blueroom.faqs();
    });
})(jQuery);
