/**
 * @author Ideatronic
 */
var zoom = new Class({
	initialize:function(element,imgSrc){
		var $this = this;
		this.imgSrc = imgSrc;
		this.createZoomer();
		element.addEvent('click',function(){
			$this.showZoom();
		});
	},
	createZoomer:function(){
		var $this = this;
		this.zoomer = new Element('div', {
		    'class': 'zoomerBox',
			'styles':{
				'display':'none',
				'width':'10px',
				'height':'10px'
			}
		});
		this.closer = new Element('div', {
		    'class': 'zoomerClose',
			'styles':{
				'display':'none',
				'position':'absolute',
				'bottom':'20px',
				'left':'0px',
				'z-index':'1200',
				'opacity':'0.9'
			}	
		});
		
		this.bigImage = new Element('img', {
		    'class': 'zoomerBox',
			'src':this.imgSrc
		});
		
		this.zoomer.zoom = new Fx.Morph(this.zoomer,{duration:700,transition: Fx.Transitions.Sine.easeOut});
		document.body.appendChild(this.zoomer);
		this.zoomer.appendChild(this.bigImage);
		this.zoomer.appendChild(this.closer);
		
		this.closer.innerHTML = 'kliknij aby zamknąć';
		
		this.zoomer.addEvent('click',function(){
			$this.closeZoom();
		});
		this.zoomer.addEvent('mouseenter',function(){
			$this.closer.setStyle('display','');
		});
		this.zoomer.addEvent('mouseleave',function(){
			$this.closer.setStyle('display','none');
		});
		this.closer.addEvent('click',function(){
			$this.closeZoom();
		})
	},
	showZoom:function(){
		var $this = this;
		this.zoomer.setStyles({'display':'block','left':$this.getCenterPage(400,300)[0],'top':$this.getCenterPage(400,300)[1]});
		this.bigImage.setStyles({'width':'auto','height':'auto','margin':'auto'});
		this.zoomer.zoom.start({
			'height':410,
			'width':310
		})
	},
	closeZoom:function(){
		var $this = this;
		this.zoomer.zoom.start({
			'height':0,
			'width':0
		}).chain(function(){
			$this.zoomer.setStyle('display','none');
		})
	},
	getCenterPage:function(x,y){
		var center = [];	
		center[0] = parseInt((window.getWidth()-x)/2)+'px';
		center[1] = parseInt((window.getHeight()-y)/2)+'px';
		return center;			
	}
});

var amountUpdater = new Class({
	initialize:function(holder,amount){
		this.amount = parseInt(amount);
		this.mainObj = $(holder);
		this.add = this.mainObj.getElements('a.increaseVal')[0];
		this.reduce = this.mainObj.getElements('a.decreaseVal')[0];
		this.inputVis = this.mainObj.getElements('input.amountvisible')[0];
		this.inputHid = this.mainObj.getElements('input.amount')[0];
		this.inputVis.value = this.inputHid.value;
		var $this = this;
		this.add.addEvent('click',function(){
			$this.addval();
		});
		this.reduce.addEvent('click',function(){
			$this.reduceval();
		})
	},
	addval:function(){
		this.inputVis.value=parseInt(this.inputHid.value)+this.amount;
		this.inputHid.value=this.inputVis.value;
	},
	reduceval:function(){
		if(parseInt(this.inputVis.value)-this.amount>=0)
		this.inputVis.value=parseInt(this.inputHid.value)-this.amount;
		this.inputHid.value=this.inputVis.value;
	}
})

var popupWind = new Class({
	initialize:function(messageBox){
		this.messageBox = $(messageBox);
		this.windowWidth = window.getSize().x;
		this.windowHeight = document.html.offsetHeight;
		
		this.readCookie();
	},
	readCookie:function(){
		
		var myCookie = Cookie.read('violation');
		if(myCookie=='true')
			return;
		
		this.createObj();
		
	},
	close:function(){
		this.messageBox.setStyle('display','none');
		$('messageBoxBg').setStyle('display','none');
		Cookie.write('violation', 'true', {domain: 'www.skleptytoniowy.pl'});
	},
	getCenterPage:function(x,y){
		var center = [];
		center[0] = parseInt((window.getWidth()-x)/2)+'px';
		center[1] = parseInt((window.getHeight()-y)/2)+'px';
		return center;			
	},
	createObj:function(){		
	/*	this.bg = new Element('div', {
			'styles':{
				'position':'absolute',
				'top':'0px',
				'left':'0px',
				'z-index':'1400',
				'opacity':'1',
				'width':parseInt(this.windowWidth)+'px',
				'height':parseInt(this.windowHeight)+'px',
				'background':'#000000'
			}
		});	
		document.body.appendChild(this.bg);*/
		
		$('messageBoxBg').setStyles({
			'display':'block',
			'height':'100%'
		});
		
		window.addEvent('domready',function(){
			$('messageBoxBg').setStyle('height',window.getScrollSize().y);
			$('messageBoxBg').setStyle('background-position',(window.getScrollSize().x-300)/2+'px '+((10*window.getSize().y)/100)+'px');
		});		
		
		this.messageBox.setStyles({'left':this.getCenterPage(300,130)[0],'top':this.getCenterPage(300,130)[1],'display':'block'});
	}
})
