/*
	damnJS, 0.8-theta (02072009131042)
	@package: Core framework

	@author: Jakub Ziółkowski (jakub.ziolkowski@dlk24.pl)
	@www: www.creativeboy.pl/code/damnJS
	@license: MIT
*/


(function() 
{
	/* Dodaj wybrane elementy do obiektu */
	function _$(els) 
	{
//SE.log(this);
		this.elements = [];

		for (var i=0; i<els.length; i++) 
		{
			var element = els[i];
			if (typeof element == 'string') 
			{
				element = getElementsBySelector(element);
				for (var i=0; i<element.length; i++) 
					this.elements.push(element[i]);

			} else 
				this.elements.push(element); 
		}
	return this;
	}


	_$.prototype = 
	{
		/* Wybierz elementy z obiektu */
		each: function(fn) 
		{
			for ( var i = 0, len = this.elements.length; i<len; ++i ) 
			{
				fn.call(this, this.elements[i]);
			}
		return this;
		},

		/* Dodaj wlasna class do elementu */
		addClass: function(className) 
		{
			this.each(function(el) 
			{
				el.className += ' '+className;
			});
		return this;
		},

		/* Dodaj zdarzenie do elementu */
		addEvent: function(type, fn) 
		{
			var listen = function(el) 
			{
				if (window.addEventListener) 
				{
				  el.addEventListener(type, fn, false);
				} 
				else 
					if (window.attachEvent) 
					{
						el.attachEvent('on'+type, function() 
						{
							fn.call(el, window.event);
						});
        			}
      		};
			this.each(function(el) 
			{
				listen(el);
			});
		return this;
		},

		addEvents: function(arraya)
		{
			for (a in arraya)
			{
				this.addEvent(a, arraya[a]);
			}
		},

		

		css: function(arraya)
		{
			for (a in arraya)
			{
				this.setCss(a, arraya[a]);
			}
		},


		setClass: function(newclass){
			this.each(function(el) 
			{
							el.className = newclass;(el);
			});

		},
		addClass: function(newclass){
			this.each(function(el) 
			{
							el.className += ' ' + newclass;(el);
			});

		},
		delProperty: function(prop){
			this.each(function(el) 
			{
							delete el.prop// += ' ' + newclass;(el);
			});

		},

		/* Ustaw wlasnosc css elementu */
		setCss: function(p, val) 
		{
			p = p.replace(/\-(.)/g, function(m, l){return l.toUpperCase()})
			this.each(function(el) 
			{
				if (p == 'opacity'){
					val = val.toString();val = val.replace(/px/,'');

					if (val == 0 && el.style.visibility != "hidden") el.style.visibility = "hidden";
					else if (el.style.visibility != "visible") el.style.visibility = "visible";
					if (window.ActiveXObject) el.style.filter = "alpha(opacity=" + val + ")";
	
				} 
				el.style[p] = (p=='opacity')?val/100:val;
			});
		return this;
		},

		/* Pobierz wlasnosc css elementu */
		getCss: function(property) 
		{
			propertyA = property.replace(/\-(.)/g, function(m, l){return l.toUpperCase()})
			var value
			this.each(function(el) 
			{
				if (window.getComputedStyle)
				{
					if (el == document) el = document.body;
				//	dbg(el);
					value = document.defaultView.getComputedStyle(el,null).getPropertyValue(property);
				}
				else 
					if (el.currentStyle)
						value = el.currentStyle[propertyA];
			});
		return value;
		},
		exist: function() {
			return this.elements.length;
		},
		nextObject: function() {
		/*	var n = this;
			do n = n.nextSibling;
			while (n && n.nodeType != 1);
			return n;*/
			/*var n 
			this.each(function(el) {
				n = el;
			});	*/
			return el;
		}


	};

	window.$ = function() 
	{
		return new _$(arguments);
	}

})();

