/*
 * for inline thickbox implementation
 */
function change_tb_href()
{
  var qString = $("a.thickbox").attr('rel');
  $("a.thickbox").attr('href', '#TB_inline?' + qString);
}

/*
 * auto submit form that has class of "auto" when any select is changed
 */
function form_auto_submit()
{
  $('form.auto select').change(function(){
    // added this to null second select if first is changed
    if (this.id == 'f1') {
      $('select#f2').attr('selectedIndex',0);
    }
    var $form = $(this).parents('form');
    $form.submit();
  });
}


function formMagic()
{
  // remove "required" class on labels
  $('form label.required').removeClass('required');
  // addptional class to input and textarea with value of "optional"
  $("form label.optional ~ input[type=text][value='optional']").addClass('optional');
  $("form label.optional ~ textarea[value='optional']").addClass('optional');
  // look for optional labels that have an empty input field or textarea as sibling
  // and add optional as value to field. remove value of optional on focus
  $("form label.optional ~ input[type=text][value='']").val('optional').addClass('optional').click(function(){
    if (this.value == 'optional') {
      $(this).val('').removeClass('optional');
    }
  }).blur(function(){
    if ($.trim(this.value) == '') {
      $(this).val('optional').addClass('optional');
    }
  });
  // ... and for textarea
  $("form label.optional ~ textarea[value='']").val('optional').addClass('optional').click(function(){
    if (this.value == 'optional') {
      $(this).val('').removeClass('optional');
    }
  }).blur(function(){
    if ($.trim(this.value) == '') {
      $(this).val('optional').addClass('optional');
    }
  });

  // remove field value of optional on submit
  $("form").submit(function(){
    $("form label.optional ~ input[type=text][value='optional']").val('').removeClass('optional');
    $("form label.optional ~ textarea[value='optional']").val('').removeClass('optional');
    return true;
  });

}

function doAction(id) {
	$('#' + id + '_hotspot').toggleClass('js_active');
	$('#' + id + '_thumb').toggleClass('js_active');
	$('#' + id + '_text').toggleClass('txt_active');
}

function doPromo()
{
	var active;
	$("[class~=promo-hover]").hover(
		function() {
			active = $(this).attr('id').split('_');
			doAction(active[0]);
		},
		function() {
			active = $(this).attr('id').split('_');
			doAction(active[0]);
			
		}
		);
}


/* onDocumentReady Call */
$(function(){
  if ($('a.thickbox').hasClass('inline')) {
      change_tb_href();
  }

//  $('.date').datepicker();

//  if (typeof(hoverIntent) != 'undefined') {
//    drop_nav();
//  }

  form_auto_submit();
  doPromo();
//  drop_nav();
  formMagic();

//  $(".fancybox").fancybox({
//    'frameWidth':680,
//    'frameHeight':510,
//    'hideOnContentClick': false
//  });
});


