// BENAGO NEWS
// 
// COOLweby (c) 2010
// 
// Všechna práva vyhrazena.
// Jakékoli šíření, úprava či používání kódu je bez povolení autora ZAKÁZÁNO. 
// Jednáni v rozporu s těmito podmínkami může být a bude postihováno podle 
// platné mezinárodní a národní legislativy a smluv.


// NASTAVENÍ
var bn_news_xml = "/index.php/home/xmlnews";          // cesta k xml souboru
var step = 0.1;                             // krok zrychlení         
var speed = 3;                              // počáteční rychlost posunu 
var delay = 50;                            // zpoždění mezi jednotlivými kroky (ms)

// Funkční kód - NEMĚNIT!!!
var current = 0; var elements_data = null; var moving = false; var wheeling = false; function bn_news_init() { var xml_data = new XMLHttpRequest(); xml_data.onreadystatechange = dataReady; xml_data.open("GET", bn_news_xml); try { xml_data.send(); } catch (e) { document.getElementById("bn_news").innerHTML = e.message; } } function dataReady(data_loaded) { if (this.readyState == 4 && this.status == 200) { if (this.responseXML != null) dataLoaded(this.responseXML.documentElement.childNodes); else dataLoaded("Error! Recieved data is NULL!"); } else if (this.readyState == 4 && this.status != 200) { dataLoaded("Error! Status: "+this.status); } } function dataLoaded(bn_data) { elements_data = bn_data; var articles = '<div id="articles">'; for (i=0; i<bn_data.length; i++) {articles += '<a id="art'+i+'" class="article" href="'+bn_data[i].childNodes[4].firstChild.nodeValue+'"><hr><img src="'+bn_data[i].childNodes[3].firstChild.nodeValue+'"><div class="text">'+bn_data[i].childNodes[1].firstChild.nodeValue+'</div><div class="clr"></div></a>'; } articles += '</div>'; var content; content = '<div class="l1"><div class="l2"><span id="title">Nejnovější články</span><div id="bn_arrow_up"><img src="./images/arrow-up.png"></div></div><div id="l3">'+articles+'</div><div class="l2"><div id="bn_arrow_down"><img src="./images/arrow-down.png"></div></div></div><a href="" id="bn_photo"><div id="bn_nadpis"></div></a><div class="clr"></div>'; document.getElementById("bn_news").innerHTML = content; for (i=0; i<bn_data.length; i++) { document.getElementById("art"+i).onmouseover = changeView; } document.getElementById("articles").style.top = "0px"; document.getElementById("bn_arrow_up").onmouseover = arrowUpOver; document.getElementById("bn_arrow_up").onmouseout = arrowOut;document.getElementById("bn_arrow_down").onmouseover = arrowDownOver; document.getElementById("bn_arrow_down").onmouseout = arrowOut; if (window.addEventListener) { document.getElementById("articles").addEventListener('DOMMouseScroll', onWheel, false); } else { document.getElementById("articles").onmousewheel = onWheel; } document.getElementById("art"+current).setAttribute("className","article current"); document.getElementById("art"+current).setAttribute("class","article current"); document.getElementById("bn_photo").style.backgroundImage = 'url("'+elements_data[current].childNodes[2].firstChild.nodeValue+'")'; document.getElementById("bn_photo").setAttribute("href", elements_data[current].childNodes[4].firstChild.nodeValue); document.getElementById("bn_nadpis").innerHTML = elements_data[current].childNodes[0].firstChild.nodeValue; document.getElementById("bn_nadpis").style.top = (parseInt(document.getElementById("bn_photo").offsetHeight) - parseInt(document.getElementById("bn_nadpis").offsetHeight)) + "px"; }function changeView(e) { document.getElementById("art"+current).setAttribute("className","article"); document.getElementById("art"+current).setAttribute("class","article"); if (e) { current = e.currentTarget.id.split("art")[1]; } else if (window.event) { current = window.event.srcElement.id.split("art")[1] || window.event.srcElement.parentElement.id.split("art")[1]; } else { throw ("Event wasn't recognized!"); } document.getElementById("art"+current).setAttribute("className","article current"); document.getElementById("art"+current).setAttribute("class","article current"); document.getElementById("bn_photo").style.backgroundImage = 'url("'+elements_data[current].childNodes[2].firstChild.nodeValue+'")'; document.getElementById("bn_photo").setAttribute("href", elements_data[current].childNodes[4].firstChild.nodeValue); document.getElementById("bn_nadpis").innerHTML = elements_data[current].childNodes[0].firstChild.nodeValue;document.getElementById("bn_nadpis").style.top = (parseInt(document.getElementById("bn_photo").offsetHeight) - parseInt(document.getElementById("bn_nadpis").offsetHeight)) + "px"; } function arrowUpOver(e) { moving = true; moveArticles(parseInt(speed)); } function arrowDownOver(e) { moving = true; moveArticles(-(parseInt(speed))); } function arrowOut(e) { moving = false; } function onWheel(d) { wheeling = true; var delta = 0; if (!d) d = window.event; if (d.wheelDelta) { delta = d.wheelDelta/120; if (window.opera) { delta = -delta; } } else if (d.detail) { delta = -d.detail/3; } if (delta) { moveArticles(parseInt(delta*speed*5)); } if (d.preventDefault) { d.preventDefault(); } d.returnValue = false; } function moveArticles(a) { if ((((parseInt(document.getElementById("articles").style.top)) + a) <= 0 ) && (((parseInt(document.getElementById("articles").style.top)) + a) >= (-(parseInt(document.getElementById("articles").offsetHeight) - parseInt(document.getElementById("l3").offsetHeight))))) {document.getElementById("articles").style.top = ((parseInt(document.getElementById("articles").style.top)) + a) + "px"; if (a > 0) { a += step; } else { a -= step; } if (moving) { setTimeout("moveArticles("+(a)+")", delay); } } else if (moving || wheeling) { if (a > 0) { document.getElementById("articles").style.top = "0px"; } else { document.getElementById("articles").style.top = (-(parseInt(document.getElementById("articles").offsetHeight) - parseInt(document.getElementById("l3").offsetHeight))) + "px"; } } wheeling = false; }
