﻿var vSliders = new Array;var hSliders = new Array;function getStaticCollectionByTagName(tag, node) {if (node==undefined) {node=document};var temp_array = node.getElementsByTagName(tag); var static_results = new Array;for (i=0; i<temp_array.length;i++) {static_results.push(temp_array[i]);}temp_array=null;return static_results;}function InitScroll(){var sd = getStaticCollectionByTagName("DIV");for(var i=0;i<sd.length;i++){if (sd[i].className.indexOf("ScrollDiv") > -1){if (sd[i].sliderIndex === null || typeof sd[i].sliderIndex == 'undefined'){Event.observe(sd[i], 'DOMMouseScroll', wheel);Event.observe(sd[i], 'mousewheel', wheel);var p = sd[i].parentNode;var f = new Element('div', { 'id': 'scrollWrapper_' + i});var vS = new Element('div', { 'id': 'vScrollWrap_' + i, 'class': 'vScrollWrap'});var hS = new Element('div', { 'id': 'hScrollWrap_' + i, 'class': 'hScrollWrap'});var sdc = sd[i].className;var oId = sd[i].id;if (sd[i].getAttribute('width') !== null){f.style.width = sd[i].getAttribute('width') + 'px';} if (sd[i].getAttribute('height') !== null){f.style.height = sd[i].getAttribute('height') + 'px';} p.insertBefore(f, sd[i]);f.appendChild(sd[i]);f.appendChild(vS);f.appendChild(hS);vS.className = "vScrollWrap";vS.style.height = (sd[i].offsetHeight - 20) + "px";sd[i].sliderIndex = vSliders.length;hS.style.width = sd[i].offsetWidth + "px";var vScrollTrackTop = new Element('div', { 'class': 'vScrollTrackTop png'});vS.appendChild(vScrollTrackTop);var vSt = new Element('div', { 'id': "vScrollTrack_" + i, 'class': 'vScrollTrack'});vSt.style.height = (sd[i].offsetHeight - 20) + "px";vS.appendChild(vSt);var hStL = new Element('div', {'class': 'hScrollTrackLeft'});hS.appendChild(hStL);var hSt = new Element('div', { 'id': "hScrollTrack_" + i, 'class': 'hScrollTrack'});hSt.style.width = sd[i].offsetWidth + "px";hS.appendChild(hSt);var vSh = new Element('div', { 'id': "vScrollHandle_" + i, 'class': 'vScrollHandle'});vSt.appendChild(vSh);var hSh = new Element('div', { 'id': "hScrollHandle_" + i, 'class': 'hScrollHandle'});hSt.appendChild(hSh);addVerticalSlider(vS.id, vSh.id, vSt.id, oId);addHorizontalSlider(hS.id, hSh.id, hSt.id, oId);}}}sd=null;}function handle(d, s){s.setValueBy(-d);}function wheel(event){var srcEl = event.srcElement? event.srcElement : event.target;if (srcEl.nodeType == 3){srcEl = srcEl.parentNode;}var p = findParentWithClassName(srcEl,"ScrollDiv");if (p !== null && typeof p !='undefined'){var delta = 0;var iHeight = p.scrollHeight;if (!event){event = window.event;}if (event.wheelDelta){delta = event.wheelDelta/iHeight;if (window.opera){delta = Math.round( ((delta * 2000)/iHeight)*100)/100;}}else if (event.detail) {delta = (-event.detail *12)/iHeight;}if (delta){handle(delta, vSliders[p.sliderIndex]);}if (event.preventDefault){event.preventDefault();}event.returnValue = false;}}function findParentWithClassName(elem, parentClassName){try {do{if (elem.className.indexOf("ScrollDiv") > -1){return elem;}else if (elem.parentNode != null){elem = elem.parentNode;}else{return null;}}while(elem.className.indexOf("ScrollDiv") == -1)return elem;}catch(e){}}function addVerticalSlider(VSWId, VSHId, VSTId, SDId){var vSlider = new Control.Slider(VSHId, VSTId, {axis: 'vertical', onSlide: function(v) { scrollVertical(v, $(SDId), vSlider);  },onChange: function(v) { scrollVertical(v, $(SDId), vSlider); }});if ($(SDId).scrollHeight <= $(SDId).offsetHeight) {vSlider.setDisabled();$(VSWId).hide();} vSliders.push(vSlider);}function addHorizontalSlider(HSWId, HSHId, HSTId, SDId){var hSlider = new Control.Slider(HSHId, HSTId, {onSlide: function(v) { scrollHorizontal(v, $(SDId), hSlider);  },onChange: function(v) { scrollHorizontal(v, $(SDId), hSlider); }});if ($(SDId).scrollWidth <= $(SDId).offsetWidth) {hSlider.setDisabled();$(HSWId).hide();}hSliders.push(hSlider);}function scrollVertical(v, e, s) {e.scrollTop = Math.round(v/s.maximum*(e.scrollHeight-e.offsetHeight));}function scrollHorizontal(v, e, s) {e.scrollLeft = Math.round(v/s.maximum*(e.scrollWidth-e.offsetWidth));}function initFormElem(elemId){var sb = document.getElementById(elemId);var inp  = sb.getElementsByTagName("INPUT");for( var i=0; i < inp.length; i++ ){if (inp[i].type != 'image'){if (inp[i].parentNode.id !== ''){inp[i].onfocus=function(){ moveTo(elemId, this.parentNode.id);};}else if (inp[i].parentNode.parentNode.id !== ''){inp[i].onfocus=function(){ moveTo(elemId, this.parentNode.parentNode.id);};}else {inp[i].onfocus=function(){ moveTo(elemId, this.id);};}}}}function moveTo(container, element){Position.prepare();container_y = Position.cumulativeOffset($(container))[1];element_y = Position.cumulativeOffset($(element))[1];var el = document.getElementById(element);var cont = document.getElementById(container);if (el.offsetTop != cont.scrollTop){handle(-((el.offsetTop - cont.scrollTop)/ cont.scrollHeight),  vSliders[document.getElementById(container).sliderIndex]);}return false;}


