
	
	/*###############################################################################################*/
	/*#############  Helper functions ###############################################################*/
	/*###############################################################################################*/


	
	
	
	

	function resizeMap () {
		var h = (typeof window.innerHeight !='undefined')?window.innerHeight:document.documentElement.clientHeight;//document.body.offsetHeight; 
		if(h == '0')
			h = document.body.offsetHeight;
		var w = (typeof window.innerWidth !='undefined')?window.innerWidth :document.body.offsetWidth;    //document.documentElement.clientWidth;
		
		if ($.browser.msie==true) {
			$("#map_canvas").css("width", w);
		} else {
			$("#map_canvas").css("width", w);
		}
		$("#map_canvas").css("height", h);
		$("#left_mainmenu").css("height", h);
		$("#left_menu").css("height", h);
		$("#left_container_dynamic").css("height", h);
		$("#left_container_static").css("height", h);
		$("#left_scroll_container").css("height",h);		
		updateScroller();
		
		parent.resolution_check();
	}

	

	function slideLeftMenu(id, state) {

		$("#" + id).animate({
		    width: ['toggle', 'swing'],
		    opacity: 'toggle'
		  }, 2000, 'linear', function() {

		  });
		
		mainMenuVisible = !mainMenuVisible;
		
	/*	$("#scroller").animate({
		    left: (!mainMenuVisible==true?'-=220':'+=220' )
		  }, 2000, 'linear', function() {

		});
	*/	
	}
	
	function reset_iframe_height(newHeight) {
		document.getElementById("iframeSiloForm").style.height=newHeight;
	}

	function getIframeHeight(){
		var iheight = document.getElementById("route_form").offsetHeight;
		if(iheight == 0)
			iheight = document.getElementById("route_form").clientHeight;
		return iheight;
	}
	
	function onLoadFunctions() {
		

		
	}	
	function extractNumbers(stringnumber){
		var number = stringnumber.replace("px","");
		return number;
		
	}
	
	function updateScroller() {
		if (getIframeHeight("route_form") > $("#left_scroll_container").height()) {
			$("#scroller").css("display","block" );
			$("#scroller").css("height","85px" );
			//$("#scroller").css("left", getRightPosition("left_containers")+"px");
			var scrollRange = (getIframeHeight("route_form") -( $("#left_scroll_container").height() - $("#scroller").height())) /( $("#left_scroll_container").height() - $("#scroller").height());
			var tp = $("#scroller").css("top");
			tp = parseInt(extractNumbers(tp));
			if (isNaN(tp)) tp=0;
			if (tp==0){
				$("#route_form").css("top",tp + "px");
			} else {
				tp = - tp * scrollRange;
				$("#route_form").css("top",tp + "px");
				$("#scroller").draggable({axis:"y",
					scroll:false,
					containment: 'parent',
					drag:
					function (ev, ui) {
						var scrollRange = (getIframeHeight("route_form") -( $("#left_scroll_container").height() - $("#scroller").height())) /( $("#left_scroll_container").height() - $("#scroller").height());
						var scroll_top =-parseInt(ui.offset.top)*scrollRange;
						$("#route_form").css("position","relative");
						$("#route_form").css("top",scroll_top + "px");
					}
				}); 
			}
		} else {
			$("#scroller").css("display","none");
		}	
	}

	function doSrollTo(nTop) {
		if ((nTop - (-1 *getIframeTop()))  >= getScrollContainerHeight()) {
			var scrollRange = (getIframeHeight("route_form") -( $("#left_scroll_container").height() - $("#scroller").height())) /( $("#left_scroll_container").height() - $("#scroller").height());
			var scroll_top = parseInt(nTop-$("#left_scroll_container").height())/scrollRange;
			$("#route_form").css("position","relative");
			$("#route_form").css("top",($("#left_scroll_container").height()-nTop) + "px");
			$("#scroller").css("left", getRightPosition("left_containers")+"px");
			$("#scroller").css("top", scroll_top+"px");
		}
	}
	
	function getScrollContainerHeight() {
		if (!$("#left_scroll_container").css("height")) return 0;
		return parseInt(extractNumbers($("#left_scroll_container").css("height")));
	}
	
	function getIframeTop() {
		return $("#route_form").position().top;
	}
	
	
	
	


	
	
	function initializeFormJsp() {
		
		if (document.location.href.indexOf("index.html")!=-1) {
			$("#scroller").css("height","85px");
			$("#scroller").draggable({axis:"y", 
				scroll:false, 
				containment: 'parent', 
				drag: 
					function (ev, ui) {
						var scrollRange =(getIframeHeight("route_form") -( $("#left_scroll_container").height() - $("#scroller").height())) /( $("#left_scroll_container").height() - $("#scroller").height());
						var scroll_top = -parseInt(ui.offset.top)*scrollRange;
						$("#route_form").css("position","relative");
						$("#route_form").css("top",scroll_top + "px");										
					}
			});
			$("#scroller").css("height","85px");	
			$("#scroller").css("position", "absolute");
			$("#scroller").css("left", getRightPosition("left_containers")+"px");
			$("#scroller").css("top", getTopPosition("left_containers")+"px");
			$("#scroller").css("display", "block");
			
			$("#scroller").hover (				
				function () {
					if (typeof document.body.style.maxHeight != "undefined"){  // IE 7, mozilla
						$("#scroller").css("background-image", "url(/_common/icons/scroller_over.png)");
					}else{   //IE6
						$("#scroller").css("background", "none");
						$("#scroller").css("filter", "progid:DXimageTransform.Microsoft.AlphaimageLoader(src='/_common/icons/scroller_over.png', sizingMethod='scale')");
					}	
				}
				,
				function () {
					if (typeof document.body.style.maxHeight != "undefined"){  // IE 7, mozilla
						$("#scroller").css("background-image", "url(/_common/icons/scroller.png)");
					}else{   //IE6
						$("#scroller").css("background", "none");
						$("#scroller").css("filter", "progid:DXimageTransform.Microsoft.AlphaimageLoader(src='/_common/icons/scroller.png', sizingMethod='scale')");
					}		
				}
			);
				
		
			//SI.Files.stylizeById("upload_image_file");
			
			resizeMap();
		}
		window.onresize = resizeMap;
	}
	
	
	$(document).ready(initializeFormJsp);








	
	
