//Scrolling Sidebar text 
jQuery(function( $ ){
		//borrowed from jQuery easing plugin
		//http://gsgd.co.uk/sandbox/jquery.easing.php

		var shuffled = $('.news-items').find('li').get().slice(0).sort(function(){
			return Math.round(Math.random())-0.5;//just a random number between -0.5 and 0.5
		});
		$(shuffled).appendTo($('.news-items'));
		
		$('.screen').serialScroll({
			target:'.view',
			items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
			prev:'.left',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
			next:'.right',// Selector to the 'next' button (absolute too)
			duration:500,
			constant:false,// Allows the cycle back to start animation to take the same time as item to item animations
			exclude:0
		});
		
	 });



$(document).ready(function()
{
	
//////////////////////////////////////////////////////////////////////////////

	//Expandable Text Toggle
	$('a.expand').click(function() {
		$(this).parent().find(".expandable").slideToggle(1);
		$(this).text($(this).text() == 'More' ? 'Hide' : 'More'); // <- HERE
	   if ($(this).hasClass('more')) 
		{
			$(this).removeClass('more');
			$(this).addClass('back');
		} else {
			$(this).removeClass('back');
			$(this).addClass('more');
		};
		return false;
	});
	
//////////////////////////////////////////////////////////////////////////////

	////Category Page Accordion Text
	$categories = $('ul.tips-list > li')
	$categories.each(function() {
		$(this).find('h3').each(function() {
			$(this).click(expand);
		});
	});
	
	function expand() {
		if ($(this).parent().find("ul.expandable").is(":visible")) {
			$(this).parent().find("ul.expandable").slideUp(400);
			$(this).parent().addClass('closed');
		} else {
			$categories.each(function() {
				if ($(this).hasClass('expandable')) {
					$(this).find("ul.expandable").slideUp(400);
					$(this).addClass('closed');
				}
			});
			
			$(this).parent().removeClass('closed');
			$(this).parent().find("ul.expandable").slideDown(400);
		}
	}
	
	//Forwards & backwards skip functionality
	
	function skip(inst, forwards) {
		$li = $(inst).parents('li.expandable')
		$ul = $(inst).parents('ul.expandable')
											   
		$ul.slideUp(400);
		$li.addClass('closed');
		
		if (forwards) {
			$li.next().removeClass('closed');
			$li.next().find('ul.expandable').slideDown(400);
		} else {
			$li.prev().removeClass('closed');
			$li.prev().find('ul.expandable').slideDown(400);
		}
	}
	
	$('ul.tips-list li a.forwards').click(function() {
			skip(this, true);
	   });
	
	$('ul.tips-list li a.backwards').click(function() {
			skip(this, false);
	   });
	


//////////////////////////////////////////////////////////////////////////////

	//Gallery Navigation
		var img_divs = $("#content-main div.img-bg");
		var active_a = $("ul#gallery li a");
		img_divs.hide();
		
		if (img_divs.length > 0 ) {
			$(img_divs[0]).show();
		}
		
		$('ul#gallery li a').each(function(i) {
			$(this).click(function() {										   
				img_divs.hide();
				active_a.removeClass("active");
				$(img_divs[i]).show();
				$(active_a[i]).addClass("active");
		   });
		});

	
//////////////////////////////////////////////////////////////////////////////	

 });
