/*  SkyBytePV.js , Jul 01 2007
 *  (c) 2007 Aleksandras Ilarionovas (Alex)
 *
 *  SkyBytePV.js is freely distributable under the terms of an MIT-style license.
 *  For details, see the SkyByte.net web site: http://www.skybyte.net/scripts/
 *--------------------------------------------------------------------------*/

if(typeof Prototype == 'undefined')  { throw("SkyBytePV.js requires Prototype.js library"); }

var PVS = {
	divs   : [],
	hide   : { x:-100, y:-100, w:0, h:0	},
	pointer: { x:0, y:0 },
	active : null,
	enable : true,
	bigsmall: false,
	register: function(obj) {
		if(this.divs.length == 0){
			Mouse.start(this);
			this.div = Element.add('div',{},{position:'absolute',zIndex:'999',top:'-500px',left:'-500px',padding:'6px',border:'1px solid #555',background:'#fff'},{a:document.body});
			this.divs.push(1);
			var c=Cookie.get('PVCookie');
			if(c==null){
				this.enable=true; //alert('no cookie, default enabled');
			}else if(c.indexOf("1")!=-1){
				this.enable=true; //alert('enabled');
			}else if(c.indexOf("0")!=-1){
				this.enable=false; //alert('disabled');
			}
		}
	},
	_mouseMove:function(e){
		if(this.active && this.enable){
			this.show_frame(this.active);
		}
	},
	show_frame: function(el){
		this.active=el; this.div.innerHTML='';
		if(this.bigsmall){
			var el2=new Image(); el2.src=el.src.replace("/small/", "/big/");
			if (el2.complete){ /*image load complete*/ }else{ /*image loading*/ }
		}else{
			var el2=el.cloneNode(true); el2.style.width='auto';  el2.style.height='auto'; el2.style.display='block';
		}
		
		var o=this.div.appendChild(el2);  var p=Element.wh(o);
		this.div.style.width=p.w;  this.div.style.height=p.h;  this.div.zIndex='999';

		x=Mouse.x+15; y=Mouse.y+15; w=p.w; h=p.h; var o=UI._wSize(); var px=o.px/2; var py=o.py/2; 
		if(x>px){ x=x-w-30; } if(y>py){ y=y-h-40; }
		Element.showAt(this.div,{x:x, y:y, w:w, h:h});
	},
	hide_frame: function(){
		this.active=false;
		if(this.divs.length>0){
			this.div.innerHTML='';
			Element.showAt(this.div,this.hide);
		}
	}
}
//---------------------------------------------------------------------------------------------
var PV = Class.create();
PV.prototype = {
	initialize: function(el){
		this.element = $(el);
		if(this.element){
			Event.observe(this.element, "mouseover",this._mouseOver.bindAsEventListener(this));
			Event.observe(this.element, "mouseout",	this._mouseOut.bindAsEventListener(this));
			PVS.register();
		}
	},
	_mouseOver:function(e){
		if(!PVS.enable){ return; }
		var el=Event.element(e);
		PVS.show_frame(el);
	},
	_mouseOut:function(e){
		if(!PVS.enable){ return; }
		PVS.hide_frame();
	}
}
//---------------------------------------------------------------------------------------------
