/*
---------------------------------------------------------------------------------------------------------
	** jDiv v1.1 ** 
	Autor: Robert J. Kurek
	Kontakt: pcrob@o2.pl, http://rkurek.xon.pl
	Licencja: skrypt darmowy (również w przypadku użycia komercyjnego)
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	Skrypt testowano pod: 
	IE7, Firefox 3.04, Google Chrome 1.0.154.36, Safari 3.2.1, Opera 9.63
	Ostatnia modyfikacja: 02.01.2009

	UWAGA !!!
	Drobne zmiany skryptu, jak np. zmiana nazw funkcji, dodanie bądź zmiana kilku linijek kodu,
	nie uprawnią do usunięcia lub zmiany komentarza podającego autora.
	Usunięcie ze skryptu informacji o autorze, jak i dokonywanie nieautoryzowanych 
	zmian kodu skryptu stanowi złamanie praw autorskich.
	NIE usuwaj tego komentarza! (Do NOT remove this comment!)
-------------------------------------------------------------------------------------------------------
*/

// Instalacja:
// 1) .
// w  pliku HTML:
// <script type="text/javascript" src="flaDiv.js"></script> w  sekcji - <head>

// <script type="text/javascript">
// flaDiv('1.gif', 550,400,100, '01.01.2009', 'http://wp.pl');   -  w sekcji <body>
// </script>

// 2).
// Argumenty funcji:
// plik:  *.html, *.swf, *.jpg, *.gif, *.png,  szerokość,  wysokość,  odległość_w_pionie (px),  'dzień.miesiąc.rok' , czas_zamknięcia_w_sek.  'link_do_strony'
// dzień.miesiąc.rok  - data wygaśnięcia reklamy


// 3).
//  Akcja przycisku w filmie flasha:
//    on (release) {
// 	  getURL("javascript:ukryj() ;");
//  }


// ** KOD SKRYPTU **

var licznik_czasu_div=0; 

// Licznik czasu
function stoper_div(czas) {
licznik_czasu_div++;
if ( licznik_czasu_div>czas ) {
clearInterval(c_licznik_czasu);
ukryj();
  }
 }


 // Animacja warstwy
function Ruch(h) {
var a=5; // parametr inercji (im większy tym wolniej)
var y=document.getElementById('reklama');
y.style.top = ( parseInt(y.style.top)+(parseInt(h)-parseInt(y.style.top))/a )+'px';

 if ( parseInt(y.style.top)<=h ) clearInterval(Y_ruch);

}

function start_ruch(){
 if ( document.getElementById('reklama')!=null) {
  document.getElementById('reklama').style.top=parseInt(3.5*window.screen.height)+'px';
  Y_ruch=setInterval("Ruch(T)",75);
  }
}

 // Odpal animację warstwy
window.onload=start_ruch;

 
 // -  Główna funkcja programu  -
