$(document).ready(function(){
    $().RobbieRoll();
});

$.fn.RobbieRoll = function(e) {
    $('.RobbieRoll').each(function () {
        var distance = 0;
        var time = 250;
        var hideDelay = 500;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var rel=$(this).attr('id');
        var info = $('#Rollover_' + rel).css('left',-2000);

        $([$(this).get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                info.css({
                       'left': 'auto',
                       'right': 80,
                       'z-index': 10
                         });

                beingShown = false;
                shown = true;

            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.css({
                       'left': -2000,
                       'right': 'auto'
                            });
                shown = false;

            }, hideDelay);

            return false;
        });
    });
};

$.fn.ajaxSubmit = function(e) {
     /* Change the forms submission type to ajax */
    var submitting = false;
    this.submit(function(){
         if (!submitting) {
                 submitting = true;
                 this.style.position = "absolute";
                 this.style.left = "-2000px";
                 var waitmessage = '<img src="images/loading.gif" width="126" height="22" alt="loading" /><br />Submitting Form';
                 $("#filter_bottom").css("padding", "20px 0 60px 0").html(waitmessage);
                 $("#PhoneList").html("");
                 var params = {};
                 $(this)
                    .find("input[checked], input[type='text'], input[type='hidden'], input[type='password'], input[type='submit'], option[selected], textarea")
                    .each(function() {
                          params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
                    })


                 FailTimer = setTimeout(function () {
                      delete FailTimer;
                      var waitmessage = '<img src="images/loading.gif" width="126" height="22" alt="loading" /><br />Server not responding - reloading page';
                      alert('Error Point 2');
                      if (typeof $ !== 'undefined') {
                         $("#filter_bottom").html(waitmessage);
                      }
                      window.location.href=window.location.href;
                 }, 30000);

                 paramstring = '';
                 for(var i in params) {
                      var value = params[i];
                      paramstring = paramstring + '&' + i +'=' + value;
                 }

                 /* Google Analytics tracking */
                 pageTracker._trackPageview('/filter?ajax' + paramstring);
                 /* We could also replace button at this point */
                 action = this.getAttribute("action");
                 action = action + ( action.indexOf('?') == -1 ? '?' : '&' );
                 $.ajax({
                   async: false,
                   dataType: "html",
                   type: 'POST',
                   url: action + "ajax",
                   data: params,
                   timeout: 10000,
                   success: function(html, textStatus, XMLHttpRequest) {
                         if (textStatus == "success") {
                                 $("#PhoneList").html(html);
                                 $("#filter_bottom").css("padding", "0").html("");
                                 if (typeof FailTimer !== 'undefined') {clearTimeout(FailTimer); delete FailTimer;}
                         } else {
                                 /* Another fail safe */
                                 var waitmessage = '<img src="images/loading.gif" width="126" height="22" alt="loading" /><br />Error in response from server. Reloading page.';
                                 $("#filter_bottom").html(waitmessage);
                                 window.location.href = window.location.href;
                         }
                      },
                   error: function (XMLHttpRequest, textStatus, errorThrown) {alert('Error in response');}
                 });

                 if (typeof FailTimer !== 'undefined') {clearTimeout(FailTimer); delete FailTimer;}
                 submitting = false;
                 this.style.position = "relative";
                 this.style.left = "0";

                 /* Half second delay until refreshinghte roll over states */
                 setTimeout(function () {
                     if (typeof $ !== 'undefined') {
                        $().RobbieRoll();
                     }
                 }, 500);
         }
         return false;
    });
    return this;
}

jQuery.preloadImages = function() {
  var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
  for(var i = a.length -1; i > -1; i--) {
     jQuery("<img>").attr("src", a[i]);
  }
}
$.fn.ajaxSubmit1 = function(e) {
     /* Change the forms submission type to ajax */
	var submitting = false;
    this.submit(function(){
	         if (!submitting) {
                 submitting = true;
                 this.style.position = "absolute";
                 this.style.left = "-2000px";
                 var waitmessage = '<img src="images/loading.gif" width="126" height="22" alt="loading" /><br />Submitting Form';
               //  $("#filter_bottom_1").css("padding", "20px 0 60px 0").html(waitmessage);
                 $("#PhoneList").html("");
                 var params = {};
                 $(this)
                    .find("input[checked], input[type='text'], input[type='hidden'], input[type='password'], input[type='submit'], option[selected], textarea")
                    .each(function() {
                          params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
                    })


                 FailTimer = setTimeout(function () {
                      delete FailTimer;
                      var waitmessage = '<img src="images/loading.gif" width="126" height="22" alt="loading" /><br />Server not responding - reloading page';
                      alert('Error Point 2');
                      if (typeof $ !== 'undefined') {
                         $("#PhoneList").html(waitmessage);
                      }
                      window.location.href=window.location.href;
                 }, 30000);

                 paramstring = '';
                 for(var i in params) {
                      var value = params[i];
                      paramstring = paramstring + '&' + i +'=' + value;
                 }
				
                 /* Google Analytics tracking */
                // pageTracker._trackPageview('/filter?ajax' + paramstring);
                 /* We could also replace button at this point */
                 action = this.getAttribute("action");
				 action = action + ( action.indexOf('?') == -1 ? '?' : '&' );
                 $.ajax({
                   async: false,
                   dataType: "html",
                   type: 'POST',
                   url: action + "ajax",
                   data: params,
                   timeout: 10000,
                   success: function(html, textStatus, XMLHttpRequest) {
                         if (textStatus == "success") {
						 
                               $("#PhoneList").html(html);
                                // $("#filter_bottom").css("padding", "0").html("");
                                 if (typeof FailTimer !== 'undefined') {clearTimeout(FailTimer); delete FailTimer;}
                         } else {
                                 /* Another fail safe */
                                 var waitmessage = '<img src="images/loading.gif" width="126" height="22" alt="loading" /><br />Error in response from server. Reloading page.';
                                 $("#filter_bottom_1").html(waitmessage);
                                 window.location.href = window.location.href;
                         }
                      },
                   error: function (XMLHttpRequest, textStatus, errorThrown) {alert('Error in response');}
                 });

                 if (typeof FailTimer !== 'undefined') {clearTimeout(FailTimer); delete FailTimer;}
                 submitting = false;
                 this.style.position = "relative";
                 this.style.left = "0";

                 /* Half second delay until refreshinghte roll over states */
                 setTimeout(function () {
                     if (typeof $ !== 'undefined') {
                        $().RobbieRoll();
                     }
                 }, 500);
         }
		 
         return false;
    });
	
    return this;
}
