﻿//////////////////////////////////////////////////////////
//
//		LightAlert v1.0
//
//
//		Author	: Olcay UZUN
//		Date	: 06/11/2008 - Monday
//		Version	: 0.1
//		Copy	: Aydın Web Center / Antalya
//
//////////////////////////////////////////////////////////

var ikAlerter = new Class({
	options: {
		title_text: "Uyarı",
		btn_text:	"X Kapat",
		ps_height:		150,
		ps_width:		400
	},
	
	initialize: function(options){

		this.setOptions(options);

		if(document.getElementById) {
			window.alert = function(alertText) {
				this._createAlert(alertText);
			}.bind(this)
		}

	},

	_createAlert: function(aText){

		if (!$("alertLoad"))
		{
			var alertLoad = new Element("div", {"id": "alertLoad"})
				.setStyle("width", window.getScrollWidth())
				.setStyle("height", window.getScrollHeight())
				.setStyle("top", 0)
				.setStyle("left", 0)
				.injectInside(document.body)
				.setOpacity(0)
				
				new Fx.Style(alertLoad, 'opacity', {duration: 200, transition: Fx.Transitions.sineInOut}).start(0, 0.6);
			
			var aContainer = new Element("div",{"id":"alertContainer"})
				.setStyle("left",((window.getWidth() - this.options.ps_width)/2)+'px')
				//.setStyle("top",((window.getScrollTop() + window.getHeight()) / 2) - this.options.ps_height)
				.setStyle("top",((window.getScrollTop() + window.getHeight()) / 2)+'px')
				.injectInside(document.body)
				.setOpacity(0)

				new Fx.Style(aContainer, 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut}).start(0,1);

				var alertTitle = new Element("div",{"id":"alertTitle"})
					.injectInside(aContainer)

				var titleText = new Element("div",{"id":"titleText"})
					.injectInside(alertTitle)
					.setText(this.options.title_text)

				var closeButton = new Element("div",{"id":"closeButton"})
					.injectInside(alertTitle)
					.setHTML(this.options.btn_text)
					.addEvent("click",function(){
						this._removeAlert(aContainer, alertLoad);
					}.bind(this));

				var alertImg = new Element("div",{"id":"alertImg"})
					.injectInside(aContainer)
					.setHTML("<img src=../i/alerticon.png /></img>")

				var alertMessage = new Element("div",{"id":"alertMessage"})
					.injectInside(aContainer)
					.setText(aText)

					this._positionEffect(aContainer);

					window.onscroll = function(){
						this._positionEffect(aContainer);
					}.bind(this)

					window.onresize = function(){
						this._positionEffect(aContainer);
					}.bind(this)
		}

	},

	_positionEffect: function(positionContainer){
		new Fx.Styles(positionContainer, {duration: 75, transition: Fx.Transitions.sineInOut}).start({
			'left':(window.getScrollLeft() + (window.getWidth() - this.options.ps_width)/2)+'px',
			'top':(window.getScrollTop() + (window.getHeight() - this.options.ps_height)/2)+'px'});
	},

	_removeAlert: function(removeContainer, loadContainer){

		new Fx.Style(removeContainer, 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut, onComplete:function(){removeContainer.remove();} }).start(1,0);
		new Fx.Style(loadContainer, 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut, onComplete:function(){loadContainer.remove();} }).start(0.9,0);
	}


});

ikAlerter.implement(new Events);
ikAlerter.implement(new Options);