/*******************************************************************************

	CSS on Sails Framework
	Title: Pheonix Te
	Author: XHTMLized (http://www.xhtmlized.com/)
	Date: August 2011

*******************************************************************************/

$(document).ready(function() {

	// Image toggle
	$(".expand").hide();
	$(".less").hide();

	$(".toggle").toggle(
		function(){
			$(this).find("a.more").hide();
			$(this).find("a.less").show();
			$(this).prev().animate({ height: 'show', opacity: 'show' }, 1000);   
		},
		function(){
			$(this).find("a.less").hide();
			$(this).find("a.more").show();
			$(this).prev().animate({ height: 'hide', opacity: 'hide' }, 1000);   
		}
	);

	$("a.less").click(
		function(){
			$("a.less").hide();
			$("a.more").show();
			$(".toggle").prev().animate({ height: 'hide', opacity: 'hide' }, 1000);
			$.scrollTo($(this).parent().parent(), 1000);
			return false;
		}
	); 

	$(".slider .caption h2 a").click(function(){
		$(this).attr('target','_blank');
	});

	var full_url = document.URL; 
	var url_array = full_url.split('#'); 
	var last_segment = url_array[url_array.length-1];
	$("li#"+last_segment+" .expand").css("display", "block");
	$("li#"+last_segment+" .more").css("display", "none");
	$("li#"+last_segment+" .less").css("display", "inline");
	
	// slider
    $('.slider').cycle({
        slideExpr: 	'li',
        fx:      	'scrollHorz',
        timeout:  	0,
        speed:		330,
        prev:    	'.slide-nav .prev',
        next:    	'.slide-nav .next'
    });	

});

$(document).keydown(function(e){
    if ($('.slider').length > 0) {
      if (e.keyCode == 37) { 
         $('.slider').cycle('prev');
         return false;
      }
      if (e.keyCode == 39) { 
         $('.slider').cycle('next');
         return false;
      }
    }
});
