// JavaScript Document

$(document).ready(function(){
	
	if($("#ts-jquery-gallery-pi1-scroller").length && $("#ts-jquery-gallery-pi1-pane > ul").length && $("#ts-jquery-gallery-pi1").length) {
    	
		$("#ts-jquery-gallery-pi1").tabs({ fx: { opacity: 'toggle' } });
		
		var ul = $("#ts-jquery-gallery-pi1-pane > ul");
		var w = $("#ts-jquery-gallery-pi1-scroller").outerWidth();
		
		if(ul.innerWidth() <= w) {
			$("#ts-jquery-gallery-pi1-scroller").hide();
		}
		
		$('#ts-jquery-gallery-pi1-scroller > div').css('width', (w * (w / ul.innerWidth())) + 'px');
		
		$("#ts-jquery-gallery-pi1-scroller").slider({
			minValue: 0,
			maxValue: ul.innerWidth() - w,
			slide: function (ev, ui) {
				ul.css('left', '-' + ui.value + 'px');
			},
			stop: function (ev, ui) {
				ul.animate({ 'left' : '-' + ui.value + 'px' }, 1000, 'easeOutExpo');
			}
		});
	}
	
	
	reloadScroller2();

});

function reloadScroller2() {

	if($("#content-normal-inner").length && $("#content-scroller").length) {
		
		var c = $("#content-normal-inner");
		var h = $("#content-scroller").outerHeight();
		
		if(c.innerHeight() <= h) {
			$("#content-scroller").hide();
		}
		
		$('#content-scroller > div').css('height', (h * (h / c.innerHeight())) + 'px');
		
		$("#content-scroller").slider({
			minValue: 0,
			maxValue: c.innerHeight() - h + 20,
			slide: function (ev, ui) {
				c.css('top', '-' + ui.value + 'px');
			},
			stop: function (ev, ui) {
				c.animate({ 'top' : '-' + ui.value + 'px' }, 1000, 'easeOutExpo');
			}
		});
		
	}
}