function dbg(what){ var output;
	if(typeof what == "undefined") {output = "undefined"} else {
	if(typeof what == "string")
		{output = "\n(string) " + what;}
	else
		{output = "\n(object) size: " + what.length + "\n";
		for(var prop in what)
			output += prop + ' -> ' + what[prop] + "\n"
		}
	}
	alert(output)

}


/*
	Dopina wlasnosci/metody obiektu do innego obiektu
*/

Function.prototype.bind = function(object) 
{
	var __method = this;
	return function() 
	{
		return __method.apply(object, arguments);
	}
};

/*
	Wykonuje funkcje, co /t/ sekund
*/
Function.prototype.periodical = function(t) 
{
	setInterval(this, t);
}

//Get DOM elements based on the given CSS Selector - V 1.00.A Beta
//http://www.openjs.com/scripts/dom/css_selector/
function getElementsBySelector(all_selectors) {
	var selected = new Array();
	if(!document.getElementsByTagName) return selected;
	all_selectors = all_selectors.replace(/\s*([^\w])\s*/g,"$1");//Remove the 'beutification' spaces
	var selectors = all_selectors.split(",");
	// Grab all of the tagName elements within current context	
	var getElements = function(context,tag) {
		if (!tag) tag = '*';
		// Get elements matching tag, filter them for class selector
		var found = new Array;
		for (var a=0,len=context.length; con=context[a],a<len; a++) {
			var eles;
			if (tag == '*') eles = con.all ? con.all : con.getElementsByTagName("*");
			else eles = con.getElementsByTagName(tag);

			for(var b=0,leng=eles.length;b<leng; b++) found.push(eles[b]);
		}
		return found;
	}

	COMMA:
	for(var i=0,len1=selectors.length; selector=selectors[i],i<len1; i++) {
		var context = new Array(document);
		var inheriters = selector.split(" ");

		SPACE:
		for(var j=0,len2=inheriters.length; element=inheriters[j],j<len2;j++) {
			//This part is to make sure that it is not part of a CSS3 Selector
			var left_bracket = element.indexOf("[");
			var right_bracket = element.indexOf("]");
			var pos = element.indexOf("#");//ID
			if(pos+1 && !(pos>left_bracket&&pos<right_bracket)) {
				var parts = element.split("#");
				var tag = parts[0];
				var id = parts[1];
				var ele = document.getElementById(id);
				if(!ele || (tag && ele.nodeName.toLowerCase() != tag)) { //Specified element not found
					continue COMMA;
				}
				context = new Array(ele);
				continue SPACE;
			}

			pos = element.indexOf(".");//Class
			if(pos+1 && !(pos>left_bracket&&pos<right_bracket)) {
				var parts = element.split('.');
				var tag = parts[0];
				var class_name = parts[1];

				var found = getElements(context,tag);
				context = new Array;
 				for (var l=0,len=found.length; fnd=found[l],l<len; l++) {
 					if(fnd.className && fnd.className.match(new RegExp('(^|\s)'+class_name+'(\s|$)'))) context.push(fnd);
 				}
				continue SPACE;
			}

			if(element.indexOf('[')+1) {//If the char '[' appears, that means it needs CSS 3 parsing
				// Code to deal with attribute selectors
				if (element.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?['"]?([^\]'"]*)['"]?\]$/)) {
					var tag = RegExp.$1;
					var attr = RegExp.$2;
					var operator = RegExp.$3;
					var value = RegExp.$4;
				}
				var found = getElements(context,tag);
				context = new Array;
				for (var l=0,len=found.length; fnd=found[l],l<len; l++) {
 					if(operator=='=' && fnd.getAttribute(attr) != value) continue;
					if(operator=='~' && !fnd.getAttribute(attr).match(new RegExp('(^|\\s)'+value+'(\\s|$)'))) continue;
					if(operator=='|' && !fnd.getAttribute(attr).match(new RegExp('^'+value+'-?'))) continue;
					if(operator=='^' && fnd.getAttribute(attr).indexOf(value)!=0) continue;
					if(operator=='$' && fnd.getAttribute(attr).lastIndexOf(value)!=(fnd.getAttribute(attr).length-value.length)) continue;
					if(operator=='*' && !(fnd.getAttribute(attr).indexOf(value)+1)) continue;
					else if(!fnd.getAttribute(attr)) continue;
					context.push(fnd);
 				}

				continue SPACE;
			}

			//Tag selectors - no class or id specified.
			var found = getElements(context,element);
			context = found;
		}
		for (var o=0,len=context.length;o<len; o++) selected.push(context[o]);
	}
	//alert(selected.toSource());
	return selected;
	
}


