var arrd = '#sidebar a.icon, #content h2, #content a.callus, #sshow p';

Cufon.replace(arrd,				{ fontFamily: 'Arial_Rounded' });

$(function(){
	$('body').setBodyHt().addClass('js');
	$('#sshow').scroller({
		auto : 'on',				//	Possible values on, off
		animtime : 1000,
		delaytime : 5000
	});
});

(function($) {

	$.fn.dummy = function(){
		if (this.length == 0){
			return $(this);
		}
		return $(this);
	}

	$.fn.scroller = function(dat){
		if (this.length == 0){
			return $(this);
		}
		var loc = {
			count : 0,
			auto : 'off',
			animtime : 1000,
			delaytime : 5000
		};
		loc = $.extend(loc, dat);
		var $sshow = $(this);
		var $slides = $sshow.find('div.slide').wrapAll('<div class="slider"></div>');
		var $slider = $sshow.children('div.slider').wrap('<div class="screen"></div>');
		var $screen = $sshow.children('div.screen');

		loc.slide = {
			wd : $slides.width(),
			num : $slides.length
		};

		$slider.width(loc.slide.wd * loc.slide.num);

		var nextfn = function(){
			loc.count++;
			if (loc.count >= loc.slide.num){
				loc.count = 0;
			}
			$screen.animate({ scrollLeft: loc.count * loc.slide.wd }, loc.animtime);
			return false;
		};

		var prevfn = function(){
			loc.count--;
			if (loc.count <= -1){
				loc.count = loc.slide.num;
			}
			$screen.animate({ scrollLeft: loc.count * loc.slide.wd }, loc.animtime);
			return false;
		};

		$(this).find('a.prev').click(prevfn);
		var $next = $(this).find('a.next').click(nextfn);

		if (loc.auto == 'on'){
			setInterval(function(){
				$next.trigger('click');
			}, loc.delaytime);
		}

		return $(this);
	}

	$.fn.setBodyHt = function(){
		if (this.length == 0){
			return $(this);
		}
		var loc = {};
		loc.docht = $('body').outerHeight();

		var htfn = function(){
			loc.winht = $(window).height();
			if (loc.winht > loc.docht){
				$('body').height(loc.winht - 50);
			}
			else {
				$('body').height('auto');
			}
		}
		htfn();
		$(window).resize(htfn);
		return $(this);
	}

//	LOGGING FUNCTIONS FOR TROUBLESHOOTING

	$.fn.log = function(){
		if (typeof window.console !== 'undefined'){
			console.log($(this));
		}
		return $(this);
	}

	$.log = function(inp){
		if (typeof window.console !== 'undefined'){
			console.log(inp);
		}
		return inp;
	}

})(jQuery);

