/*esteem.js*/


/*
var Esteem =
{
	init:function() {

		// grab the content div
		var content = $('content');
		
		// create a new element called scroll
		var scroll = new Element('div', {id:'scroll'});
		
		// set scroll overflow to hidden
		scroll.setStyle('overflow','hidden');
		
		// fix the stupid ie7 overflow bug
		scroll.setStyle('position','relative');
		
		// place the content div inside of the scroll div
		scroll.wraps(content);
		
		var top = $$('footer a');
		
		top.each(function(element) {
			element.addEvent('click', function(e) { Esteem.move(e, 0); });
		});
		
		
		$('home-button').addEvent('click', function(e) {	Esteem.move(e, 0); });
		$('students-button').addEvent('click', function(e) { Esteem.move(e, -500); });
		$('ministers-button').addEvent('click', function(e) { Esteem.move(e, -1155); });
		$('help-button').addEvent('click', function(e) { Esteem.move(e, -1730); });
		$('contact-label').addEvent('click', function(e) { Esteem.move(e, -2058); });


		
	},
	
	move:function(e, dist) {
		
		// check to see if the button being clicked is a "return to top" link 
		// and check to see if the content has been moved with javascript or not
		if(dist == 0 && $('content').getStyle('margin-top') == '0px') {
			return;
		} else { 
			e = new Event(e);
			$('content').tween('margin-top',dist);
			e.stop();
		}
	}
}
*/


// grab the content div
var $content = $('#content');

// create a div to encapsulate the moving part of the page
$content.wrap("<div id='scroll'></div>");

// set the overflow property to hidden
$('#scroll').css({'overflow':'hidden','position':'relative'});




move = function(e, dist) {

	// when moving the content first check to see if we're trying to return to top
	// and the user has scrolled to the content instead of clicking one of the buttons
	// if this is the case then allow the default behavior (anchor link) to occur
	// otherwise let it rip.

	if(dist == 0 && $content.css('margin-top') == '0px') {
		return;
	} else { 
		e.preventDefault();
		$content.animate({ "margin-top": dist }, 500);
	}
}


// add click events to all return to top links
$('.rtt').click(function(event) { move(event,0) })

// events for each button. theoretically the distance values could be calculated
// dynamically, but i preferred the more discrete positioning allowed by manually
// adjusting the values.
$('#home-button').click(function(event) 		{ move(event, 0); });
$('#students-button').click(function(event) 	{ move(event, -550); });
$('#ministers-button').click(function(event) 	{ move(event, -1225); });
$('#help-button').click(function(event) 		{ move(event, -1810); });
$('#contact-label').click(function(event) 		{ move(event, -2098); });






/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.0.2.1 (22-APRIL-2011)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */


jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
			travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 1000;
				$strip.find("li").each(function(i){
					//alert("this width = " + jQuery(this, i).outerWidth(true) + " current width  " + stripWidth + " == " + (stripWidth + jQuery(this, i).outerWidth(true)));
					//alert(jQuery(this, i).css("margin-right"));
					stripWidth += jQuery(this, i).outerWidth(true) + parseInt(jQuery(this, i).css("margin-right")); // thanks to Michael Haszprunar and Fabien Volpi
				});
				
				
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	

				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				
				function scrollnews(spazio, tempo){
					$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				
				scrollnews(totalTravel, defTiming);				
				
				$strip.hover(function(){
					jQuery(this).stop();
				},
				
				function(){
					var offset = jQuery(this).offset();
					var residualSpace = offset.left + stripWidth;
					var residualTime = residualSpace/settings.travelocity;
					scrollnews(residualSpace, residualTime);
				});			
		});	
};


$(function(){
    $("#ticker").liScroll({travelocity: 0.09});
});
