Cufon.replace('h1',{fontFamily:'Gill Sans'});
Cufon.replace('.header_box1 h2',{fontFamily:'Gill Sans'});
Cufon.replace('.selectoffice',{fontFamily:'Gill Sans'});
Cufon.replace('.blue_band',{fontFamily:'Gill Sans'});



function clearText(field){

	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;

}


/**
 * Function to select and remember office
 */
function selectOffice() {
  var t = $(this).text();

  // Set cookie
  $.cookie('office', t, { expires: 7, path: '/'});
}

/**
 * Auto-redirect to correct homepage
 */
function officeRedirect(e) {

  var h = $(this).attr('href');

  // Check for Chepstow office cookie and that a homepage link was clicked
  if($.cookie('office') == 'Chepstow' && (h=='home' || h=='index.php/home' || h=='#')) {
    e.preventDefault();
    
    // Figure out redirect link
    var redirect = location.href.match('index.php') ? 'index.php/chepstow-home' : 'chepstow-home';
    location.href = redirect;
    return false;
  }

  return true;
}


/**
 * Select nav tab
 */
function selectNavTab() {
  if(location.href.match('chepstow-home')) {
    $('ul.nav li:first-child').addClass('selected');
  }
}

/**
 * Add body class
 */
function addBodyClass() {
  $('body').addClass($.cookie('office'));
}


function fixHomeBoxes() {
  $('div#homeboxes').children('div').each(function(i, item) {
    var n = i+1;
    $(this).attr('class', $(this).attr('class').replace(1, n));
    $(this).find('a.blue_band').addClass('blue_band' + n);
  });
}

$(function() {

  // Fix CSS styles on home boxes
  fixHomeBoxes();

  // Select office
  $('.selectoffice a').click(selectOffice);
  $('a').click(officeRedirect);
  selectNavTab();
  addBodyClass();

  $('br.linebreak').replaceWith('<div class="linebreak"></div>');

  $('#homegallery').cycle({timeout : 7000});

  if(typeof($.fn.placeholder) == 'function') {
    $(':input').placeholder();
  }


})