ajax = function(url, options)
{
		this.transport = this.getTransport();
		this.postBody = options.postBody || '';
		this.method = options.method || 'post';
		this.onComplete = options.onComplete || null;
		this.update = $(options.update) || null;
		this.request(url);
};

ajax.prototype = {
	request: function(url){
		this.transport.open(this.method, url, true);
		this.transport.onreadystatechange = this.onStateChange.bind(this);
		if (this.method == 'post') {
			this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
		}
		this.transport.send(this.postBody);
	},

	onStateChange: function(){
		if (this.transport.readyState == 4 && this.transport.status == 200) {
			if (this.onComplete) 
				setTimeout(function(){this.onComplete(this.transport);}.bind(this), 10);
			if (this.update)
				setTimeout(function(){this.update.innerHTML = this.transport.responseText;}.bind(this), 10);
			this.transport.onreadystatechange = function(){};
		}
	},

	getTransport: function() {
		if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
		else if (window.XMLHttpRequest) return new XMLHttpRequest();
		else return false;
	}
};





/*
	damnJS, 0.8-theta (02072009131042)
	@package: Eff.Css library

	@author: Jakub Ziółkowski (jakub.ziolkowski@dlk24.pl)
	@www: www.creativeboy.pl/code/damnJS
	@license: MIT
*/

var Eff = Eff || {};

Eff.Css = function(el, options)
{
	//alert('this is constructor?')
	this.options = options
this.options['speed'] = this.options['speed']/10
	this.el = el;
	this.el.ready = true;
};

Eff.Css.prototype = 
{
	morpher: function()
	{
		if(this.step < this.speed)
		{
			this.step++
			for(prop in this.transition)
			{	
				//if(prop = "opacity") {this.transition[prop][this.step].replace(/px/,'');}
				this.el.setCss(prop, this.transition[prop][this.step]) 
			}
		} else 
			{
				 	if (typeof this.options['onComplete'] != "undefined") this.options['onComplete']()
				this.step = 0;
				clearInterval(this.timer);this.timer = undefined;
				this.transition[prop] = [];
				this.el.ready = true;
			}
	},

	colorTransition: function(colorFrom, colorTo, speed)
	{
		transitionArray = []
		from = to = [];
	
		from = colorToRGB(colorFrom)
		if(from == "transparent") { from = "rgb(255,255,255)" }//FIXME from z parent elelentu}
		to = colorToRGB(colorTo)
	
		out = []	

		for(var i=0;i<=speed;i++)
		{
			transitionArray.push('rgb('+Math.floor(this.options['transition'](i,from['r'],to['r']-from['r'],speed))+', '
						 +Math.floor(this.options['transition'](i,from['g'],to['g']-from['g'],speed))+', '
						 +Math.floor(this.options['transition'](i,from['b'],to['b']-from['b'],speed))+')'.replace(/NaN/, ''))
		}
	return transitionArray;
	},

	getTransition: function(begin, end, speed)
	{
		transitionArray = []

		for(var i=0;i<=speed;i++) 
		{
			transitionArray.push(Math.floor(this.options['transition'](i,begin,(end - begin),speed))+"px") //TODO unit
		}
		return transitionArray;
	},

	start: function(styles)
	{
		if(this.el.ready)
		{
			this.step = 0;
			if(this.options['wait'] == true) { this.el.ready = false }
			clearInterval(this.timer);this.timer = undefined;
			this.speed = this.options['speed']
			this.transition = []
			this.el.styles = [];

			for(prop in styles)
			{
				this.el.styles.push(prop)
				if(prop.indexOf("color") == -1) 
				{
					begin =  parseInt(this.el.getCss(prop));
					end = parseInt(styles[prop])
					if(prop.indexOf("opacity") != -1)
					{
					begin = this.el.getCss(prop)
					end = styles[prop];
					this.transition[prop] = this.getTransition(begin*100, end*100, this.speed);
					}else {
					this.transition[prop] = this.getTransition(begin, end, this.speed);
					}
				}
				else {
					begin = this.el.getCss(prop)
					end = styles[prop]
					this.transition[prop] = this.colorTransition(begin, end, this.speed);
				}
			}

			if(!this.timer) 
				this.timer = setInterval(this.morpher.bind(this), 13);
			
		} else {
				;
		}
	}

};

