	var dir = 'left';
	var dis = 10;
	var distime_init = 300;
	var expansion = 20;
	var expansiontime = 200;
	var acceleration = 3;
	var deceleration = 0.3;
	var frameleft = 0;
	var frameright = 0;
	var distime = distime_init;
	var ulwidth = 0;


$(document).ready(function(){
	jQuery.event.add(window, "load", function($) {
		inforinit();
	});
});

function inforinit() {
	var PATHNAME = location.pathname;

	if ($("#scrollgallery").size() == 1) {
		scg_init();
	}

}


function scg_init () {


	frameleft = $("#scrollWrapper").offset().left;
	frameright = $("#scrollWrapper").outerWidth() + frameleft;
	$("#scrollWrapper ul li").each(function(idx) {
		ulwidth += $(this).outerWidth();
	});
	$("#scrollWrapper ul").width(ulwidth * 2);

$("#allowleft").hover(
	function() {
		dir = 'left';
		distime = distime_init / acceleration;
	},
	function() {
		distime = distime_init;
	}
);
$("#allowright").hover(
	function() {
		dir = 'right';
		distime = distime_init / acceleration;
	},
	function() {
		distime = distime_init;
	}
);
$("#scrollWrapper ul li img").hover(function() {hovon($(this))},function() {hovoff($(this))});


	if ($("#scrollWrapper").outerWidth({margin: true}) + 20 < ulwidth) {
		scg_slide();
	}

}

function scg_slide() {

	if (dir == 'left') {
//		for (;;) {
			var firstli = $("#scrollWrapper ul li:first");

			if (frameleft - firstli.offset().left > firstli.outerWidth({margin: true})) {

				var trimliwidth = firstli.outerWidth({margin: true});
				var firstlihtml = firstli.html();
				firstli.remove();
				$("#scrollWrapper ul").append('<li>' + firstlihtml + '</li>');
				$("#scrollWrapper ul").animate( {left: '+=' + trimliwidth + 'px'}, 0 ,"linear");
				$("#scrollWrapper ul li:last img").bind('mouseover',function() {hovon($(this))}).bind('mouseout',function() {hovoff($(this))});
			}
			else {
//				break;
			}
//		}
		$("#scrollWrapper ul").animate( {left: '-=' + dis + 'px'}, distime ,"linear",scg_slide);
	}
	else if (dir == 'right') {
//		for (;;) {
			var lastli = $("#scrollWrapper ul li:last");
			if (frameright - lastli.offset().left < 0) {
				var trimliwidth = lastli.outerWidth({margin: true});
				var lastlihtml = lastli.html();
				lastli.remove();
				$("#scrollWrapper ul").prepend('<li>' + lastlihtml + '</li>');
				$("#scrollWrapper ul").animate( {left: '-=' + trimliwidth + 'px'}, 0 ,"linear");
				$("#scrollWrapper ul li:first img").bind('mouseover',function() {hovon($(this))}).bind('mouseout',function() {hovoff($(this))});
			}
			else {
//				break;
			}
//		}
		$("#scrollWrapper ul").animate( {left: '+=' + dis + 'px'}, distime ,"linear",scg_slide);
	}
}
function hovon(thisobj) {
//    thisobj.animate( {marginTop: '-=' + expansion/2 + 'px',height: '+=' + expansion + 'px'}, expansiontime);
	distime = distime_init / deceleration;
}
function hovoff(thisobj) {
//    thisobj.animate( {marginTop: '+=' + expansion/2 + 'px',height: '-=' + expansion + 'px'}, expansiontime);
	distime = distime_init;
}


