// Madeira Real Estate

var $j = jQuery.noConflict();

function equalHeight(group) {
  tallest = 0;
  group.each(function() {
    thisHeight = $j(this).height();
    if(thisHeight > tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
}

$j(document).ready(function() {

  if( $j('#footbar .col').length > 0 ) {
    equalHeight($j('#footbar .col'));
  }

  var ch = $j('.col-b').height();

  if( $j('.col-c').height() > ch) {
    ch = $j('.col-c').height();
  }

  if( $j('.col-a').height() < ch ) {
    $j('.col-a').height(ch+20);
  }

  if( $j('div.gallery a').length > 0 ) {
    $j('div.gallery a').attr({ rel: '[slide]' });
    $j('div.gallery a').prettyPhoto();
  }

  if( $j('form#newsletter').length > 0 ) {
    $j('form#newsletter').submit(function(){
      $j(this).attr({ target:'popupwindow' });
      window.open('http://feedburner.google.com/fb/a/mailverify?uri=Madeira_Property',
                  'popupwindow',
                  'scrollbars=yes,width=550,height=520');
      return true;
    });
  }

  if( $j('form#searchform').length > 0 ) {
    var s = 'Search here';
    $j('form#searchform input#s').val(s)
                                 .focus(function(){
                                   if($j(this).val() == s) $j(this).val('');
                                 })
                                 .blur(function(){
                                   if(!$j.trim($j(this).val())) $j(this).val(s);
                                 });
  }

  if( $j('form.contact-form').length > 0 ) {
    var fieldset = $j('form.contact-form fieldset:last');
    $j('legend, div.form-label, div.form-input', fieldset).hide();
    $j('div.form-input input', fieldset).val('Portugal');
    fieldset.addClass('no-border');

    var query = $j.url.parse(window.location);
    if(query.params.subject.length > 0 && $j('form.contact-form input#ec_subject').val().length < 1) {
        $j('form.contact-form input#ec_subject').val(query.params.subject);
    }
  }

});