function init_tag_slider_element(domId,slider,sections){
	$(document).ready(function(){
		
		var cDiv = $('#TS' + domId);
		var width = cDiv.width();
		
		/* Pixcels Per Unit X*/

		var ppux = (width / (slider.end - slider.start));

		for(var i = 0;i < sections.length;i++){
			var section = sections[i];
			var sDiv = $('#TSS' + section.id);
			var sWidth = ppux * (section.end - section.start) - 2;
			sDiv.width(sWidth);
		}

		var TSUiDivEl = $('#TSUiDiv' + domId);

		TSUiDivEl.slider({animate: true,max: 1000});

		var labelEl = $('#TSUiLabel' + domId);

		if(labelEl != null){
			TSUiDivEl.bind('slide',function (event,ui){
				if(ui == null){
					var value = TSUiDivEl.slider('option','value');
				}else{
					value = ui.value;
				}
				var newValue = slider.start + ((value / 1000) * (slider.end - slider.start));
				var oldValue = Number(labelEl.text());
				var oldSection = null;
				var newSection = null;
				var i = 0;
				var tmpSection = null;

				for(i = 0; i < sections.length;i++){
					tmpSection = sections[i];

					if(oldValue > tmpSection.start && oldValue <= tmpSection.end){
						oldSection = tmpSection;
					}
					
					if(newValue > tmpSection.start && newValue <= tmpSection.end){
						newSection = tmpSection;
					}
				}
				
				labelEl.text(newValue.toPrecision(3));

				if(newSection != null && (oldSection == null ||  newSection.id != oldSection.id)){
					$.get("/useful-tools/gateway.php?url=TagSliders/getSection/" + newSection.id + "/" + domId,handelDivs);
				}

			});
		}
	});
}

function set_value_tag_slider_element(domId,slider,value){
	$(document).ready(function(){
		var tSUiDiv = $('#TSUiDiv' + domId);
		var slideValue = ((value - slider.start) / (slider.end - slider.start)) * 1000;
		tSUiDiv.slider('option','value',slideValue);
		$('#TS' + domId + ' .tagSliderSections').css('background-image','url(/site-resources/images/tag_slider_element/slider_value_bg.png)');
		$('#TS' + domId + ' .tagSliderSections').css('background-repeat','repeat-y');

		var ppux = tSUiDiv.width() / (slider.end - slider.start) ;

		var xpos = ppux * (value - slider.start);

		$('#TS' + domId + ' .tagSliderSections').css('background-position',xpos + "px 0px");

	});
}

