/**
* @author Nathan Letsinger
*
* Loader.js is for site-wide javascript that initiates when the document is loaded
* i.e. the ready() event in jquery.
*/






$(document).ready(function(){
	
//----------------------------------------------------------------------------------//
//  SUPERFISH MENU BEHAVIORS (main horizonal menu)
//----------------------------------------------------------------------------------//
	
	$('ul.nav').superfish({
	pathClass : 'current',
	animation : {opacity:'show'},
	delay : 50
	});
	
	
	
//----------------------------------------------------------------------------------//
//  SEARCH MENU BEHAVIORS
//----------------------------------------------------------------------------------//
	
    // if form input is pre-populated, we should show the menu
    if ($("div#search_form :input[value !='']").length){
        $('div#search_form').show();
        $('a#search_options').text('Hide options');
    } else {
       $('div#search_form').hide();
       $('a#search_options').text("Search options");
    }

	$('a#search_options').click( function(){
		$txt = $(this).text();
		if ($txt == "Search options"){ 
			$txt = "Hide options"; 
		} else { 
			$txt = "Search options"; }
		$(this).text($txt);

        $('div#search_form').slideToggle();
	});
	

//----------------------------------------------------------------------------------//
//  MODAL WINDOW BEHAVIORS
//----------------------------------------------------------------------------------//
	
	
			/* Overriding Javascript's Confirm Dialog */
			// NOTE; A callback must be passed. It is executed on "continue". 
			//  This differs from the standard confirm() function, which returns
			//   only true or false!
			
			// If the callback is a string, it will be considered a "URL", and
			//  followed.
			
			// If the callback is a function, it will be executed.
			
			/*
			function modal_confirm(msg,callback) {
			  $('#confirm')
			    .jqmShow()
			    .find('p.jqmConfirmMsg')
			      .html(msg)
			    .end()
			    .find(':submit:visible')
			      .click(function(){
			        if(this.value == 'yes')
			          (typeof callback == 'string') ?
			            window.location.href = callback :
			            callback();
			        $('#confirm').jqmHide();
			      });
			}
			
			*/
		
			
		
	
	
//----------------------------------------------------------------------------------//
//  GLOBAL FORM BEHAVIORS
//----------------------------------------------------------------------------------//
	
	// 
	//On focus remove default value of textarea unless it has the class "noclear"
	//	
	$("textarea[class!=noclear]").focus(function(){
		$(this).val('');
	});


	
	//  used by FAL flashMsg() helper to display a message stored in the session to user, then sideUp. 
     $("div#flashMessage").show('normal',
        function()
        {
            $("div#flashMessage.slideUp").slideUp(4000);
            $("div#flashMessage.fadeOut").fadeOut(4000);
        }
        					);  
   
      
//----------------------------------------------------------------------------------//
//  GLOBAL ANCHOR BEHAVIORS
//----------------------------------------------------------------------------------//
	
	// provokes a confirmation window populated with the value of the link's title attribute.
	$("a.confirm , input.confirm:submit").click(function() {
		if (confirm( $(this).attr("title") )) {
			return true;
		}else{
			return false;
		}
	});
     



//----------------------------------------------------------------------------------//
//  GLOBAL TABLE BEHAVIORS
//----------------------------------------------------------------------------------//

	// used to make entire table rows clickable 
	// @param `rel` attribute is controller/method uri
	// @param `id` attribute is the variables

    $("tr.clickable").click(function () { 
    location.href = $(this).attr("rel")+'/'+$(this).attr("id"); 
    })
    $("tr.clickable").hover(function () {
      $(this).addClass("hilite");
    }, function () {
      $(this).removeClass("hilite");
    });
 
 
  });
