/*
	Anti Sweden functions library
*/

function getFeatures(obj_suffix) {
	var features = '';

	if ($('#fvalset' + obj_suffix).length) {
		features = $('#fvalset' + obj_suffix).val();
	}
	return features;
}

/* *** */

function handleChangeABO(e, ui) {
	var maxScroll = $("#a_b_o_scroller").attr("scrollHeight") - $("#a_b_o_scroller").height();
	jQuery('#a_b_o_scroller').stop(true, true);
	$("#a_b_o_scroller").animate({ scrollTop: maxScroll * (1 - ui.value / 100) }, 800);
}

function handleSlideABO(e, ui) {
	var maxScroll = $("#a_b_o_scroller").attr("scrollHeight") - $("#a_b_o_scroller").height();
	$("#a_b_o_scroller").attr({ scrollTop: maxScroll * (1 - ui.value / 100) });
}

function initABOScroller() {
	$("#a_b_o_slider_container").css({"visibility":"visible"});
	var paddings = parseInt($("#a_b_o_scroller").css('padding-top'), 10) + parseInt($("#a_b_o_scroller").css('padding-bottom'), 10);
	if ($("#a_b_o_scroller").attr("scrollHeight") - paddings > $("#a_b_o_scroller").height()) {
		$("#a_b_o_slider").slider( { orientation: 'vertical', change: handleChangeABO, slide: handleSlideABO, min: 0, max: 100, value: 100, animate: true } );
	} else {
		$("#a_b_o_slider_container").css({"visibility":"hidden"});
	}
	jQuery('#a_b_o_slider_btn_bottom').click(function() {
		handleABOClick('bottom');
	});
	jQuery('#a_b_o_slider_btn_top').click(function() {
		handleABOClick('top');
	});
}

function handleABOClick(flg_top_bottom) {
	var value = $("#a_b_o_slider").slider("option", "value");
	if (flg_top_bottom == 'top') {
		value = (value > 90) ? 100 : value + 10;
	}
	if (flg_top_bottom == 'bottom') {
		value = (value < 10) ? 0 : value - 10;
	}
	$("#a_b_o_slider").slider("value", value);
}


/* *** */

function handleChangeWL(e, ui) {
	var maxScroll = $("#w_l_scroller").attr("scrollHeight") - $("#w_l_scroller").height();
	jQuery('#w_l_scroller').stop(true, true);
	$("#w_l_scroller").animate({ scrollTop: maxScroll * (1 - ui.value / 100) }, 800);
}

function handleSlideWL(e, ui) {
	var maxScroll = $("#w_l_scroller").attr("scrollHeight") - $("#w_l_scroller").height();
	$("#w_l_scroller").attr({ scrollTop: maxScroll * (1 - ui.value / 100) });
}

function initWLScroller() {
	$("#w_l_slider_container").css({"visibility":"visible"});
	if ($("#w_l_scroller").attr("scrollHeight") > $("#w_l_scroller").height()) {
		$("#w_l_slider").slider( { orientation: 'vertical', change: handleChangeWL, slide: handleSlideWL, min: 0, max: 100, value: 100, animate: true } );
	} else {
		$("#w_l_slider_container").css({"visibility":"hidden"});
	}
	jQuery('#w_l_slider_btn_bottom').click(function() {
		handleWLClick('bottom');
	});
	jQuery('#w_l_slider_btn_top').click(function() {
		handleWLClick('top');
	});
}

function handleWLClick(flg_top_bottom) {
	var value = $("#w_l_slider").slider("option", "value");
	if (flg_top_bottom == 'top') {
		value = (value > 90) ? 100 : value + 10;
	}
	if (flg_top_bottom == 'bottom') {
		value = (value < 10) ? 0 : value - 10;
	}
	$("#w_l_slider").slider("value", value);
}

/* *** */

function handleChangeOVL1(e, ui) {
	var maxScroll = $("#ovl1_scroller").attr("scrollHeight") - $("#ovl1_scroller").height();
	jQuery('#ovl1_scroller').stop(true, true);
	$("#ovl1_scroller").animate({ scrollTop: maxScroll * (1 - ui.value / 100) }, 800);
}

function handleSlideOVL1(e, ui) {
	var maxScroll = $("#ovl1_scroller").attr("scrollHeight") - $("#ovl1_scroller").height();
	$("#ovl1_scroller").attr({ scrollTop: maxScroll * (1 - ui.value / 100) });
}

function initOVL1Scroller() {
	$("#ovl1_slider_container").css({"visibility":"visible"});
	if ($("#ovl1_scroller").attr("scrollHeight") > $("#ovl1_scroller").height()) {
		$("#ovl1_slider").slider( { orientation: 'vertical', change: handleChangeOVL1, slide: handleSlideOVL1, min: 0, max: 100, value: 100, animate: true } );
	} else {
		$("#ovl1_slider_container").css({"visibility":"hidden"});
	}
	jQuery('#ovl1_slider_btn_bottom').click(function() {
		handleOVL1Click('bottom');
	});
	jQuery('#ovl1_slider_btn_top').click(function() {
		handleOVL1Click('top');
	});
}

function handleOVL1Click(flg_top_bottom) {
	var value = $("#ovl1_slider").slider("option", "value");
	if (flg_top_bottom == 'top') {
		value = (value > 90) ? 100 : value + 10;
	}
	if (flg_top_bottom == 'bottom') {
		value = (value < 10) ? 0 : value - 10;
	}
	$("#ovl1_slider").slider("value", value);
}
