//jquery plugin to use a fade effect when toggling 
jQuery.fn.fadeToggle = function(speed, easing, callback)
{
    return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

//causes the testimonials block to be displayed as a rotating slideshow
$(document).ready( 
function()
{
    // other transitions are supported: fade, scrollUp, shuffle, etc... 
    //will pause on hover
    $('#testimonials').cycle(
        {
         fx: 'turnDown', 
         pause: 1, 
         timeout: 8000
         });
    
});

//causes the logos block to be displayed as a rotating slideshow
$(document).ready( 
function()
{
    // other transitions are supported: fade, scrollUp, shuffle, etc... 
    //will pause on hover
    $('#rotatingLogos').cycle(
        {
         fx: 'turnDown', 
         pause: 1, 
         timeout: 4000
         });
    
});


//causes the news block to be displayed as a rotating slideshow
$(document).ready( 
function()
{
    // other transitions are supported: fade, scrollUp, shuffle, etc... 
    //will pause on hover
    $('#sidebarNews').cycle(
        {
         fx: 'fade', 
         pause: 1, 
         timeout: 9000
         });
    
});

//causes the news block to be displayed as a rotating slideshow
$(document).ready( 
function()
{
    // other transitions are supported: fade, scrollUp, shuffle, etc... 
    //will pause on hover
    $('#sidebarEvents').cycle(
        {
         fx: 'fade', 
         pause: 1, 
         timeout: 9000
         });
    
});

$(document).ready(function() {
	// find the button row elements and hook the hover event
	$('.rightbar_buttonrow img').hover(function() {
		var text = this.alt;
        $('#buttonrow_text').html( text ); 
        $('#buttonrow_text').stop().fadeTo( 'fast', 1.0 ); 
        var newsletterblockvisible = $('#newsletterblock').is(":visible");
        if ( this.id != 'newsletterbtn' && newsletterblockvisible )
        {
            toggleNewsletterBlock(); 
        }
		return false; 
       });
 });
 
$(document).ready(function() {
	// find the button row elements and hook the hover event
	$('.rightbar_buttonrow img').mouseout(function() {
		var text = this.alt;
        $('#buttonrow_text').stop().fadeTo( 'fast', 0.001, function() 
            {   
                $('#buttonrow_text').html( '&nbsp;' ); 
            });
       });
 });

$(document).ready(function() {
  $('#header').click( function() { location.href='/'; });
  $('#s').click( function() { return false; } );  
});

//click handler for the "what is your..." elements on the main page.  Toggles children. 
function toggleMainPageChild( childID )
{
	var isHidden = $('#' + childID).is(':hidden');
	var toggleLink = $('#toggle_' + childID)
	if ( toggleLink )
	{ 
		$(toggleLink).html ( ( isHidden ? 'Choose Here &#x25bc;' : 'Choose Here &#x25ba;' ) );
	}
	if ( isHidden )
	{
	   //close anything that's already expanded 
	   for ( var i = 0; i < $('.how_can_ivara_help_sublist').size(); i++ )
	   {
	      var element = $('.how_can_ivara_help_sublist')[i]; 
		  if ( !$(element).is(':hidden') )
		  {
		    toggleMainPageChild( element.id );
		  }
	   }
	}
	$('#' + childID).slideToggle( ( isHidden ? 800 : 400 ) );
	return false; 
}

function toggleNewsletterBlock()
{
	var isHidden = $('#newsletterblock').is(':hidden');
	//source.innerHTML = ( isHidden ) ? 'Sign up here &#x25bc;' : 'Sign up here &#x25ba;';
	$('#newsletterblock').slideToggle( ( isHidden ? 300 : 150 ) );
	return false; 
}

