// JavaScript Document

$(document).ready(function() {
	
	/*-- Text Replacement --*/
	Cufon.replace('h1,h2,h3,.splash-ribbon');
	Cufon.replace('.button-orange,#contact-form .submit',{textShadow: '#b74522 0px 1px'})
	Cufon.replace('.splash-ribbon',{textShadow: '#b74522 0px 1px'})
	Cufon.replace('#navigation li',{textShadow: '#ffffff 0px 1px', hover:true})
	
	/*--jQuery Cycle---------*/
	
	$('#splash-rotator').cycle({
		pager:  '.pagination',
		timeout: 8000
	});
	
	/*--Sticky Float---------*/
	

	$.fn.stickyfloat = function(options, lockBottom) {
		var $obj                 = this;
		var parentPaddingTop     = parseInt($obj.parent().css('padding-top'));
		var startOffset          = $obj.parent().offset().top;
		var opts                 = $.extend({ startOffset: startOffset, offsetY: parentPaddingTop, duration: 200, lockBottom:true }, options);
	
		$obj.css({ position: 'absolute' });
	
		if(opts.lockBottom){
			var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop; //get the maximum scrollTop value
		if( bottomPos < 0 )
			bottomPos = 0;
	}
	
	$(window).scroll(function () {
		$obj.stop(); // stop all calculations on scroll event
		
		var pastStartOffset            = $(document).scrollTop() > opts.startOffset;    // check if the window was scrolled down more than the start offset declared.
		var objFartherThanTopPos    = $obj.offset().top > startOffset;    // check if the object is at it's top position (starting point)
		var objBiggerThanWindow     = $obj.outerHeight() < $(window).height();    // if the window size is smaller than the Obj size, then do not animate.
		
	if( (pastStartOffset || objFartherThanTopPos) && objBiggerThanWindow ){
		var newpos = ($(document).scrollTop() -startOffset + opts.offsetY );
			if ( newpos > bottomPos )
				newpos = bottomPos;
			if ( $(document).scrollTop() < opts.startOffset ) // if window scrolled < starting offset, then reset Obj position (opts.offsetY);
				newpos = parentPaddingTop;
			
				$obj.animate({ top: newpos }, opts.duration );
			}
		});
	};
	$('#sidebar').stickyfloat({ duration: 400 });
	
	/*--classes--*/
	
	$(".item-list li:nth-child(4n)").addClass("end");
	$("#navigation-section li:first").addClass("first");
	$("#navigation-section li:last").addClass("end");
	
});



