//*****Replace align attribute with class**************************************************//
function replaceAlign() {
  if (!document.getElementsByTagName('img')) return false;
  $('img[align="left"]').addClass('left').removeAttr('align');
  $('img[align="right"]').addClass('right').removeAttr('align');
  $('img[align="middle"]').addClass('middle').removeAttr('align');
}
//*****Replace target attribute with class**************************************************//
function replaceTarget() {
  if (!document.getElementsByTagName('a')) return false;
  $('a[target]').addClass('newwindow').removeAttr('target');
}
//*****The following function make it possible to have web standard popups**************************************************//
function strictNewWindow() {
  if (!document.getElementsByTagName('a')) return false;
  $('a.newwindow').click(function() {
    window.open($(this).attr('href'));
    return false;
  });
}
//*****Add swfobject flash call**************************************************//
function initializeFlash() {
  if (!document.getElementById('flash-content')) return false;
  var flashvars = {};
  var params = {wmode: 'transparent'};
  var attributes = {};
  attributes.id = "flash";
  swfobject.embedSWF("/pces/swf/banner-flash-home.swf", "flash-content", "960", "338", "8.0.0", "/pces/swf/expressInstall.swf", flashvars, params, attributes);
}
//*****jQuery clear value from july 21st 2009 comment on http://www.joesak.com/2008/11/19/a-jquery-function-to-auto-fill-input-fields-and-clear-them-on-click*****//
function clearDefaultValue() {
  $(':input').focus(function() {
    if($(this).val() == $(this).attr('title')) {
      $(this).val('');
    }
  }).blur(function() {
    if($(this).val() == '') {
      $(this).val($(this).attr('title'));
    }
  });
  $('#btnNext').click(function() {
	  $(':input').each(function (i) {
      if($(this).val() == $(this).attr('title')) {
        $(this).val('');
      }
    });
  });
}
function populateDefaultValues(){
  $(':input').each(function(){
    if($(this).val() == ''){
      $(this).val($(this).attr('title'));      
    }
  });
}
//*****Extend the footer to the bottom of the page**************************************************//
function extendFooter() {
  var footerHeight = $('#footer').height();
  var pageHeight = $(document.body).height();
  var windowHeight = $(document).height();
  var difference = windowHeight - pageHeight;
  if (pageHeight < windowHeight) {
    $('#footer').height(footerHeight + difference);
  } else {
    $('#footer').height('auto');
  }
}
//*****IE rounded corners from http://dillerdesign.com/experiment/DD_roundies/**************************************************//
function rounded() {
  DD_roundies.addRule('#header ul#headerNav li ul', '0 0 5px 5px');
  DD_roundies.addRule('#sidebar ul#sidebarNav,#sidebar .upcomingEvents', '0 0 10px 0');
}
//*****Load all functions**************************************************//
$(document).ready(function(){
  replaceAlign();
  replaceTarget();
  strictNewWindow();
  initializeFlash();
  clearDefaultValue();
  extendFooter();
  rounded();
});
//$(window).resize(function(){
//  extendFooter();
//});