function flaDiv(p,w,h,t, dmr, tz, url) {

    var N = p;  // Nazwa obrazka (animacji.swf)
	var W = w;  // Szerokość animacji
	var H = h;  // Wysokość animacji
	
	T = t;      // Odległość w pionie ( występuje w funkcji - Ruch(T) )
    Tzam=tz;    // Zmienna czasu zamknięcia warstwy
	
	
var czas0=new Date();
var r0= czas0.getFullYear();
var m0=czas0.getMonth();
var d0=czas0.getDate();

// Obróbka daty: dd.mm.rrrr
var str=dmr.split('.');
var r=parseInt(str[2]);
var m=parseInt(str[1]);
var d=parseInt(str[0]);
var mm=m-1;

var data1=new Date(r0, m0, d0);
var data2=new Date(r, mm, d);	
var okres=data2-data1;
	
var t=T+'px';
var L=window.screen.width;
var x=(L-W)/2+'px';

 // Sprawdzanie rozszerzenia pliku...
 
	var roz=N.substring(N.length,N.length-4).toLowerCase();
	var roz2=N.substring(N.length,N.length-5).toLowerCase();

	
 if ( document.cookie.indexOf('jdiv')==-1 && okres>0 && Tzam>0 ) {
 
 // Dozwolone formaty plików graficznych:
 if ( roz == '.jpg' || roz == '.gif' || roz == '.png'  ) {
 
  document.write('<div id="reklama" style="z-index:9999; background:transparent; position:absolute;left:'+x+';">');
 
  document.write('<div style="padding-bottom:5px; text-align:right;">');
  // document.write('<button id="bu" onclick="ukryj(); return(false);"> x </button>');
  document.write('<button id="bu" onclick="ukryj(); return(false);"> x </button> <button id="bi" onclick="alert(\'jDiv v1.1\\n&copy; R.Kurek\\nhttp://zsti.pl\'); return(false);"> ? </button>');
  document.write('</div>');
  
  // Obrazek:
  document.write('<img id="foto" width="'+W+'" src="'+N+'" />');
  document.write('</div>');
  document.getElementById('foto').style.border='14px ridge #efefef';
  
  // Błąd ładowania obrazka
 document.getElementById('foto').onerror = function() { 
 alert ('Nie można załadować pliku: '+N); 
 ukryj();
   }
 
 
 // Jeśli podano adres url
 if ( url !=null && url !='') {
 
 document.getElementById('foto').style.cursor='pointer';
 document.getElementById('foto').title='Zobacz więcej ...';

 document.getElementById('foto').onmouseover = function() { 
 document.getElementById('foto').style.border='14px ridge #ff0000';
  }
 
 document.getElementById('foto').onmouseout = function() { 
 document.getElementById('foto').style.border='14px ridge #efefef';
  }
  
  
 document.getElementById('foto').onclick = function() { 
 var URL=url;
 window.location=URL;
 ukryj();
  }
  
}
 
// Dodatkowa podmianka obrazka dla - onmousedown

 // a=new Image(); 
 // b=new Image();

 // a.src='zyczenia2.jpg'; // nowy obrazek
 // b.src=p;
 
 // document.getElementById('foto').onmousedown = function() { 
 // document.getElementById('foto').src=a.src;
 // }
 
 // document.getElementById('foto').onmouseup = function() { 
 // document.getElementById('foto').src=b.src;
 // }

   // Style przycisku zamykania i info o autorze:
   style_przyciskow();
 
 }
 
 else if ( roz == '.swf'  ){
 document.write('<div id="reklama" style="z-index:1000; position:absolute; left:'+x+';">');
 document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+W+'" height="'+H+'" align="middle">');
 document.write('<param name="allowScriptAccess" value="sameDomain" />');
 document.write('<param name="movie" value="'+N+'" />');
 document.write('<param name="quality" value="high" />');
 document.write('<param name="wmode" value="transparent" />');
 document.write('<param name="menu" value="false" />');
 document.write('<embed src="'+N+'" menu="false" quality="high" wmode="transparent" width="'+W+'"'+' height="'+H+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
 document.write('</object>');
 document.write('</div>');
     }
	 
	 
	  else if ( roz == '.htm' ||  roz2 == '.html'  ){
	  
	 document.write('<div id="reklama" style="z-index:9999; position:absolute; left:'+x+';">');
     document.write('<div style="padding-bottom:5px; text-align:right;">');
     // document.write('<button id="bu" onclick="ukryj(); return(false);"> x </button>');
     document.write('<button id="bu" onclick="ukryj(); return(false);"> x </button> <button id="bi" onclick="alert(\'jDiv v1.1\\nhttp://zsti.pl\'); return(false);"> ? </button>');
     document.write('</div>');
	 
	 document.write('<iframe id="ijd" style="background:#fff;" width="'+W+'"'+'height="'+H+'"'+'src="'+N+'"></iframe>');
	 document.write('</div>');
	 
	 // Style przycisku zamykania, info o autorze oraz iframe
	 style_przyciskow();
	 style_ifrme();
	 
	  }
	 
	 // Zewnętrza strona WWW ...
	  else if ( N.indexOf('http://')!=-1 )  {
	  
	 document.write('<div id="reklama" style="z-index:9999; position:absolute; left:'+x+';">');
     document.write('<div style="padding-bottom:5px; text-align:right;">');
     // document.write('<button id="bu" onclick="ukryj(); return(false);"> x </button>');
     document.write('<button id="bu" onclick="ukryj(); return(false);"> x </button> <button id="bi" onclick="alert(\'jDiv v1.1\\nhttp://zsti.pl\'); return(false);"> ? </button>');
     document.write('</div>');
	 
	 document.write('<iframe id="ijd" style="background:#fff;" width="'+W+'"'+'height="'+H+'"'+'src="'+N+'"></iframe>');
	 document.write('</div>');
	 
	 // Style przycisku zamykania, info o autorze oraz iframe
	 style_przyciskow();
	 style_ifrme();
	  }
	 
	 
	 else {
	 alert('Nieznany format pliku: '+N);
	 }
  }
  
  // Ukryj warstwę po czasie t
  if ( document.getElementById('reklama')!=null) {
    c_licznik_czasu=setInterval("stoper_div(Tzam)",1000);
	}
  
}

// Zamykanie warstwy <div> o id = "reklama" i ustawienie Cookie
function ukryj() {
 if ( document.getElementById('reklama')!=null) {
 document.getElementById('reklama').style.display='none';
 clearInterval(c_licznik_czasu);
 document.cookie = "jdiv=" + "0123"; 
  }
}



function style_przyciskow() {

    // Style przycisku:
	// [x]
	document.getElementById('bu').title='Zamknij ...';
	document.getElementById('bu').style.color='red';
	document.getElementById('bu').style.fontWeight='bold';
 
	// [?]
	document.getElementById('bi').title='O skrypcie ...';
	document.getElementById('bi').style.color='green';
	
	// Rozpoznawanie MS IE
	if ( navigator.appName.indexOf('Microsoft')!=-1 ) {
		document.getElementById('bi').style.width='23px';
		document.getElementById('bu').style.width='23px';
	}
	document.getElementById('bi').style.fontWeight='bold';
	
	
}


function style_ifrme() {
     // Style ramki <iframe>:
	document.getElementById('ijd').style.border='none';
    // document.getElementById('ijd').style.background='transparent';
}

// ** KONIEC KODU. **