/* Файл: main.js Автор: Aloha [ohana2005@yandex.ru] требуются библиотеки: e_dom.js, style.js, event.js, limit.js, timer.js, moveable.js, movement.js, resizeable.js */ var _onglobalstop = new DOMEvent(); var _ie = !window.getComputedStyle; var __left_menu_mwidth = 250; var time_out; var _IS_MOVING = false; var tim = new Timer(50); var console; var mov_step = 10; var screen_height = 240; var global_movs; var ie6 = Style._browser == "IE" && parseInt(Style._br_version) == 6; tim.start(); function init_right(){ var current_index = 0; var root = $("image"); var s_root = $("small_images"); var mov_items = $C("move-item", root, "DIV"); var small_items = $C("small-item", s_root, "DIV"); var header = $("blue"); header.small = $T("SPAN", header)[0]; small_items.each(function(item, index){ if(item.className.indexOf("current") != -1){ current_index = index; throw $break; } }); var i_container = $("image-container"); var images = $T("IMG", i_container); var movs = []; mov_items.each(function(item, index){ var mov = new Movement(item, tim); mov.Moveable.moveTo(0, 240 * index); mov._next = index ? false : true; if(index){ item.appendChild(images[current_index]) }else{ item.appendChild(images.next(images[current_index])); } mov.onreach.remove(Movement.defaultOnReach.name); mov.onreach.register("reach", function(){ this.stopMoveTo(); if(this.Moveable.top == 480){ this.setSteps(0, -480); this.onmove.register("test", function(){ this.stop(); _IS_MOVING = false; _onglobalstop.fire(); }.bind(this), 1); this.start(); } }.bind(mov)); mov.onstart.register("replace", function(){ _IS_MOVING = true; if(this.Moveable.top == 0){ current_index ++; clearElem(this.Moveable.elem); var c_ind = current_index % images.length; this.Moveable.elem.appendChild(images[c_ind]); var mov_out, mov_in; small_items.each(function(item){ if(item.className.indexOf("current") != -1){ item.className = item.className.replace("current", ""); mov_out= item.mov; }else{ item.mov.moveTo(0, 50); } }); var c_item = small_items[c_ind]; c_item.className += " current"; header.removeChild(header.firstChild); header.insertBefore(document.createTextNode(c_item.js_title), header.small); clearElem(header.small); header.small.appendChild(document.createTextNode(c_item.js_city)); mov_in = small_items[c_ind].mov; this.onmove.register("change-small", function(mOut, mIn){ mOut.moveBy(0, mOut._height / this.mt_numOfSteps); mIn.moveBy(0, mOut._height / this.mt_numOfSteps); }.bind(this, mov_out, mov_in)); this.onstop.register("remove", function(){ this.onmove.remove("change-small"); }.bind(this), 1) } }.bind(mov)) movs.push(mov); }); global_movs = movs; small_items.each(function(item, index){ item.index = index; item.js_title = $C("title", item, "DIV")[0].firstChild.nodeValue; item.js_city = ""; var city_div = $C("city", item, "DIV")[0]; if(city_div.firstChild){ item.js_city = city_div.firstChild.nodeValue; } item.mov = new moveable($C("yellow", item, "DIV")[0]); item.mov._height = parseInt(Style.getElementStyle(item.mov.elem, "height")); if(item.className.indexOf("current") != -1){ item.mov.moveBy(0, 10); header.removeChild(header.firstChild); header.insertBefore(document.createTextNode(item.js_title), header.small); clearElem(header.small); header.small.appendChild(document.createTextNode(item.js_city)); } item.onmouseover = function(){ if(this.className.indexOf("current") != -1){ return false; } current_index = this.index - 1; clearTimeout(time_out) if(!_IS_MOVING){ move_items(); }else{ _onglobalstop.register("move", function(){ clearTimeout(time_out); setTimeout(function(){ move_items(); }, 1); this.remove("move") }.bind(_onglobalstop),1); } } }) //time_out = setTimeout(move_items, 6000); _onglobalstop.register("timeout", function(){ time_out = setTimeout(function(){ move_items_first(); }, 3000); }) } function move_items_first(){ var s_root = $("small_images"); var small_items = $C("small-item", s_root, "DIV"); small_items[0].onmouseover( ); } function move_items(){ global_movs.each(function(mov){ mov.moveTo(0, mov.Moveable.top + 240, 15); }); } function init_left(){ var root = $("menu_main"); var items = $C("m-item", root, "DIV"); items.each(function(item){ if(item.className.indexOf("here") != -1){ throw $continue; } item.className += " initializing"; item.mov_item = $C("mov-item", item, "DIV"); if(item.mov_item){ item.mov_item = item.mov_item[0]; var _width = item.mov_item.offsetWidth; if(_width > __left_menu_mwidth){ _width = __left_menu_mwidth; item.className += " wrap"; }else{ item.className += " nowrap"; } var _height = item.mov_item.offsetHeight; var _top = Math.floor(-_height / 2); item.dropdown = $C("dropdown", item, "DIV")[0]; item.dropdown.style.width = _width + (ie6 ? 49 : 50) + "px";// 40 - horizontal padding item.dropdown.style.height = _height + 15 + "px"; item.dropdown.style.top = _top + "px"; // item._top = _top; /* item.mov = new Movement(item.mov_item, tim); item.mov.onstart.register("c-name", function(NS){ NS.className += " over"; NS.dropdown.style.top = - Math.floor(NS.mov_item.offsetHeight / 2) + 10 + "px"; }.bind(item.mov, item)); */ item._width = _width + 40; } item.onmouseover = function(){ if(this.className.indexOf("over") != -1){ return; } if(this.mov){ this.mov.moveTo(0, 0, 15); }else{ this.className += " over"; if(this.dropdown){ this.dropdown.style.top = -Math.floor(this.mov_item.offsetHeight / 2) + 10 + "px"; } } } item.onmouseout = function(e){ if(this.className.indexOf("over") == -1){ return; } if(this.mov){ var ev = window.event || e; var target = ev.toElement || ev.relatedTarget; if(target == this || target == this.dropdown || _isChild(target, this) || _isChild(target, this.dropdown)){ return false; } hide_plashka(this) }else{ this.className = this.className.replace(" over", ""); } } if(item.mov){ item.dropdown.onmouseout = item.onmouseout.bind(item); } item.className = item.className.replace(" initializing", ""); }) } function hide_plashka(NS){ if(NS.opacity){ NS.opacity.fade(0, 10); }else{ var reg = /over/gi; NS.mov.stop(); NS.mov.Moveable.moveTo(-NS._width, 0); NS.className = NS.className.replace(reg, ""); } } function init_gallery(){ var objects = $C("object", $("right-col"), "DIV"); if(!objects){ return false; } objects.each(function(obj){ var arr = $C_arr(["image-container", "zaglushka", "move-holder"], obj, "DIV"); obj.image_container = arr.shift(); obj.zaglushka = arr.shift(); obj.move_holder = arr.shift(); obj.mov_items = $C("move-item", obj, "DIV"); obj.movs = []; obj.currentImage = $T("IMG", obj.image_container)[0]; obj.onglobalstop = new DOMEvent(); obj.IS_MOVING = false; obj.from_item = obj.to_item = null; obj.mov_items.each(function(item, index){ //this = obj if(index){ item.appendChild(this.currentImage); } var mov = new Movement(item, tim); mov.Moveable.moveTo(0, 240 * index); mov.onstop.register("stop", function(NS){ if(this.Moveable.top == 480){ NS.from_item.mov.moveTo(0, 50); NS.to_item.mov.moveTo(0, 60); NS.to_item.mov.saveFloatY.refresh(); NS.from_item.mov.saveFloatY.refresh(); NS.IS_MOVING = false; setTimeout(function(){ this.Moveable.moveTo(0, 0); }.bind(this), 1); } }.bind(mov, this)); mov.onmove.register("yellow", function(NS){ var step = NS.to_item.mov._height / (this.mt_numOfSteps * 2); NS.to_item.mov.moveBy(0, step); NS.from_item.mov.moveBy(0, step); }.bind(mov, this)) mov.onreach.remove(Movement.defaultOnReach.name); mov.onreach.register("reach", function(){ this.stopMoveTo(); }.bind(mov)); obj.movs.push(mov) }.bind(obj)); obj.items = $C("small-item", obj, "DIV"); obj.items.each(function(item){ item.link = $T("A", item)[0]; /////////////////////////////////////// item.image_div = $C("imageH2", item, "DIV")[0]; item.small_image = $T("IMG", item)[0]; //item.image_div.style.background = "url(" + item.small_image.src + ") no-repeat"; //item.small_image.parentNode.removeChild(item.small_image) item.yellow = $C("yellow", item, "DIV")[0]; item.mov = new moveable(item.yellow); item.mov._height = item.yellow.offsetHeight; item.mov.onmove.register("refresh", function(){ if(this.top >= 70){ setTimeout(function(){ this.moveTo(0, 50); }.bind(this), 1); } }.bind(item.mov)); //////////////////////////////////////// item.image = new Image(); item.image.src = item.link.href; item.image.alt = item.link.title; item.image.title = item.link.title; if(obj.currentImage.src == item.image.src){ item.className += " current"; item.mov.moveTo(0, 60); } item.image.loaded = (item.image.height != 0); item.onclick = function(NS) { //alert( this.image.src ); if(NS.IS_MOVING || this.className.indexOf("current") != -1){ return false; } NS.to_item = this; NS.items.each(function(it){ if(it.className.indexOf("current") != -1){ it.className = it.className.replace("current", ""); NS.from_item = it; } }); this.className += " current"; if (this.image ){ NS.movs.each(function(mov){ if(mov.Moveable.top == 0){ clearElem(mov.Moveable.elem); mov.Moveable.elem.appendChild(this.image); } mov.moveTo(0, mov.Moveable.top + 240, 15); }.bind(this)); NS.IS_MOVING = true; }else{ //alert("Sorry, still under construction"); } return false; }.bindAvoidingEvent(item, obj) }); }) } function init_tables(){ var root = $("usual_text"); if(!root){ return false; } var tables = $C("tbl", root, "TABLE"); if(!tables){ return false; } tables.each(function(tbl){ var trs = $T("TR", tbl); trs.each(function(tr, index){ var val = 0; if(!index){ if(!$C("theader", tr, "TD")){ val = 1; tr.className = "zebra"; } throw $continue; } if(index % 2 == val){ tr.className = "zebra"; } }); trs.last().className = trs.last().className ? trs.last().className + " last" : "last"; }) }