










var jScrollPaneApi;

$(document).ready(function() {
    //FIND LI ASSOCIATED WITH PAGE TITLE
    
    $('#navDetails li a').each(function(index) {
        aTxt = $(this).text();
        tTxt = $('h1').text(); 
        if (aTxt == tTxt) {
            $(this).parent().addClass("active");
        }
    });
    $('#navApplications li a').each(function(index) {
        aTxt = $(this).text();
        tTxt = $('h1').text();
        if (aTxt == tTxt) {
            $(this).parent().addClass("active");
        }
    });

    /*display:none;*/
    //login toggle
    $("a.moreInfo").click(function() {

        $("a.moreInfo").toggleClass("off").toggleClass("on");
        //$("#content #base").slideToggle("medium", function() {
        $("#content #base").toggle(0, function() {
            if ($("a.moreInfo").hasClass('moreInfoClose')) {
                initjScrollPane();
            }
        });

        $('html, body').animate({ scrollTop: $("#base").offset().top }, 'medium');

        return false;
    });

    $("li:last-child").addClass("last");

    //stop single menu ites linking off - basically for camcopter page.
    if ($('#top').is('.MineHome')) {

    } else {
        $("#navApplications li:only-child").addClass("active").children().click(function(e) {
            e.preventDefault();

        });
    }


    //    $("a#menuBtn").mouseenter(function() {
    //        if ($("a#menuBtn").hasClass("off")) {
    //            $("a#menuBtn").addClass("on").removeClass("off");
    //            $(".RadMenu").slideDown("medium");
    //        }
    //        return false;
    //    });


    //    $('.RadMenu').mouseleave(function() {
    //        $('.RadMenu').slideUp('slow');
    //        $("a#menuBtn").removeClass("on").addClass("off");
    //    });


    //PREVENT CLICK
    $('a#menuBtn').click(function(e) {
        e.preventDefault();
    });

    $("a#menuBtn").mouseover(function() {
        if ($("a#menuBtn").hasClass("off")) {
            $("a#menuBtn").addClass("on").removeClass("off");
            $(".RadMenu").show();
        }
    })
    $(".RadMenu").mouseleave(function() {
        $('.RadMenu').hide();
        $("a#menuBtn").removeClass("on").addClass("off");

    })

    //    $("a#menuBtn").hoverIntent({ over: makeTall });
    //    $(".RadMenu").hoverIntent({ over: makeTall, timeout: 150, out: makeShort });
    //    function nothing() { }
    //    function makeTall() {
    //        if ($("a#menuBtn").hasClass("off")) {
    //            $("a#menuBtn").addClass("on").removeClass("off");
    //            //$(".RadMenu").slideDown("medium");
    //            $(".RadMenu").show();
    //        }
    //    }

    //    function makeShort() {
    //        // $('.RadMenu').slideUp('slow');
    //        $('.RadMenu').hide();

    //        $("a#menuBtn").removeClass("on").addClass("off");
    //    }




    $(".products input[type=checkbox]").each(function() {
        var bp = $(this).parent().css("background-position");
        var ioa = bp.indexOf("px");
        var iob = bp.substring(5, ioa);
        var bpn = parseInt(iob);
        var spacer = 34;

        if ($(this).is(':checked')) {
            $(this).parent().css({ 'background-position': '100% ' + (bpn + spacer) + 'px' });
            $(this).parent().addClass('selected');
        }


        $(this).change(function() {
            var bp = $(this).parent().css("background-position");
            var ioa = bp.indexOf("px");
            var iob = bp.substring(5, ioa);
            var bpn = parseInt(iob);


            var myClass = $(this).parent().attr("class");
            if ($(this).is(':checked')) {
                $(this).parent().css({ 'background-position': '100% ' + (bpn + spacer) + 'px' });
                $(this).parent().addClass('selected');
                //$(this).parent().addClass(myClass.replace("-off", "-selected"));
            }
            else {
                $(this).parent().css({ 'background-position': '100% ' + (bpn - spacer) + 'px' });
                $(this).parent().removeClass('selected');
                //$(this).parent().addClass(myClass.replace("-selected", "-off"));
            }
        });
    });


    //initjScrollPane();


    // $("#content #base").hide();


});


function initTabScrollable() {
    $(".scrollable").each(function(ind, Element) {
        // Initialize the Scrollable control
    
    $(this).scrollable({ vertical: true, mousewheel: true });
        // Get the Scrollable control
        var so =$(this);
        //eval("var scrollable" + ind);

        // var vn= vn+ind; window['scrollable' + ind]

         window['scrollable' + ind] = jQuery($(this)).data('scrollable');
        // Set to the number of visible items

        //alert($(this) + "_" + window['scrollable' + ind]);
        var size = 3;

        //alert(window['scrollable' + ind].getSize())

        if (window['scrollable' + ind].getSize() <= size) {
            so.siblings("a.next").addClass("disabled");
        }

        // Handle the Scrollable control's onSeek event
        window['scrollable' + ind].onSeek(function(event, index) {
            // Check to see if we're at the end
            if (this.getIndex() >= this.getSize() - size) {
                // Disable the Next link
                so.siblings("a.next").addClass("disabled");
            }
        });
        // Handle the Scrollable control's onBeforeSeek event
        window['scrollable' + ind].onBeforeSeek(function(event, index) {
            // Check to see if we're at the end
            if (this.getIndex() >= this.getSize() - size) {
                // Check to see if we're trying to move forward
                if (index > this.getIndex()) {
                    // Cancel navigation
                    return false;
                }
            }
        });
    });
 }
function initjScrollPane(){
    var jScrollPane = $('.scroll-pane').jScrollPane({
        showArrows: true,
        maintainPosition: false,
        hijackInternalLinks: true,
        verticalDragMinHeight: 18,
        verticalDragMaxHeight: 18

    });
    
    if (jScrollPane != null) {
        jScrollPaneApi = jScrollPane.data('jsp');
    }
    //console.log("initjScrollPane");
    //alert("initjScrollPane")
}

function onResponseEnd(sender, arguments) {
    //alert('Callback request is completed. Response is processed.');
    jScrollPaneApi.reinitialise();
};

function onResponseStart(sender, arguments) {
    //alert('Callback request is started.');
};


function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }

 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

loadjscssfile("http://www.projekktor.com/js/projekktor.test.min.js", "js") //dynamically load and add this .js file







