jQuery.fn.hscroll = function(options){
	options = jQuery.extend({ammount: 25, speed: 250},options);
	return this.each(function(){
		this.options = options;

		$(this).wrapInner("<div class='hscroll-wrap'></div>");
		$(this).append('<div class="hscroll-controller">'+
				'<a class="scrollup"><img src="public/images/scroll-up.gif" alt="" /></a>'+
				'<a class="scrolldown"><img src="public/images/scroll-down.gif" alt="" /></a>'+
				'</div>');
		var self = this;
		$('a.scrollup',this).click(function(){ $(self).scroll_do(1); });
		$('a.scrolldown',this).click(function(){ $(self).scroll_do(-1); });
	});
};

jQuery.fn.scroll_do = function(sigma){
	return this.each(function(){

		var trg = jQuery('.hscroll-wrap',this)[0];

		var h = jQuery(this).height(); // container height
		var h2 = jQuery(trg).height(); // inner height
//		console.log("h2:"+h2+"; h1:"+h);
		var yoffset = this.options.ammount * sigma;
		var newy = trg.offsetTop + yoffset;
//			console.log("yoffset:"+yoffset+"; newy:"+newy);
		var max = 0; var min = -(h2-h);
//			console.log("min:"+min+" ;max:"+max);
//			console.log("--------------");
		if (( newy < max ) && ( newy > min))
		{
			newy = newy;
		}else{
			if ( newy > max ){
				newy = max;
			}else{
				newy = min;
			}
		}

		jQuery(trg).animate({top: newy+"px"}, this.options.speed);
	});
};

jQuery.fn.y = function(n) {
     var result = null;
     this.each(function() {
         var o = this;
         if (n === undefined) {
             var y = 0;
             if (o.offsetParent) {
                 while (o.offsetParent) {
                     y += o.offsetTop;
                     o = o.offsetParent;
                 }
             }
             if (result === null) {
                 result = y;
             } else {
                 result = Math.min(result, y);
             }
         } else {
             o.style.top = n + 'px';
			 result = jQuery(this);
         }
     });
     return result;
};

// */
