// Poltergeist - wyskakująca reklama na warstwie ponad stroną, wersja 0.35 var closeButtonUrl="img/dummy.gif"; var startRendering; var frames=0; var frame=0; var positions = new Array(); function createFlash(movie, width, height, background, idName, dest, fVars) { obj_setFlash=document.getElementById(dest); if (obj_setFlash) { pytajnik = ""; if (fVars != "") pytajnik = "?"; objTag = ""; obj_setFlash.innerHTML=objTag+objTag2+paramTag; // alert (obj_setFlash.innerHTML); } } // addLoadEvent() // Adds event to window.onload without overwriting currently assigned onload functions. // Function found at Simon Willison's weblog - http://simon.incutio.com/ function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function'){ window.onload = func; } else { window.onload = function(){ oldonload(); func(); } } } // getPageSize() // Returns array with page width, height and window width, height // Core code from - quirksmode.org // Edit for Firefox by pHaez function getPageSize(){ var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { // all except Explorer windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } // for small pages with total width less then width of the viewport if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) return arrayPageSize; } // getPageScroll() // Returns array with x,y page scroll values. // Core code from - quirksmode.org function getPageScroll(){ var yScroll; if (self.pageYOffset) { yScroll = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict yScroll = document.documentElement.scrollTop; } else if (document.body) {// all other Explorers yScroll = document.body.scrollTop; } arrayPageScroll = new Array('',yScroll) return arrayPageScroll; } // Usuwa obiekt Poltergeist z ekranu function killPoltergeist() { document.getElementById('poltergeistWrapper').style.display="none"; document.getElementById('poltergeist').style.display="none"; window.onscroll = function () { return true; } } // Powoduje animowany ruch Poltergeista function slidePoltergeist(duration, fps, direction, percX, percY) { var posY; var arrayPageSize=getPageSize(); var arrayScrollSize=getPageScroll(); var width=400; //document.getElementById('poltergeistAdvert').width; var height=250; //document.getElementById('poltergeistAdvert').height; // Końcowe położenie obiektu Poltergeist - jeśli rozmiar okna zostanie // zmieniony podczas trwania animacji Poltergeist dostosuje sie destX=Math.round((arrayPageSize[2]*(percX/100))-(width/2)); destY=Math.round((arrayPageSize[3]*(percY/100))-(height/2)); if (direction) { switch (direction) { case "top": { step = Math.floor(Math.abs((destY+height))/frames); posY=step*frame+arrayScrollSize[1]-height; posX=destX; break; } case "bottom": { step = Math.floor(Math.abs((destX+height))/frames); posY=arrayPageSize[3]+arrayScrollSize[1]-(step*frame); posX=destX; break; } case "left": { step = Math.floor(Math.abs((destX+width))/frames); posX=step*frame-width; posY=destY+arrayScrollSize[1]; break; } case "right": { step = Math.floor(Math.abs((destX+width))/frames); posX=arrayPageSize[2]-(step*frame); posY=destY+arrayScrollSize[1]; break; } case "none": { posX=destX; posY=destY+arrayScrollSize[1]; movePoltergeist(posX, posY); // Obiekt Poltergeist będzie przesuwał się wraz ze stroną window.onscroll = function () { scrollPoltergeist(percX, percY);} // Wyłączenie animacji clearInterval(startRendering); break; } } movePoltergeist(posX, posY); // Przy pierwszej klatce animacji należy odsłonić Poltergeista if (frame==0) document.getElementById('poltergeist').style.visibility="visible"; frame++; // Zakończenie animacji if (frame>=frames) { // Obiekt Poltergeist będzie przesuwał się wraz ze stroną window.onscroll = function () { scrollPoltergeist(percX, percY);} // Obiekt Poltergeist ustawiany jest na finałowym miejscu - sam tam najprawdopodobniej // nie dojedzie, ze względu na błędy zaokrągleń przy obliczaniu kroku movePoltergeist(destX, destY+arrayScrollSize[1]); // Wyłączenie animacji clearInterval(startRendering); } } else { // Obiekt Poltergeist będzie przesuwał się wraz ze stroną window.onscroll = function () { scrollPoltergeist(percX, percY);} // Wyłączenie animacji clearInterval(startRendering); } } function createPoltergeist(advertImgUrl, closeOrginX, closeOrginY, closeWidth, closeHeight, duration, fps, direction, percX, percY, multipleRuns, linkOrginX, linkOrginY, linkWidth, linkHeight, linkURL, newWindow) { if (multipleRuns==true || !alreadyRunned()) { advertImg = new Image(); // Jeśli ścieżka do obrazka będzie błędna, Poltergeist nie zostanie wogóle stworzony advertImg.onload = function() { // Zabezpieczenie na wypadek nie podania podstawowych danych if (!closeOrginX) closeOrginX=0; if (!closeOrginY) closeOrginY=0; if (!closeWidth) closeWidth=25; if (!closeHeight) closeHeight=25; if (!duration) duration=1000; if (!fps) fps=25; if (!direction) direction="top"; if (!percX) percX=50; if (!percY) percY=50; // Tworzy następujący kawałek kodu html //
//poltergeistWrapper = document.createElement('div'); //poltergeistWrapper.setAttribute('id','poltergeistWrapper'); poltergeistBase = document.createElement('div'); poltergeistBase.setAttribute('id','poltergeist'); poltergeistBase.style.position = "absolute"; poltergeistBase.style.zIndex = "1000001"; closeButton = new Image(); //closeButton.src = closeButtonUrl; closeButton.src = 'grafika/pix.gif'; closeButton.setAttribute('id','poltergeistCloseButton'); closeButton.style.top=closeOrginY+"px"; closeButton.style.left=closeOrginX+"px"; closeButton.style.width=closeWidth+"px"; closeButton.style.height=closeHeight+"px"; closeButton.style.position = "absolute"; closeButton.style.zIndex = "100"; closeButton.style.cursor = "pointer"; if (linkOrginX && linkOrginY && linkWidth && linkHeight && linkURL) { linkArea = document.createElement("a"); linkArea.href=linkURL; if (newWindow==true) linkArea.target='_blank'; linkArea.setAttribute('id','poltergeistLinkArea'); linkArea.innerHTML='
';
linkArea.style.top=linkOrginY+"px";
linkArea.style.left=linkOrginX+"px";
linkArea.style.width=linkWidth+"px";
linkArea.style.height=linkHeight+"px";
}
flashElement = document.createElement ('div');
flashElement.setAttribute('id','poltergeistAdvert');
flashElement.style.position = "absolute";
flashElement.style.zIndex = "10";
/*
imageElement = document.createElement('img');
imageElement.setAttribute('id','poltergeistAdvert');
imageElement.src = advertImgUrl;
*/
//poltergeistWrapper.appendChild(poltergeistBase);
poltergeistBase.appendChild(closeButton);
if (linkOrginX && linkOrginY && linkWidth && linkHeight && linkURL) poltergeistBase.appendChild(linkArea);
//poltergeistBase.appendChild(imageElement);
poltergeistBase.appendChild(flashElement);
//document.getElementsByTagName("body")[0].appendChild(poltergeistWrapper);
document.getElementsByTagName("body")[0].appendChild(poltergeistBase);
document.getElementById('poltergeistCloseButton').onclick = function () {killPoltergeist();}
// Oblicza długość animacji i uruchamia ją
frames = Math.round(fps*duration/1000); // Calkowita liczba renderowanych klatek
interval = duration / frames; // Czas co jaki jest renderowana nowa ramka
//slidePoltergeist(duration, fps, direction, percX, percY);
//startRendering=setInterval("slidePoltergeist("+duration+", "+fps+", \""+direction+"\", "+percX+", "+percY+")", interval);
createFlash ('flash/toplayer.swf', '600', '675', '#000000', 'flashContentCreated02', 'poltergeistAdvert', '');
document.getElementById('poltergeistWrapper').style.display = "block";
$('poltergeist').setStyle({
top: percY + '%',
left: percX + '%'
});
}
advertImg.src = advertImgUrl;
}
}
// Powoduje przesunięcie obiektu Poltergeist w nowe miejsce
function movePoltergeist(x, y)
{
document.getElementById('poltergeist').style.top=y+"px";
document.getElementById('poltergeist').style.left=x+"px";
}
// Powoduje przesuwanie obiektu Poltergeist wraz ze scrollowaniem strony
function scrollPoltergeist(percX, percY)
{
var arrayPageSize=getPageSize();
var arrayScrollSize=getPageScroll();
var width=400;
//document.getElementById('poltergeistAdvert').width;
var height=250;
//document.getElementById('poltergeistAdvert').height;
destX=Math.round((arrayPageSize[2]*(percX/100))-(width/2));
destY=arrayScrollSize[1]+Math.round((arrayPageSize[3]*(percY/100))-(height/2));
movePoltergeist(destX, destY);
}
// From http://www.w3schools.com/js/js_cookies.asp
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function alreadyRunned()
{
if (getCookie("poltergeist")=="")
{
document.cookie="poltergeist=yes";
return false;
}
return true;
}