/*
  Easing Equations v1.5
  May 1, 2003
  (c) 2003 Robert Penner, all rights reserved. 
  This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html.  
  
  These tweening functions provide different flavors of 
  math-based motion under a consistent API. 
  
  Types of easing:
  
	  Linear
	  Quadratic
	  Cubic
	  Quartic
	  Quintic
	  Sinusoidal
	  Exponential
	  Circular
	  Elastic
	  Back
	  Bounce

  Changes:
  1.5 - added bounce easing
  1.4 - added elastic and back easing
  1.3 - tweaked the exponential easing functions to make endpoints exact
  1.2 - inline optimizations (changing t and multiplying in one step)--thanks to Tatsuo Kato for the idea
  
  Discussed in Chapter 7 of 
  Robert Penner's Programming Macromedia Flash MX
  (including graphs of the easing equations)
  
  http://www.robertpenner.com/profmx
  http://www.amazon.com/exec/obidos/ASIN/0072223561/robertpennerc-20
*/


// simple linear tweening - no easing
// t: current time, b: beginning value, c: change in value, d: duration
Math.linearTween = function (t, b, c, d) {
	return c*t/d + b;
};


 ///////////// QUADRATIC EASING: t^2 ///////////////////

// quadratic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be in frames or seconds/milliseconds
Math.easeInQuad = function (t, b, c, d) {
	return c*(t/=d)*t + b;
};

// quadratic easing out - decelerating to zero velocity
Math.easeOutQuad = function (t, b, c, d) {
	return -c *(t/=d)*(t-2) + b;
};

// quadratic easing in/out - acceleration until halfway, then deceleration
Math.easeInOutQuad = function (t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t + b;
	return -c/2 * ((--t)*(t-2) - 1) + b;
};


 ///////////// CUBIC EASING: t^3 ///////////////////////

// cubic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
Math.easeInCubic = function (t, b, c, d) {
	return c*(t/=d)*t*t + b;
};

// cubic easing out - decelerating to zero velocity
Math.easeOutCubic = function (t, b, c, d) {
	return c*((t=t/d-1)*t*t + 1) + b;
};

// cubic easing in/out - acceleration until halfway, then deceleration
Math.easeInOutCubic = function (t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
};


 ///////////// QUARTIC EASING: t^4 /////////////////////

// quartic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
Math.easeInQuart = function (t, b, c, d) {
	return c*(t/=d)*t*t*t + b;
};

