/* tooltps */
function tooltip2()
{
  /* CONFIG */
  xOffset2 = 10;
  yOffset2 = -180;
  // these 2 variable determine popup's distance from the cursor
  // you might want to adjust to get the right result
  /* END CONFIG */

  jQuery("a.tooltip2").hover(function(e)
  {
    this.t = this.title;
    this.title = "";
    jQuery("body").append("<p id='tooltip2'>"+ this.t +"</p>");
    jQuery("#tooltip2")
    .css("top",(e.pageY - xOffset2) + "px")
    .css("left",(e.pageX + yOffset2) + "px")
    .css("position", "absolute")
    .fadeIn("fast");
  },
  function()
  {
    this.title = this.t;
    jQuery("#tooltip2").remove();
  });

  jQuery("a.tooltip2").mousemove(function(e)
  {
    jQuery("#tooltip2")
    .css("top",(e.pageY - xOffset2) + "px")
    .css("left",(e.pageX + yOffset2) + "px");
  });

  jQuery("a.tooltip2").click(function()
  {
    return false;
  });
};
/* end tooltips */


function getValueCss(attrClass, rx) {
        var match = attrClass.match(rx);
        var val = '';
        if (match && match.length > 1) {
            val = match[1];
        }
        return val;
    }


jQuery().ready(function() {
  jQuery('#dialog').jqm();

   jQuery('#fly-close').click(function(){
      jQuery('#dialog').jqmHide();
  });

tooltip2();

});


jQuery().ready(function() {
                jQuery("#distanceslider").slider({
                        range: "min",
                        value: 200,
                        min: 0,
                        max: 200,
                        slide: function(event, ui) {

                          if (ui.value == '200' || ui.value == '0')
                          {
                                jQuery("#amount").val('National');
                                jQuery("#amount").css({'margin-left':'-35px','width':'55px'});

                          }
                          else
                          {
                                jQuery("#amount").val('Within ' + ui.value + ' miles');
                                jQuery("#amount").css({'margin-left':'-80px','width':'95px'});
                          }

                        jQuery("#distance2").val(ui.value);

                        }
                });

                        if (jQuery("#distanceslider").slider("value") == '200' || jQuery("#distanceslider").slider("value") == '0')
                        {
                          jQuery("#amount").val('National');
			  jQuery("#amount").css({'margin-left':'-35px','width':'55px'});
                        }
                        else
                        {
                          jQuery("#amount").val('Within ' + jQuery("#distanceslider").slider("value")+ ' miles');
                          jQuery("#amount").css({'margin-left':'-80px','width':'95px'});
                        }

			jQuery("#distance2").val(jQuery("#distanceslider").slider("value"));



                        jQuery("#priceslider").slider({
                                range: true,
                                min: 0,
                                max: 50000,
                                values: [0, 50000],
                                step: 500,
                                slide: function(event, ui) {
                                jQuery("#amount2").val('$' + ui.values[0] + ' - $' + ui.values[1]);
                                $slider = jQuery("#priceslider");
                if (ui.values && ui.values.length > 1) {
                    var min = $slider.slider('option', 'min');
                    var max = $slider.slider('option', 'max');
                    var isMin = (ui.values[0] == min);
                    var isMax = (ui.values[1] == max);

                    if (isMin) {
                        if (isMax) {
                            text = 'Any price';
                            jQuery("#price").css({'margin-left':'-40px','width':'60px'});
                        } else {
                            text = 'Below £' + ui.values[1] ;
                            jQuery("#price").css({'margin-left':'-75px','width':'90px'});
                        }
                    } else if (isMax) {
                        text = 'Above £' + ui.values[0] ;
                        jQuery("#price").css({'margin-left':'-75px','width':'90px'});
                    } else {
                        text = 'Between £' + ui.values[0] + ' and £' +  ui.values[1] ;
                        jQuery("#price").css({'margin-left':'-150px','width':'170px'});
                    }

                }
                        jQuery("#price").val(text);
			jQuery("#price_from").val(ui.values[0]);
		        jQuery("#price_to").val(ui.values[1]);
                }

                        });

                if (jQuery("#priceslider").slider("values", 0) == '0' && jQuery("#priceslider").slider("values", 1) == '50000')
                {
                  jQuery("#price").val('Any price');
		  jQuery("#price").css({'margin-left':'-40px','width':'60px'});
                }

		jQuery("#from_price_F").val('0');
		jQuery("#to_price_F").val('50000')


        });

      jQuery('#jqModal').jqmShow();

function buildUrl()
{
if (jQuery("#distance2").val() == '200')
{
 jQuery("#distance2").val('');
}

if (jQuery("#price_from").val() == '0')
{
jQuery("#price_from").val('');
}

if (jQuery("#price_to").val() == '50000')
{
jQuery("#price_to").val('');
}


 jQuery("#v2").attr("action","http://v2.motors.co.uk/search.aspx?price="+jQuery("#price_from").val()+","+jQuery("#price_to").val()+'&postcode='+jQuery("#postcode_v2_F").val()+'&distance='+jQuery("#distance2").val());
return true;
}

