/*
    <script type="text/javascript" src="http://kartki.marek.local/kartki.js"></script>
    <script type="text/javascript">
		Popup.showCloseButton = false;
		Popup.show_absolute('bn2008nr2009.jpg', 500, 220, 'center', 'center' );
    </script>	

*/

// domyslny styl
var np_cssfile_ = '/kartki.css';

// domyslny obrazek zamykający
var np_closeimage_ = '/kartki_close.gif';


//////////////////////////////////////////////////
var Popup = {

    customCSS: np_cssfile_,
    closeImage: np_closeimage_,
    showCloseButton: true,
    originalLeft: 0,
    originalTop: 0,
    left: 0,
    top: 0,
    box: null,

    Browser: {
	IE:     !!(window.attachEvent && !window.opera),
	    Opera:  !!window.opera,
	    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
	    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
	    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
    },

    init: function() {	    	    
		this.windowHeight = document.body.clientHeight;
		this.windowWidth = document.body.clientWidth;
		document.writeln('<link rel="StyleSheet" type="text/css" href="'+this.customCSS+'" />');
    },

    redraw: function() {
		this.windowHeight = document.body.clientHeight;
		this.windowWidth = document.body.clientWidth;
	
	if(this.originalLeft=='center') {
	    l = Math.round((this.windowWidth - this.imageWidth)/2);		
	    this.left = l>=0?l:0;
	}
	else { this.left = this.originalLeft; }
	if(this.originalTop=='center') {
	    t = Math.round((this.windowHeight - this.imageHeight)/2);
	    this.top = t>=0?t:0;
	}
	else { this.top = this.originalTop; }
	
	//this.box = document.getElementById('np_kartki');
	this.box.style.left = this.left+'px';
	this.box.style.top = this.top+'px';
	
    },

    show_html_absolute: function( text,imageWidth, imageHeight, left, top) {    
		var l;    
		this.originalTop = top;
		this.originalLeft = left;
		this.imageWidth = imageWidth;
		this.imageHeight = imageHeight;
	
		this.init();
		document.write(
	    	'<div id="np_kartki" class="np_kartki_box" style="width:'+imageWidth+'px;height:'+imageHeight+'px;margin:0px;padding:0px;display:none;">'+
		    (this.showCloseButton?'<div id="np_kartki_belka"><img src="'+this.closeImage+'" border="0" alt="" id="np_close_img"><br /></div>':'')+
		    '<div class="np_kartki_content">'+text+'</div></div>');
		document.close();
	
		this.box = document.getElementById('np_kartki');
		this.box.style.position = 'absolute';
	
	
		if(this.originalLeft=='center') {
		    l = Math.round((this.windowWidth - imageWidth)/2);
	    	this.left = l;
		}
		else { this.left = this.originalLeft; }

		if(this.originalTop=='center') {
		    t = Math.round((this.windowHeight - imageHeight)/2);
	    	this.top = t;
		}
		else { this.top = this.originalTop; }
	
		if(this.left != null) this.box.style.left = this.left+'px';
		if(this.top != null) this.box.style.top = this.top+'px';
		
		this.box.style.display = 'block';
		this.box.style.width = this.imageWidth;
		this.box.style.height = this.imageHeight;
	
	
		if(this.showCloseButton)
		    document.getElementById('np_close_img').onclick = function() { 
			document.getElementById('np_kartki').style.display = 'none';
		}
	    
		if(!window.onresize){ 
	    	window.onresize = function() {
			Popup.redraw();
		    }
		}
		
    }

};


