var lastrssbridgeurl="lastrss/bridge.php";

//var lastrssbridgeurl="http://"+window.location.hostname+"/lastrss/bridge.php";

function createAjaxObj() {
  if (typeof XMLHttpRequest === 'undefined') {
    XMLHttpRequest = function() {
      try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
        catch(e) {}
      try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
        catch(e) {}
      try { return new ActiveXObject("Msxml2.XMLHTTP"); }
        catch(e) {}
      try { return new ActiveXObject("Microsoft.XMLHTTP"); }
        catch(e) {}
    };
  }
  return new XMLHttpRequest();
}

function rssticker_ajax(RSS_id, cachetime, divId, divClass, delay, logicswitch){
this.RSS_id=RSS_id; 
this.cachetime=cachetime;
this.tickerid=divId; 
this.delay=delay; 
this.logicswitch=(typeof logicswitch!="undefined")? logicswitch : "";
this.mouseoverBol=0; 
this.pointer=0;
this.opacitysetting=0.2; 
this.title=[]; 
this.link=[]; 
this.description=[]; 
this.pubdate=[]; 
this.ajaxobj=createAjaxObj();
document.write('<div id="'+divId+'" class="'+divClass+'" >Завантаження...</div>');
if (window.getComputedStyle) 
this.mozopacityisdefined=(window.getComputedStyle(document.getElementById(this.tickerid), "").getPropertyValue("-moz-opacity")==1)? 0 : 1;
this.getAjaxcontent();
}

rssticker_ajax.prototype.getAjaxcontent=function(){
if (this.ajaxobj){
var instanceOfTicker=this;
var parameters="id="+encodeURIComponent(this.RSS_id)+"&cachetime="+this.cachetime+"&bustcache="+new Date().getTime();
this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize();}
this.ajaxobj.open('GET', lastrssbridgeurl+"?"+parameters, true);
this.ajaxobj.send(null);
}
}

rssticker_ajax.prototype.initialize=function(){ 
if (this.ajaxobj.readyState == 4){ 
if (this.ajaxobj.status==200){ 
var xmldata=this.ajaxobj.responseXML;
if(xmldata.getElementsByTagName("item").length==0){ 
document.getElementById(this.tickerid).innerHTML="<b>Помилка</b> відсутня RSS стрічка!<br>"+this.ajaxobj.responseText;
return;
}
var instanceOfTicker=this;
var i;
this.feeditems=xmldata.getElementsByTagName("item");
for (i=0; i<this.feeditems.length; i++){
this.title[i]=this.feeditems[i].getElementsByTagName("title")[0].firstChild.nodeValue;
this.link[i]=this.feeditems[i].getElementsByTagName("link")[0].firstChild.nodeValue;
this.description[i]=this.feeditems[i].getElementsByTagName("description")[0].firstChild.nodeValue;
this.pubdate[i]=this.feeditems[i].getElementsByTagName("pubDate")[0].firstChild.nodeValue;
}
document.getElementById(this.tickerid).onmouseover=function(){instanceOfTicker.mouseoverBol=1;}
document.getElementById(this.tickerid).onmouseout=function(){instanceOfTicker.mouseoverBol=0;}
this.rotatemsg();
}
}
}


rssticker_ajax.prototype.rotatemsg=function(){
var instanceOfTicker=this;
if (this.mouseoverBol==1)
setTimeout(function(){instanceOfTicker.rotatemsg()}, 100);
else{ 
var tickerDiv=document.getElementById(this.tickerid);
var linktitle='<div class="rsstitle"><a href="'+this.link[this.pointer]+'">'+this.title[this.pointer]+'</a></div>';
var description='<div class="rssdescription">'+this.description[this.pointer]+'</div>';
var feeddate='<div class="rssdate">'+this.pubdate[this.pointer]+'</div>';
if (this.logicswitch.indexOf("description")==-1) description="";
if (this.logicswitch.indexOf("date")==-1) feeddate="";
var tickercontent=linktitle+feeddate+description;  
this.fadetransition("reset"); 
tickerDiv.innerHTML=tickercontent;
this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100); 
this.pointer=(this.pointer<this.feeditems.length-1)? this.pointer+1 : 0;
setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay);
}
}

