
$(document).ready(function()
{

	$("#nav li.sliding-element").click(function(){$("html, body").animate({scrollTop:0}, "slow"); return false;});	
//	$("#nav a").click(function(){$("#s7").animate({scrollTop:0}, "slow"); return false;});	

	slide("#nav", 25, 15, 150, .8);
	
	$("#topnav li.normal").prepend("<span></span>"); //Throws an empty span tag right before the a tag
	
	$("#topnav li.normal").each(function() { //For each list item...
		var linkText = $(this).find("a").html(); //Find the text inside of the a tag
		$(this).find("span").show().html(linkText); //Add the text in the span tag
	}); 
	
	$("#topnav li.normal").hover(function() {	//On hover...
		$(this).find("span").stop().animate({ 
			marginTop: "-40" //Find the span tag and move it up 40 pixels
		}, 250);
	} , function() { //On hover out...
		$(this).find("span").stop().animate({
			marginTop: "0" //Move the span back to its original state (0px)
		}, 250);
	});

    $("#contention").fortune({file: "./contentions.json", cookieNode: "contentions", metaNodes: {theIndex: "index", theContent: "content"}, animate: true});

    $('#another').click(function() {
        $("#contention").fortune({file: "./contentions.json", cookieNode: "contentions", metaNodes: {theIndex: "index", theContent: "content"}, animate: true});
        return false;
    });
	
		
});

function slide(navigation_id, pad_out, pad_in, time, multiplier)
{

	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	//	var timer = 0;
	
	// creates the slide animation for all list elements 
	//	$(list_elements).each(function(i)
	//	{
		// margin left = - ([width of element] + [total vertical padding of element])
	//		$(this).css("margin-left","-180px");
		// updates timer
	//		timer = (timer*multiplier + time);
	//		$(this).animate({ marginLeft: "0" }, timer);
	//		$(this).animate({ marginLeft: "15px" }, timer);
	//		$(this).animate({ marginLeft: "0" }, timer);
	//	});

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, 150);
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, 150);
		});
	});
	
}

$('#s7').cycle({ 
    fx:     'scrollHorz', 
    speed:  'slow', 
    timeout: 0, 
    pager:  '#nav', 
    after: onAfter,
    pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#nav li:eq(' + idx + ') a'; 
    }     
}); 
 
function onAfter(curr, next, opts, fwd) {
var index = opts.currSlide;
$('#prev')[index == 0 ? 'hide' : 'show']();
$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
//get the height of the current slide
var $ht = $(this).height() + 320;
//var $ht = $(this).height();

//set the container's height to that of the current slide
$(this).parent().css("height", $ht);
}

