/******************************************************************** ******* scrollbox.js ********************************************************************/ /********************************************************* * Scrollbox control ************************ * by Kozyuck Alexander, 2008 ************************ * kolexander@gmail.com ************************ *********************************************************/ var Scrollbox = Class.create(); Scrollbox.prototype = { initialize: function(parameters) { this.cont = $(parameters.contId); this.list = $(parameters.listId); if(typeof parameters.insertTo == 'undefined') this.insertTo = $('scrollrows') else this.insertTo = $(parameters.insertTo) if(typeof parameters.gauge == 'undefined') this.gauge = $('regauge'); else this.gauge = $(parameters.gauge); if(typeof parameters.scrollLeft == 'undefined') this.scrollLeft = 0; else this.scrollLeft = parameters.scrollLeft; this.offsetDiv = 10; this.repeatTm = 5; this.timer = null; this.downButton = false; this.nomoreRows = false; this.countFetchRows = 20; this.fromVal = 0; if(typeof parameters.prevButton == 'undefined') this.prevButton = $('prev'); else this.prevButton = $(parameters.prevButton); if(typeof parameters.nextButton == 'undefined') this.nextButton = $('next'); else this.nextButton = $(parameters.nextButton); if(typeof parameters.fetching == 'undefined') this.fetching = false; else this.fetching = parameters.fetching; if(typeof parameters.fromUrl == 'undefined') this.fromUrl = '/main/fetch'; else this.fromUrl = parameters.fromUrl; if(typeof parameters.fetchParams == 'undefined') this.fetchParams = null; else this.fetchParams = parameters.fetchParams; if(typeof parameters.direction == 'undefined') this.direction = 'vertical'; else this.direction = parameters.direction; if(typeof parameters.prevButton != 'undefined') { this.prevButton.onmousedown = this.pressPrevButton.bindAsEventListener(this); this.prevButton.onmouseup = this.releaseButton.bindAsEventListener(this); this.prevButton.onmouseout = this.releaseButton.bindAsEventListener(this); } if(typeof parameters.nextButton != 'undefined') { this.nextButton.onmousedown = this.pressNextButton.bindAsEventListener(this); this.nextButton.onmouseup = this.releaseButton.bindAsEventListener(this); this.nextButton.onmouseout = this.releaseButton.bindAsEventListener(this); } }, setGaugeHidden: function(){ this.gauge.style.visibility = 'hidden'; }, setGaugeVisible: function(){ this.gauge.style.left = this.cont.offsetLeft+Math.round((this.cont.offsetWidth-this.gauge.offsetWidth)/2)+'px'; this.gauge.style.top = this.cont.offsetTop+Math.round((this.cont.offsetHeight-this.gauge.offsetHeight)/2)+'px'; this.gauge.style.visibility = 'visible'; }, dec: function(val) { var par = parseInt(val); val = (isNaN(par))?0:par - this.offsetDiv; return val+"px"; }, inc: function(val) { var par = parseInt(val); val = (isNaN(par))?0:par + this.offsetDiv; return val+"px"; }, pressPrevButton: function() { this.downButton = true; this.scrollPrev(); }, pressNextButton: function() { this.downButton = true; this.scrollNext(); }, releaseButton: function() { this.downButton = false; }, scrollPrev: function() { if(this.downButton) { //если долистали в начало if((this.direction=='horizontal'&&parseInt(this.list.style.left) >= this.scrollLeft) || (this.direction=='vertical'&&parseInt(this.list.style.top) >= this.scrollLeft)) { this.downButton = false; clearTimeout(this.timer); this.onAfterScroll(); return; } if(this.direction=='horizontal') this.list.style.left = this.inc(this.list.style.left); if(this.direction=='vertical') this.list.style.top = this.inc(this.list.style.top); this.timer = setTimeout( function(){ this.scrollPrev() ; }.bind(this), this.repeatTm) } else clearTimeout(this.timer); }, scrollNext: function() { if(this.downButton) { //если долистали до конца if((this.direction=='horizontal' && ((-1)*parseInt(this.list.offsetLeft) > (parseInt(this.list.offsetWidth) - parseInt(this.cont.offsetWidth) - this.scrollLeft))) || (this.direction=='vertical' && ((-1)*parseInt(this.list.offsetTop) > (parseInt(this.list.offsetHeight) - parseInt(this.cont.offsetHeight))) )) { this.downButton = false; clearTimeout(this.timer); this.fromVal += this.countFetchRows; if(!this.nomoreRows && this.fetching) this.fetchNextBlock(); this.scrollLeft = 0; this.onAfterScroll(); return; } if(this.direction=='horizontal') this.list.style.left = this.dec(this.list.style.left); else this.list.style.top = this.dec(this.list.style.top); this.timer = setTimeout( function(){ this.scrollNext(); }.bind(this), this.repeatTm); } else clearTimeout(this.timer); }, scrollBegin: function() { this.downButton = true; this.scrollPrev(); }, scrollEnd: function() { this.downButton = true; this.scrollNext(); }, fetchNextBlock: function() { this.setGaugeVisible(); var sfparm = ''; for(fparm in this.fetchParams) { sfparm += '&'+fparm+'='+this.fetchParams[fparm] } new Ajax.Updater(this.insertTo.id, this.fromUrl,{ method: "post", parameters:sfparm+"&offset=" + this.fromVal + "&rowcount=" + this.countFetchRows, //&light=1 insertion: Insertion.Bottom, onComplete: this.handleResponse.bind(this), onFailure: this.reportError.bind(this) } ); }, onAfterScroll: function (){ }, handleResponse: function(response) { if(response.responseText.length == 0) this.nomoreRows = true; this.setGaugeHidden(); }, reportError: function(err) { } } /******************************************************************** ******* slider.js ********************************************************************/ if(!Control){var Control={}}Control.Slider=Class.create({initialize:function(D,A,B){var C=this;if(Object.isArray(D)){this.handles=D.collect(function(E){return $(E)})}else{this.handles=[$(D)]}this.track=$(A);this.options=B||{};this.axis=this.options.axis||"horizontal";this.increment=this.options.increment||1;this.step=parseInt(this.options.step||"1");this.range=this.options.range||$R(0,1);this.value=0;this.values=this.handles.map(function(){return 0});this.spans=this.options.spans?this.options.spans.map(function(E){return $(E)}):false;this.options.startSpan=$(this.options.startSpan||null);this.options.endSpan=$(this.options.endSpan||null);this.restricted=this.options.restricted||false;this.maximum=this.options.maximum||this.range.end;this.minimum=this.options.minimum||this.range.start;this.alignX=parseInt(this.options.alignX||"0");this.alignY=parseInt(this.options.alignY||"0");this.trackLength=this.maximumOffset()-this.minimumOffset();this.handleLength=this.isVertical()?(this.handles[0].offsetHeight!=0?this.handles[0].offsetHeight:this.handles[0].style.height.replace(/px$/,"")):(this.handles[0].offsetWidth!=0?this.handles[0].offsetWidth:this.handles[0].style.width.replace(/px$/,""));this.active=false;this.dragging=false;this.disabled=false;if(this.options.disabled){this.setDisabled()}this.allowedValues=this.options.values?this.options.values.sortBy(Prototype.K):false;if(this.allowedValues){this.minimum=this.allowedValues.min();this.maximum=this.allowedValues.max()}this.eventMouseDown=this.startDrag.bindAsEventListener(this);this.eventMouseUp=this.endDrag.bindAsEventListener(this);this.eventMouseMove=this.update.bindAsEventListener(this);this.handles.each(function(F,E){E=C.handles.length-1-E;C.setValue(parseFloat((Object.isArray(C.options.sliderValue)?C.options.sliderValue[E]:C.options.sliderValue)||C.range.start),E);F.makePositioned().observe("mousedown",C.eventMouseDown)});this.track.observe("mousedown",this.eventMouseDown);document.observe("mouseup",this.eventMouseUp);document.observe("mousemove",this.eventMouseMove);this.initialized=true},dispose:function(){var A=this;Event.stopObserving(this.track,"mousedown",this.eventMouseDown);Event.stopObserving(document,"mouseup",this.eventMouseUp);Event.stopObserving(document,"mousemove",this.eventMouseMove);this.handles.each(function(B){Event.stopObserving(B,"mousedown",A.eventMouseDown)})},setDisabled:function(){this.disabled=true},setEnabled:function(){this.disabled=false},getNearestValue:function(A){if(this.allowedValues){if(A>=this.allowedValues.max()){return(this.allowedValues.max())}if(A<=this.allowedValues.min()){return(this.allowedValues.min())}var C=Math.abs(this.allowedValues[0]-A);var B=this.allowedValues[0];this.allowedValues.each(function(D){var E=Math.abs(D-A);if(E<=C){B=D;C=E}});return B}if(A>this.range.end){return this.range.end}if(A0)&&(Bthis.values[A+1])){B=this.values[A+1]}}B=this.getNearestValue(B);this.values[A]=B;this.value=this.values[0];this.handles[A].style[this.isVertical()?"top":"left"]=this.translateToPx(B);this.drawSpans();if(!this.dragging||!this.event){this.updateFinished()}},setValueBy:function(B,A){this.setValue(this.values[A||this.activeHandleIdx||0]+B,A||this.activeHandleIdx||0)},translateToPx:function(A){return Math.round(((this.trackLength-this.handleLength)/(this.range.end-this.range.start))*(A-this.range.start))+"px"},translateToValue:function(A){return((A/(this.trackLength-this.handleLength)*(this.range.end-this.range.start))+this.range.start)},getRange:function(B){var A=this.values.sortBy(Prototype.K);B=B||0;return $R(A[B],A[B+1])},minimumOffset:function(){return(this.isVertical()?this.alignY:this.alignX)},maximumOffset:function(){return(this.isVertical()?(this.track.offsetHeight!=0?this.track.offsetHeight:this.track.style.height.replace(/px$/,""))-this.alignY:(this.track.offsetWidth!=0?this.track.offsetWidth:this.track.style.width.replace(/px$/,""))-this.alignX)},isVertical:function(){return(this.axis=="vertical")},drawSpans:function(){var A=this;if(this.spans){$R(0,this.spans.length-1).each(function(B){A.setSpan(A.spans[B],A.getRange(B))})}if(this.options.startSpan){this.setSpan(this.options.startSpan,$R(0,this.values.length>1?this.getRange(0).min():this.value))}if(this.options.endSpan){this.setSpan(this.options.endSpan,$R(this.values.length>1?this.getRange(this.spans.length-1).max():this.value,this.maximum))}},setSpan:function(B,A){if(this.isVertical()){B.style.top=this.translateToPx(A.start);B.style.height=this.translateToPx(A.end-A.start+this.range.start)}else{B.style.left=this.translateToPx(A.start);B.style.width=this.translateToPx(A.end-A.start+this.range.start)}},updateStyles:function(){this.handles.each(function(A){Element.removeClassName(A,"selected")});Element.addClassName(this.activeHandle,"selected")},startDrag:function(C){if(Event.isLeftClick(C)){if(!this.disabled){this.active=true;var D=Event.element(C);var E=[Event.pointerX(C),Event.pointerY(C)];var A=D;if(A==this.track){var B=Position.cumulativeOffset(this.track);this.event=C;this.setValue(this.translateToValue((this.isVertical()?E[1]-B[1]:E[0]-B[0])-(this.handleLength/2)));var B=Position.cumulativeOffset(this.activeHandle);this.offsetX=(E[0]-B[0]);this.offsetY=(E[1]-B[1])}else{while((this.handles.indexOf(D)==-1)&&D.parentNode){D=D.parentNode}if(this.handles.indexOf(D)!=-1){this.activeHandle=D;this.activeHandleIdx=this.handles.indexOf(this.activeHandle);this.updateStyles();var B=Position.cumulativeOffset(this.activeHandle);this.offsetX=(E[0]-B[0]);this.offsetY=(E[1]-B[1])}}}Event.stop(C)}},update:function(A){if(this.active){if(!this.dragging){this.dragging=true}this.draw(A);if(Prototype.Browser.WebKit){window.scrollBy(0,0)}Event.stop(A)}},draw:function(B){var C=[Event.pointerX(B),Event.pointerY(B)];var A=Position.cumulativeOffset(this.track);C[0]-=this.offsetX+A[0];C[1]-=this.offsetY+A[1];this.event=B;this.setValue(this.translateToValue(this.isVertical()?C[1]:C[0]));if(this.initialized&&this.options.onSlide){this.options.onSlide(this.values.length>1?this.values:this.value,this)}},endDrag:function(A){if(this.active&&this.dragging){this.finishDrag(A,true);Event.stop(A)}this.active=false;this.dragging=false},finishDrag:function(A,B){this.active=false;this.dragging=false;this.updateFinished()},updateFinished:function(){if(this.initialized&&this.options.onChange){this.options.onChange(this.values.length>1?this.values:this.value,this)}this.event=null}}) /******************************************************************** ******* weathermap.js ********************************************************************/ initCommon(); var mapTime = curyear + curmonth + curday + String(nexthour).substr(0,2); // var selMapTime = mapTime; var selMapTime = curyear + curmonth + '07' + '00'; var playPointPause = 1000; var tmPlayer = null; var playerEnable = true; var show = new Array("clw", "pre", "prs", "tc", "rh", "wnd", "wsp"); show["clw"] = true; show["pre"] = true; show["prs"] = true; show["tc"] = true; show["rh"] = true; show["wnd"] = true; show["wsp"] = true; function getImage(type,prefix,tm) { if(typeof tm == 'undefined') var tm = mapTime; document.images[type+'map'].src = "/pictures/weathermaps/" + curegion + "/" + prefix + '_' + curegion + '_' + tm + ".png" } function getImages() { getImage('clw','CLW'); getImage('pre','PRE'); getImage('prs','PRS'); getImage('tc', 'TC_'); getImage('rh', 'RH_'); getImage('wnd','WND'); getImage('wsp','WSP'); } function InitMap() { setWMapHeight(); switchParam("clw"); switchParam("pre"); switchParam("prs"); switchParam("tc"); switchParam("rh"); switchParam("wnd"); switchParam("wsp"); getImages(); } function switchParam(param) { var paramMapName = param + "map"; var paramButton = param + "button"; var paramButtonOff = param + "_off.jpg"; var paramButtonOn = param + "_on.jpg"; show[param]=!show[param]; if (show[param]) { document.images[paramMapName].style.visibility = ""; document.images[paramButton].parentNode.style.fontWeight = 'bold'; document.images[paramButton].src = "/images/" + paramButtonOn; } else { document.images[paramMapName].style.visibility = "hidden"; document.images[paramButton].parentNode.style.fontWeight = 'normal'; document.images[paramButton].src = "/images/" + paramButtonOff; } } /*************************************************************************/ /**** Календарь /*************************************************************************/ function initPoints(classname) { var points = document.getElementsByClassName(classname, $('calendarlist')); var len = points.length; for(var i = 0; i < len; i++) { points[i].onclick = tmClick.bindAsEventListener(this,points[i]); } } function initCalendar() { initPoints('wmap-tm'); initPoints('wmap-tm-act'); } function getMyInt(str) { var a = str.split(""); var b = Array(); for(var i=0,m=0;i 0) points[0].className = 'wmap-tm'; point.className = 'wmap-tm-act'; //выводим выбранную дату в окно плеера var tr = point.parentNode.parentNode.parentNode.firstChild; if(typeof tr.childNodes[0].tagName == 'undefined') { var day = tr.childNodes[1].firstChild.innerHTML; } else { if(tr.childNodes[0].tagName == 'TD') var day = tr.childNodes[0].firstChild.innerHTML; } $("plr_curdate").innerHTML = day + ' ' + point.innerHTML; var date_arr = day.split(" "); if (date_arr.length > 0) date_str = date_arr[1]; if (undefined != date_str) date_arr = date_str.split("."); if (date_arr.length > 0) { day_str = date_arr[0]; mon_str = date_arr[1]; } else { day_str = day.substr(7,2); mon_str = day.substr(4,2); } //* var _curdate = new Date(); var _workdate = new Date(); _curdate.setFullYear(curyear, getMyInt(curmonth) - 1, curday); _workdate.setFullYear(curyear, getMyInt(mon_str) - 1, day_str); if((_workdate.getTime() - _curdate.getTime()) < 0) { var _workdate = new Date(); _workdate.setFullYear(parseInt(curyear) + 1, getMyInt(mon_str) - 1, day_str); } _selMapTime = _workdate.getFullYear().toString(); _selMapTime1 = (_workdate.getMonth() + 1).toString(); _selMapTime2 = _workdate.getDate().toString(); _selMapTime+= (_selMapTime1 <= 9) ? "0" + _selMapTime1 : _selMapTime1; _selMapTime+= (_selMapTime2 <= 9) ? "0" + _selMapTime2 : _selMapTime2; _selMapTime+= point.innerHTML.substr(0,2); selMapTime = _selMapTime; //*/ // selMapTime = curyear + mon_str + day_str + point.innerHTML.substr(0,2); // alert(selMapTime); reloadMap(); } function reloadMap(){ if(show["clw"]) getImage('clw','CLW',selMapTime); if(show["pre"]) getImage('pre','PRE',selMapTime); if(show["prs"]) getImage('prs','PRS',selMapTime); if(show["tc" ]) getImage('tc', 'TC_',selMapTime); if(show["rh" ]) getImage('rh', 'RH_',selMapTime); if(show["wnd"]) getImage('wnd','WND',selMapTime); if(show["wsp"]) getImage('wsp','WSP',selMapTime); } function simulateClick(el) { var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); if(typeof el == 'string') var obj = document.getElementById(el); else var obj = el; obj.dispatchEvent(evt); } function findSubNode(cont,tag,num){ if(cont.childNodes[0].tagName == tag) { if(typeof num == 'undefined') num = 0; node = cont.childNodes[num].firstChild; } return node; } //переход на предыдущий пункт календаря function showPrev() { var points = document.getElementsByClassName('wmap-tm-act', $('calendarlist')); if(points.length > 0) { point = points[0]; var nextp = point.parentNode; if(nextp.className=='wmap-tm-l') { nextp = nextp.parentNode.previousSibling; if(nextp.firstChild.className!='wmap-tm-d') { nextp = findSubNode(nextp,'TD',2); } else { nextp = nextp.parentNode.parentNode; var dayweeknum = nextp.getAttribute('dayweeknum'); if(dayweeknum==4) { scroller.scrollBegin(); } nextp = nextp.parentNode.previousSibling; if(typeof nextp.tagName == 'undefined') nextp = nextp.previousSibling; nextp = nextp.firstChild.firstChild.childNodes; nextp = nextp[nextp.length-1]; nextp = findSubNode(nextp,'TD',2); } } else if(nextp.className=='wmap-tm-r') { nextp = nextp.previousSibling.previousSibling.firstChild; } if(nextp.className!='wmap-tm-disable') { point.className = 'wmap-tm'; if(BrowserDetect.browser == 'Explorer') nextp.click(); else simulateClick(nextp); } } } //переход на следующий пункт календаря function showNext() { var points = document.getElementsByClassName('wmap-tm-act', $('calendarlist')); if(points.length > 0) { point = points[0]; var nextp = point.parentNode; if(nextp.className=='wmap-tm-l') { nextp = nextp.nextSibling.nextSibling.firstChild; } else if(nextp.className=='wmap-tm-r') { if(nextp.parentNode.nextSibling!=null) { nextp = nextp.parentNode.nextSibling; nextp = findSubNode(nextp,'TD'); } else { nextp = nextp.parentNode.parentNode.parentNode; var dayweeknum = nextp.getAttribute('dayweeknum'); if(dayweeknum==4) { scroller.scrollEnd(); } nextp = nextp.parentNode.nextSibling; if(typeof nextp.tagName == 'undefined') nextp = nextp.nextSibling; if(nextp==null) return false; nextp = nextp.firstChild.firstChild.childNodes; nextp = nextp[1]; nextp = findSubNode(nextp,'TD',0); } } if(nextp.className!='wmap-tm-disable') { point.className = 'wmap-tm'; if(BrowserDetect.browser == 'Explorer') nextp.click(); else simulateClick(nextp); } else { clearTimeout(tmPlayer); playerEnable = false; } } } function playMaps(){ showNext(); if(playerEnable) tmPlayer = setTimeout('playMaps()', playPointPause); } function gotoWeatherMap(select){ if(select.value != -1) window.location.href = '/'+curlang+'/wmap7days/'+select.value+((String(select.value).length>0)?'/':''); } function setWMapHeight(){ var mapa = $('mapa'); if(typeof mapa != 'undefined') if(typeof mapa.offsetHeight != 'undefined' && mapa.offsetHeight > 0) { $('mapcont').style.height = mapa.offsetHeight+'px'; } } function initWMap7days() { InitMap(); initCalendar(); new Control.Slider('handle1','track1',{ values:[1,2,3,4,5], range:$R(1,5), sliderValue:2, onSlide:function(v){$('trackres').innerHTML=+v+' s.'}, onChange:function(v){playPointPause = v*1000} } ); } function doKyiv() { $('imgwmap').src = '/pictures/maps/wmap_kyiv_'+curlang+'.jpg'; $('mapcont').style.width = '635px'; $('mapcont').style.height = '636px'; curegion = 'Kyiv'; getImages(); } //Event.observe(window, "load", init); var scroller = new Scrollbox({ contId:'calendar', listId:'calendarlist', prevButton:'prev', nextButton:'next', direction:'horizontal' }); initWMap7days();