rssticker_ajax.prototype.fadetransition=function(fadetype, timerid){
var tickerDiv=document.getElementById(this.tickerid);
if (fadetype=="reset")
this.opacitysetting=0.2;
if (tickerDiv.filters && tickerDiv.filters[0]){
if (typeof tickerDiv.filters[0].opacity=="number") 
tickerDiv.filters[0].opacity=this.opacitysetting*100;
else 
tickerDiv.style.filter="alpha(opacity="+this.opacitysetting*100+")";
}
else if (typeof tickerDiv.style.MozOpacity!="undefined" && this.mozopacityisdefined){
tickerDiv.style.MozOpacity=this.opacitysetting;
}
if (fadetype=="up") {
this.opacitysetting+=0.2; }
if (fadetype=="up" && this.opacitysetting>=1) {
clearInterval(this[timerid]); }
}
// for talne block
function index(n) {
for(i=1;i<=4;i++) {document.getElementById('tab'+i).className='nazva';
document.getElementById('cont'+i).style.display='none'}
document.getElementById('tab'+n).className='nazva';
document.getElementById('cont'+n).style.display='block';}
// scroll
this.easyscroll = function(){
var id = "myContent";
var nav = ["Вверх &#8593;", "Вниз &#8595;", "На початок"];
var navId = ["btnUp", "btnDown", "btnReset"];
var speed = 5;
var height = 300;
var obj = document.getElementById(id);
	
obj.up = false;
obj.down = false;
obj.fast = false;

var container = document.createElement("div");
var parent = obj.parentNode;
container.id="easyscroll";
parent.insertBefore(container,obj);
parent.removeChild(obj);

container.style.position = "relative";
container.style.height = height + "px";
container.style.overflow = "hidden";
obj.style.position = "absolute";
obj.style.top = "0";
obj.style.left = "0";
container.appendChild(obj);

var btns = new Array();
var ul = document.createElement("ul");
ul.id="easyscrollnav";
for (var i=0;i<nav.length;i++){
var li = document.createElement("li");
li.innerHTML = nav[i];
li.id = navId[i];
btns.push(li);
ul.appendChild(li);
};
parent.insertBefore(ul,container);

btns[0].onmouseover = function(){
obj.up = true;
this.className = "over";
};
btns[0].onmouseout = function(){
obj.up = false;
this.className = "";
};
btns[1].onmouseover = function(){
obj.down = true;
this.className = "over";
};
btns[1].onmouseout = function(){
obj.down = false;
this.className = "";
};
btns[0].onmousedown = btns[1].onmousedown = function(){
obj.fast = true;
};
btns[0].onmouseup = btns[1].onmouseup = function(){
obj.fast = false;
};
btns[2].onmouseover = function(){ 
this.className = "over";
};
btns[2].onmouseout = function(){ 
this.className = "";
};
btns[2].onclick = function(){ 
obj.style.top = "0px";
};

this.start = function(){
var newTop;
var objHeight = obj.offsetHeight;
var top = obj.offsetTop;
var fast = (obj.fast) ? 2 : 1;
if(obj.down){ 
newTop = ((objHeight+top) > height) ? top-(speed*fast) : top;
obj.style.top = newTop + "px";
};
if(obj.up){ 
newTop = (top < 0) ? top+(speed*fast) : top;
obj.style.top = newTop + "px";
};
};
obj.interval = setInterval("start()",50);

};


//
// script initiates on page load. 
//

this.addEvent = function(obj,type,fn){
if(obj.attachEvent){
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn](window.event );}
obj.attachEvent('on'+type, obj[type+fn]);
} else {
obj.addEventListener(type,fn,false);
};
};
addEvent(window,"load",easyscroll);
