$(document).ready(function() {
  $("div.warning").fadeIn(2000).animate({opacity: 1.0}, 3000).fadeOut(1000, function() { $(this).remove(); } ); 
	$(".fadeIn").hide().fadeIn(1500);
	$(".fadeInSlow").hide().fadeIn(2500);

  $("div.round").corner("6px");


// --------------------------------------------------------
// Main Nav line slider
// --------------------------------------------------------


// --------------------------------------------------------
// Forgot password reset
// --------------------------------------------------------

  $.fn.finishAjax = function(id, response){
  $('#usernameLoading').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}

	$('#usernameLoading').hide();
	$('#fld_email_work').blur(function(){
	  $('#usernameLoading').show();
      $.post("/pub/check_email.php", {
        email: $('#fld_email_work').attr('value')
      }, function(response){
        $('#usernameResult').fadeOut();
        setTimeout("$(this).finishAjax('usernameResult', '"+escape(response)+"')", 600);
      });
    	return false;
	});

// --------------------------------------------------------
// Slide Show
// --------------------------------------------------------

// set container width
var pagerCount = $('#slideshow').attr("count");  
var pagerDivWidth = (pagerCount * 26);
$("#pager").width(pagerDivWidth);

//    $('#slideshow').after('<div id="pager">').cycle({
    $('#slideshow').after('').cycle({
      speed:5000,
      speedIn:500,
      speedOut:1000,
      timeout:2000,
      prev:   '#prev', 
      next:   '#next',      
      pager: '#pager',
      fastOnEvent: true,      
      sync: 1,
      delay:1000,
      // callback fn that creates a thumbnail to use as pager anchor 
      pagerAnchorBuilder: function(idx, slide) { 
        var imgalt = $(slide).children().eq(0).attr("alt");
        if (imgalt == null ) { imgalt = slide.alt; }
        return '<div id="banner_0' + idx + '" class="pager_box"><a href="#"><img src="/img/raven/pager_box.png" width="78" height="25" /></a></div>'; 
      }
      //after: onAfter
    }); 


  $('#slideshow_interior').cycle({
      speedIn:2500,
      speedOut:1500,
      sync: 1,
      delay:-1000
    });    

//	$("#stage_content_wide").fadeIn(900).animate({opacity: 1.0}, 2);
// { fx: 'scrollHorz', timeout:  2000, autostop: 1, end: function() { alert('The slideshow has ended.'); } }  
  
  $('#toggle').click(function(){
   $('div.showhide').slideToggle();
  });
  

/*
  $("[title]").mbTooltip({          // also $([domElement])..mbTooltip  >>  in this case only children element are involved
    opacity : .97,                  //opacity
    wait:1200,                      //before show
    cssClass:"default",             // default = default
    timePerWord:70,                 //time to show in milliseconds per word
    hasArrow:true,			            // if you whant a little arrow on the corner
    imgPath:"/img/tooltips/",
    ancor:"mouse",                  //"parent"  you can ancor the tooltip to the mouse position or at the bottom of the element
    shadowColor:"black"             //the color of the shadow
  });
*/  

  // contact form
  $('#form_contact').ajaxForm(function(data) {
    if (data==1){
      $('#success').fadeIn("slow");
      $('#form_contact').resetForm();
    } else {
      $('#errormsg').html(data).fadeIn("slow");
    }
  });
  

// --------------------------------------------------------
// Box Grid (Staff Listing Page)
// --------------------------------------------------------
  var currentTallest = 0,
     currentRowStart = 0,
     rowDivs = new Array(),
     $el,
     topPosition = 0;

 $('.blocks').each(function() {
  
   $el = $(this);
   topPostion = $el.position().top;

   if (currentRowStart != topPostion) {

     // we just came to a new row.  Set all the heights on the completed row
     for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
       rowDivs[currentDiv].height(currentTallest);
     }

     // set the variables for the new row
     rowDivs.length = 0; // empty the array
     currentRowStart = topPostion;
     currentTallest = $el.height();
     rowDivs.push($el);

   } else {

     // another div on the current row.  Add it to the list and check if it's taller
     rowDivs.push($el);
     currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);

  }

  // do the last row
   for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
     rowDivs[currentDiv].height(currentTallest);
   }

 });
 
});
