/* List Ticker by Alex Fish 
// www.alexefish.com
//
// options:
//
// effect: fade/slide
// speed: milliseconds
// run_once: boolean
*/

(function($){
  $.fn.list_ticker = function(options){
    
    var defaults = {
      speed:4000,
	  effect:'slide',
	  run_once:false
    };
    
    var options = $.extend(defaults, options);
    
    return this.each(function(){
      
      var obj = $(this);
      var list = obj.children();
      var count = list.length - 1;

      list.not(':first').hide();
      
      var interval = setInterval(function(){
        
        list = obj.children();
        list.not(':first').hide();
        
        var first_li = list.eq(0)
        var second_li = list.eq(1)
		
		if(options.effect == 'slide'){
			first_li.slideUp();
			second_li.slideDown(function(){
				first_li.remove().appendTo(obj);
				
			});
		} else if(options.effect == 'fade'){
			first_li.fadeOut(function(){
				obj.css('height',second_li.height());
				second_li.fadeIn();
				first_li.remove().appendTo(obj);
			});
		}
		
		count--;
		
		if(count == 0 && options.run_once){
			clearInterval(interval);
		}
		
      }, options.speed)
    });
  };
})(jQuery);


// custom jquery for PFRA
$(function(){
    $('a[rel=external]').attr('target','_blank');  
    $('#twitter ul').list_ticker({
			speed:7000,
			effect:'fade'
		});
	if( $('#twitter_update_list').length > 0 ) {
		$(this).find('a').attr('target', '_blank');
	}
});


/* quote rotation timer */
function rotateQuotes( element ) {
	t = setTimeout( "changeQuote("+ element +")", timer );
}


/* change the quote text on the front page with fade */
function changeQuote( element ) {

	if( element==quoteBank.length )
		element = 0;
		
	$('div.didyouknow').find('blockquote.ontop').fadeOut("slow", function() {				
			$('blockquote.ontop').html(quoteBank[ element ]); 
			$('blockquote.ontop').fadeIn("slow");  
    });
	nextelement = element+1; 
	rotateQuotes( nextelement ); 
}

    /* rotation timer */
    timer = 3000; // 3 seconds

    /* handle the quotes for the front page and rotate....*/
    quoteBank = new Array(); var j=0; 
	
    $('div.didyouknow').find('blockquote.quotebank').each(function (i) {
			quoteBank[j] = $(this).html(); 
			j++;
    });
	
	if( quoteBank.length > 1 )
		rotateQuotes( 0 ); 


jQuery(document).ready(function() {
// -- fancybox
$("a[rel=example_ef]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    //return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		    return '<span id="fancybox-title-over">'+title+'</span>';
		}
	});
});

