(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

jQuery.preLoadImages("/images/DownloadPDFRollover.png","/images/drivingRollover.png");

$().ready(function(){

    
     $(".cleared").click(function(){
         $(this).attr("value", "")
     });
     $(".ajax-fc-container").captcha({formId: "the_form"});
    $("#bottom_content").each(function(){
        if(this.scrollHeight> 370)
        {
            $('#bottom_content')
            .bind('mousewheel', function(event, delta) {
                if(delta < 0)
                {
                    newpos = ($(".bot_handle").position().top) + 30;
                    if(newpos > 370 - ($(".bot_handle").height()))
                        newpos = 370 - ($(".bot_handle").height());
                }else
                {
                    newpos = ($(".bot_handle").position().top) - 30;
                    if(newpos < 0)
                        newpos = 0;
                }

                $(".bot_handle").css("top", newpos);
                var percentage = ((newpos*100)/$(".bot_handle").parent().height())/100;
                $("#bottom_content").scrollTop($("#bottom_content").attr("scrollHeight")*percentage);
                return false;
            });

            $(this).parent().prepend("<div class='scroll_vert height_350'><div class='handle bot_handle'></div></div>");
            $(".bot_handle").css("height",(350*((350*100)/this.scrollHeight)/100));
            $('.bot_handle').draggable({ axis: 'y', containment: 'parent', cursor: 'pointer', scroll: true, drag: function(event, ui){
                            var percentage = ((ui.position.top*100)/$(this).parent().height())/100;
                            $("#bottom_content").scrollTop($("#bottom_content").attr("scrollHeight")*percentage);
                        }
                     });
        }
    })

     $(".text").each(function(){

        if(this.scrollHeight> 325)
        {
            $('.text')
            .bind('mousewheel', function(event, delta) {
                if(delta < 0)
                {
                    newpos = ($(".top_handle").position().top) + 30;
                    if(newpos > 370 - ($(".top_handle").height()))
                        newpos = 370 - ($(".top_handle").height());
                }else
                {
                    newpos = ($(".top_handle").position().top) - 30;
                    if(newpos < 0)
                        newpos = 0;
                }

                $(".top_handle").css("top", newpos);
                var percentage = ((newpos*100)/$(".top_handle").parent().height())/100;
                $(".text").scrollTop($(".text").attr("scrollHeight")*percentage);
                return false;
            });
            $(this).parent().prepend("<div class='scroll_vert height_325'><div class='handle top_handle'></div></div>");
            $("#page_summary .scroll_vert").css("top", 25);
            $("#page_summary .handle").css("height",(325*((325*100)/this.scrollHeight)/100));
            $('#page_summary .handle').draggable({ axis: 'y', containment: 'parent', cursor: 'pointer', scroll: true, drag: function(event, ui){
                            var percentage = ((ui.position.top*100)/$(this).parent().height())/100;
                            $(".text").scrollTop($(".text").attr("scrollHeight")*percentage);
                        }
                     });
        }
    })
    
    
    
    $("#logo_holder").each(function(){
        if(this.scrollHeight> 370)
        {
            
            $('#logo_holder')
            .bind('mousewheel', function(event, delta) {
                if(delta < 0)
                {
                    newpos = ($(".top_handle").position().top) + 30;
                    if(newpos > 370 - ($(".top_handle").height()))
                        newpos = 370 - ($(".top_handle").height());
                }else
                {
                    newpos = ($(".top_handle").position().top) - 30;
                    if(newpos < 0)
                        newpos = 0;
                }

                $(".top_handle").css("top", newpos);
                var percentage = ((newpos*100)/$(".top_handle").parent().height())/100;
                $("#logo_holder").scrollTop($("#logo_holder").attr("scrollHeight")*percentage);
                return false;
            });
            $(this).parent().prepend("<div class='scroll_vert height_325 logo_bar'><div class='handle top_handle'></div></div>");
            $(".scroll_vert").css("top", 10);
            $(".handle").css("height",(325*((325*100)/this.scrollHeight)/100));
            $('.handle').draggable({ axis: 'y', containment: 'parent', cursor: 'pointer', scroll: true, drag: function(event, ui){
                            var percentage = ((ui.position.top*100)/$(this).parent().height())/100;
                            $("#logo_holder").scrollTop($("#logo_holder").attr("scrollHeight")*percentage);
                        }
                     });
        }
    })


})