/**
 * HORIZON.js
 * http://horizondisplay.com
 * 
 * Last Updated: 2011-07-16
 * Author: Mark Nauroth
 * 
 * Functions that are required on most pages.
 * 
 */

$(function(){
	
	/******* HELP BAR ********/
	
	function show_help() {
		// Grow the helper bar
		$('#help_bar').animate({
			'height':'250px'
		}, 350);
		
		// Fade in the bar contents 
		$('#help_bar .wrap').fadeIn('350');
	}
	
	function hide_help() {
		// Fade out the bar contents
		$('#help_bar .wrap').fadeOut('350');
		
		// Return the helper bar to its original height
		$('#help_bar').animate({
			'height':'5px'
		}, 350);
		
	}
	
	// Bind the toggle actions to the help button
	$('#help_tab a').toggle(show_help, hide_help);
	
	
	/******** MORE FEATURED CONTENT **********/
	
	function more_featured() {
		// Change the text of the trigger
		$(this).text('less');
		
		// Show the additonal content
		$('#feature #more').slideDown();
	}
	
	function less_featured() {
		// Return the trigger text to default (only if it has been changed)
		if ($(this).text != 'read more') {
			$(this).text('read more');
		}
		
		// Hide the additional content
		$('#feature #more').slideUp()
	}
	
	// Bind the toggle actions to the read more button
	$('#feature #read_more').toggle(more_featured, less_featured)
	
	// Trigger the read more anchor when the read less anchor is clicked
	$('#feature #read_less').click(function(){
		//$(this).rotateRight();
		
		$('#feature #read_more').trigger('click');
	});
	
	
	
	/******** NEWS TICKER ********/
	// jQuery tools vertical scrollable
	if ($('#ticker').length > 0) {
		var ticker = $('#ticker').scrollable({
			vertical: true,
			circular: true
		}).autoscroll({
			interval: '5000'
		}).data('scrollable');
	}
	
	
	/******* NAVIGATION ********/
	function nav_over() {
		// Only show the hover styles if there's a sub-menu
		var sub = $(this).find('.sub');
		if (sub.length > 0) {
			// Apply the active class to the anchor
			$(this).find('a').addClass('active');
			
			// Show the sub-menu
			sub.fadeIn('fast');
		}
	}
	
	function nav_out() {
		// Remove the active class from the anchor
		$(this).find('a').removeClass('active');
		
		// Hide the sub-menu
		var sub = $(this).find('.sub');
		sub.fadeOut('fast');
	}
	
	var nav_config = {
		over: nav_over,
		timeout: '100',
		out: nav_out	
	}
	
	$('#primary > li').hoverIntent(nav_config);
	
	
	
});
