﻿var adplayer;function nilAdPlayer(){this.allAds=new Array();this.currActive=-1;this.time=5000;this.timer=null;this.add=adPlayerAdd;this.calcNext=adPlayerCalcNext;this.clearTimer=adPlayerClearTimer;this.generatePlayer=adPlayerGeneratePlayer;this.generateNavigation=adPlayerNavigation;this.getAllAds=adPlayerGetAllAds;this.getItem=adPlayerGetItem;this.playPause=adPlayerPlayPause;this.setTimer=adPlayerSetTimer;this.showItem=adPlayerShowItem;this.step=adPlayerStep;}
function adPlayerGeneratePlayer(){this.getAllAds();this.generateNavigation();this.setTimer();}
function adPlayerGetAllAds(){this.allAds=$("#adPlayer li").get();}
function adPlayerShowItem(n){for(i=0;i<this.allAds.length;i++){if(i==n){this.allAds[i].style.display="";$("#adPlayerNav li:eq("+i+")").addClass("active");}
else{this.allAds[i].style.display="none";$("#adPlayerNav li:eq("+i+")").removeClass("active");}}
this.currActive=n;}
function adPlayerAdd(url,src,alt){$("#adPlayer").append("<li><a href='"+url+"'><img src='"+src+"' alt='"+alt+"' /></a></li>");}
function adPlayerCalcNext(step){var next=(this.currActive+step)%this.allAds.length;if(next<0)next+=this.allAds.length;return next;}
function adPlayerClearTimer(){if(this.timer){clearTimeout(this.timer);this.timer=null;}}
function adPlayerGetItem(n){if(this.timer)this.playPause();this.showItem(n);}
function adPlayerNavigation(){$("#adPlayerNav").css("margin-top","-30px");$("#adPlayerNav").append("<ul></ul>");$("#adPlayerNav").append("<div style='clear: both;'></div>");for(i=0;i<this.allAds.length;i++){$("#adPlayerNav ul").append("<li><a onclick='adplayer.getItem( "+i+" );'>"+(i+1)+"</a></li>");}
$("#adPlayerNav ul").append("<li class='adplay'><a onclick='adplayer.playPause();'>&gt;</a></li>");$("#adPlayerNav ul").append("<li class='adpause'><a onclick='adplayer.playPause();'>||</a></li>");$("#adPlayerNav ul li.adpause").hide();}
function adPlayerPlayPause(){if(this.timer){this.clearTimer();$("#adPlayerNav ul li.adplay").hide();$("#adPlayerNav ul li.adpause").show();}
else{$("#adPlayerNav ul li.adplay").show();$("#adPlayerNav ul li.adpause").hide();this.currActive--;this.setTimer();}}
function adPlayerSetTimer(){var next=adplayer.calcNext(1);adplayer.showItem(next);adplayer.timer=setTimeout("adPlayerSetTimer()",adplayer.time);}
function adPlayerStep(step){var next=this.calcNext(step);if(this.timer)this.playPause();this.showItem(next);}
function loadPlayer(dynamic){adplayer=new nilAdPlayer();if(!dynamic)
adplayer.generatePlayer();}