// quartic easing out - decelerating to zero velocity
Math.easeOutQuart = function (t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

// quartic easing in/out - acceleration until halfway, then deceleration
Math.easeInOutQuart = function (t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
	return -c/2 * ((t-=2)*t*t*t - 2) + b;
};


 ///////////// QUINTIC EASING: t^5  ////////////////////

// quintic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
Math.easeInQuint = function (t, b, c, d) {
	return c*(t/=d)*t*t*t*t + b;
};

// quintic easing out - decelerating to zero velocity
Math.easeOutQuint = function (t, b, c, d) {
	return c*((t=t/d-1)*t*t*t*t + 1) + b;
};

// quintic easing in/out - acceleration until halfway, then deceleration
Math.easeInOutQuint = function (t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
	return c/2*((t-=2)*t*t*t*t + 2) + b;
};



 ///////////// SINUSOIDAL EASING: sin(t) ///////////////

// sinusoidal easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in position, d: duration
Math.easeInSine = function (t, b, c, d) {
	return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
};

// sinusoidal easing out - decelerating to zero velocity
Math.easeOutSine = function (t, b, c, d) {
	return c * Math.sin(t/d * (Math.PI/2)) + b;
};

// sinusoidal easing in/out - accelerating until halfway, then decelerating
Math.easeInOutSine = function (t, b, c, d) {
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
};


 ///////////// EXPONENTIAL EASING: 2^t /////////////////

// exponential easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in position, d: duration
Math.easeInExpo = function (t, b, c, d) {
	return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
};

// exponential easing out - decelerating to zero velocity
Math.easeOutExpo = function (t, b, c, d) {
	return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
};

// exponential easing in/out - accelerating until halfway, then decelerating
Math.easeInOutExpo = function (t, b, c, d) {
	if (t==0) return b;
	if (t==d) return b+c;
	if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
	return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
};


 /////////// CIRCULAR EASING: sqrt(1-t^2) //////////////

// circular easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in position, d: duration
Math.easeInCirc = function (t, b, c, d) {
	return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
};

// circular easing out - decelerating to zero velocity
Math.easeOutCirc = function (t, b, c, d) {
	return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
};

// circular easing in/out - acceleration until halfway, then deceleration
Math.easeInOutCirc = function (t, b, c, d) {
	if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
	return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
};


 /////////// ELASTIC EASING: exponentially decaying sine wave  //////////////

// t: current time, b: beginning value, c: change in value, d: duration, a: amplitude (optional), p: period (optional)
// t and d can be in frames or seconds/milliseconds

Math.easeInElastic = function (t, b, c, d, a, p) {
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	if (a < Math.abs(c) || !a) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
};

Math.easeOutElastic = function (t, b, c, d, a, p) {
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	if (a < Math.abs(c) || !a) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};

Math.easeInOutElastic = function (t, b, c, d, a, p) {
	if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
	if (a < Math.abs(c) || !a) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
};


 /////////// BACK EASING: overshooting cubic easing: (s+1)*t^3 - s*t^2  //////////////

// back easing in - backtracking slightly, then reversing direction and moving to target
// t: current time, b: beginning value, c: change in value, d: duration, s: overshoot amount (optional)
// t and d can be in frames or seconds/milliseconds
// s controls the amount of overshoot: higher s means greater overshoot
// s has a default value of 1.70158, which produces an overshoot of 10 percent
// s==0 produces cubic easing with no overshoot
Math.easeInBack = function (t, b, c, d, s) {
	if (s == undefined) s = 1.70158;
	return c*(t/=d)*t*((s+1)*t - s) + b;
};

// back easing out - moving towards target, overshooting it slightly, then reversing and coming back to target
Math.easeOutBack = function (t, b, c, d, s) {
	if (s == undefined) s = 1.70158;
	return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
};

// back easing in/out - backtracking slightly, then reversing direction and moving to target,
// then overshooting target, reversing, and finally coming back to target
Math.easeInOutBack = function (t, b, c, d, s) {
	if (s == undefined) s = 1.70158; 
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
};


 /////////// BOUNCE EASING: exponentially decaying parabolic bounce  //////////////

// bounce easing in
// t: current time, b: beginning value, c: change in position, d: duration
Math.easeInBounce = function (t, b, c, d) {
	return c - Math.easeOutBounce (d-t, 0, c, d) + b;
};

// bounce easing out
Math.easeOutBounce = function (t, b, c, d) {
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
};


// bounce easing in/out
Math.easeInOutBounce = function (t, b, c, d) {
	if (t < d/2) return Math.easeInBounce (t*2, 0, c, d) * .5 + b;
	return Math.easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b;
};





function colorToRGB(color)
{
	if(color.indexOf("#") > -1) 
		return hexToRGB(color)
	else 		
		return hexToRGB(toRGBHex(color));
}

function toRGBHex(num)
{
	num = num.replace(/rgb\(/i, "").replace(/\)/, "");
	var decToHex="#";
	var arr = new Array();
	var numStr = new String();
	numStr = num;
	arr = numStr.split(",");
	for(var i=0;i<3;i++)
	{
		var hexArray = new Array( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" );
		var code1 = Math.floor(arr[i] / 16);var code2 = arr[i] - code1 * 16;
		decToHex += hexArray[code1];
		decToHex += hexArray[code2];
	}

return (decToHex);
}





function hexToRGB(hexv)
{
	var hex = hexv.match(new RegExp('^[#]{0,1}([\\w]{1,2})([\\w]{1,2})([\\w]{1,2})$'));
	var rgb = [];
	for (var i = 1; i < hex.length; i++)
	{
		if (hex[i].length == 1) hex[i] += hex[i];
		rgb.push(parseInt(hex[i], 16));
	}
	var out = []; 
	out['r'] = parseInt(rgb[0]);
	out['g'] = parseInt(rgb[1]);
	out['b'] = parseInt(rgb[2]);

return out;
}









//trace (">> Penner easing equations loaded");


/*
	damnJS, 0.8-theta (02072009131042)
	@package: Eff.More library

	@author: Jakub Ziółkowski (jakub.ziolkowski@dlk24.pl)
	@www: www.creativeboy.pl/code/damnJS
	@license: MIT
*/

//var Eff = {} || Eff;

Eff.Scroll = function(el, item, options)
{
	items=0
	item.each(function(){items++})
	//alert(items)
	viewSize = parseInt(item.getCss('width')),
//	viewSize = viewSize
	//var viewSize = item.getCss('width');
	//var inta = 0;
//	dbg(item)
//el.setCss('width', ''800')
//alert()
//	el.setCss('width', parseInt(item.getCss('width'))*2 + 'px');
	el.elements[0].innerHTML = '<div class="content-holder">' + el.elements[0].innerHTML + '</div>'
	
	$('.content-holder').setCss('width',parseInt(viewSize*items)+'px')

	this.options = options
	this.items = items
	this.el = el;
	this.item = item;
	this.el.ready = true;
};

Eff.Scroll.prototype = 
{
	
	cur: 0,

	show: function(count){
		this.cur = count
		this.start({'scrollLeft': parseInt(viewSize)*this.cur});
		
	},
	next: function() {

		this.cur++;
		this.cur = (this.cur>=this.items)?0:this.cur;
		this.start({'scrollLeft': parseInt(viewSize)*this.cur}); //FIXME
		},
	prev: function() {

		this.cur--;
		this.cur = (this.cur< 0)?this.items-1:this.cur;
		this.start({'scrollLeft': parseInt(viewSize)*this.cur});

	},
	morpher: function()
	{
		if(this.step < this.speed)
		{
			this.step++
			for(prop in this.transition)
			{	
				//if(prop = "opacity") {this.transition[prop][this.step].replace(/px/,'');}
//alert( this.transition[prop][this.step])
			this.el.elements[0].scrollLeft = this.transition[prop][this.step]
//dbg(this.el.elem))
				
				//this.el.innerHTML = this.transition[prop][this.step]
			}
		} else 
			{
				
				this.step = 0;
				clearInterval(this.timer);this.timer = undefined;
				this.transition[prop] = [];
				this.el.ready = true;
			}
	},


	getTransition: function(begin, end, speed)
	{
		transitionArray = []

		for(var i=0;i<=speed;i++) 
		{
			transitionArray.push(Math.floor(this.options['transition'](i,begin,(end - begin),speed))) //TODO unit
		}
		return transitionArray;
	},

	start: function(styles)
	{
		if(this.el.ready)
		{
			this.step = 0;
			if(this.options['wait'] == true) { this.el.ready = false }
			clearInterval(this.timer);this.timer = undefined;
			this.speed = this.options['speed']
			this.transition = []
			this.el.styles = [];

			for(prop in styles)
			{
				this.el.styles.push(prop)
				//	this.el.scrollLeft = 50
					begin =  parseInt(this.el.elements[0].scrollLeft) || 0;
//alert(begin)
					end = parseInt(styles[prop])
//alert(end)

					this.transition[prop] = this.getTransition(begin, end, this.speed);
				
			}

			if(!this.timer) 
				this.timer = setInterval(this.morpher.bind(this), 13);
			
		} else {
				;
		}
	}

};



function fireEvent(el, event){

			if (document.createEventObject){
				// dispatch for IE
				var evt = document.createEventObject();
				return el.fireEvent('on'+event,evt)
			}
			else{
				// dispatch for firefox + others
				var evt = document.createEvent("HTMLEvents");
				evt.initEvent(event, true, true ); // event type,bubbling,cancelable
				return !el.dispatchEvent(evt);
			}
			};








Eff.Accordion = function(tog,els, options)
{
//dbg(options)
	this.options = options
	//this.transition = options['transition']
	this.init(tog,els);
	fireEvent(tog.elements[0], 'click')
//	alert('a')
};

Eff.Accordion.prototype = 
{
	init: function(tog, els){
		var t = this.options['transition'];
		var heights = Array();
		els.each(function(el){
			$(el).css({'overflow':'hidden'});
			heights.push($(el).getCss('height'));
		});
		var n = 0;
		tog.each(function(el){
			el.id = n++;
			$(el).addEvent('click', function(){
		//dbg(that.options)
					var a = new Eff.Css($(els.elements[el.id]), {speed: 250, transition: Math.easeInOutExpo, wait: false}).start({'height':heights[el.id],'opacity':1});
tog.elements[el.id].style. backgroundImage = "url(../css/img/menu0_dta.png)"
					var b = new Eff.Css($(tog.elements[el.id]), {speed: 250, transition: Math.easeInOutExpo, wait: false}).start({'color':'#ffffff'});
					var t = 0;
					els.each(function(els){
						if(t != el.id )
							{
tog.elements[t].style. backgroundImage = "url(templates/csFinal/css/img/menu0_dt.png)"
var a = new Eff.Css($(els), {speed: 210, transition: Math.easeInOutExpo, wait: false}).start({'height':'0px','opacity':0});
							var b = new Eff.Css($(tog.elements[t]), {speed: 210, transition: Math.easeInOutExpo, wait: false}).start({'color':'#666666','background-color':'#6AB5DB'});
							}
						t++;
					});
			});
		});

	}
}


ajax = function(url, options)
{
		this.transport = this.getTransport();
		this.postBody = options.postBody || '';
		this.method = options.method || 'post';
		this.onComplete = options.onComplete || null;
		this.update = $(options.update) || null;
		this.request(url);
};

ajax.prototype = {
	request: function(url){
		this.transport.open(this.method, url, true);
		this.transport.onreadystatechange = this.onStateChange.bind(this);
		if (this.method == 'post') {
			this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
		}
		this.transport.send(this.postBody);
	},

	onStateChange: function(){
		if (this.transport.readyState == 4 && this.transport.status == 200) {
			if (this.onComplete) 
				setTimeout(function(){this.onComplete(this.transport);}.bind(this), 10);
			if (this.update)
				setTimeout(function(){this.update.innerHTML = this.transport.responseText;}.bind(this), 10);
			this.transport.onreadystatechange = function(){};
		}
	},

	getTransport: function() {
		if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
		else if (window.XMLHttpRequest) return new XMLHttpRequest();
		else return false;
	}
};




