twttr.anywhere(function (T) {
	T.hovercards();
});

$(document).ready(function() {
	
	var hoverTimer;
	
	$('.widget_twitter').bind('mouseover', function() {
		
		hoverTimer = window.setTimeout(function() {
			if ( $('#twitter_timeline').is(':hidden') ) {
				$('#twitter_timeline').fadeIn('fast',function(){
					twttr.anywhere(function (T) {
						T('#follow-twitterapi').followButton("jj_jiles");
						T.hovercards();
					});
					
					/* ****************************************
					* START :::
					* Vertical tabs slide back if anything
					* but the tab is clicked               */				
					$(document).bind('click', function(e) {
						var $clicked=$(e.target); // get the element clicked			
						var $par = $(e.target).parent().attr('class');
						
						if ( ! ( $clicked.isChildOf('.widget_twitter') )) {
							$('#twitter_timeline').fadeOut('fast',function() {
								$('#follow-twitterapi').html('');
							});
						}
					});
					
					$().removeFilter(this);
					
				});
			}
		}, 500);
		
		$('.widget_twitter').bind('mouseout', function() {
			window.clearTimeout(hoverTimer);
		});
	});
	
	
	var accordion = {
		parent      : '.accordion-item',
		header      : '.accordion-header',
		collapsible : '.accordion-collapsible'
	};

        /* ***
        * hide all collapsible items */
        $(accordion.collapsible).css('display','none');
	
	/* ****
	* bind the accordion header click event */
	$(accordion.header).unbind('click');
	$(accordion.header).bind('click', function() {
		var header_obj      = $(this);          // The current header
		var next_parent_obj = $(this).parent(); // The parent of the header
		
		var content_obj = $(this).siblings(accordion.collapsible); // find the collapsible element
		
		if(content_obj.is(":hidden")) {
			// collapse all collapsible elements
			next_parent_obj.siblings(accordion.parent).each(function() {
				$(this).children(accordion.collapsible).slideUp('fast');
			});
			// show the content of the clicked header
			content_obj.slideDown('fast');
		} else {
			content_obj.slideUp('fast');
		}
	});
	
	
	   
	   
	
	/* ************************************
	* only initiate the tab function if tabs are preset */
		if ( $('#tabs').length > 0 ) {
		   tabs.init();
		}
	   
	if ( $('#selected-categories').length > 0 ) {
		ls.init({
			_variable      : '#selected-categories',
			_clickable     : 'li',
			_update_list   : true,
			_constant      : '#all-categories'
		});
	}
	   
	if ( $('#selected-categories-single').length > 0 ) {
		ls.init({
			_variable      : '#selected-categories-single',
			_clickable     : 'li',
			_update_list   : false
		});
	}
	
	 $('a[rel*=facebox]').facebox();

});
