/*!
 * iFade V1.1
 * http://www.ourconsultancy.net
 *
 * Copyright 2011, Karl Kern
 *
 * Date: 11/05/2011
 */

var iFade = {
	fadingDuration : 400,
	showTime : 4000,
	fadingDiv : 'iFader',
	iFadeHeight : '0px;',
	iFadeWidth : '0px;',
	fadeIn : true,
	iFadeSource : [],
	sourceCnt : 0,
	position : 0,
	iFadeZindex : 100,

	init : function(data){
		var tmppic = new Image();
		for(var propertyName in data){
			this[propertyName] = data[propertyName];
		}
		this.sourceCnt = this.iFadeSource.length;

		if(this.iFadeHeight != '0px'){
			$('#' + this.fadingDiv).css('height', this.iFadeHeight);
		}
		if(this.iFadeWidth != '0px'){
			$('#' + this.fadingDiv).css('width', this.iFadeWidth);
		}
		$('#' + this.fadingDiv).children('img').attr('z-index', this.iFadeZindex);
		$('#' + this.fadingDiv).children('img').css('opacity', 0);


		if(this.fadeIn){
			$('#' + this.fadingDiv).children('img').attr('src', this.iFadeSource[this.position][0]);
			$('#' + this.fadingDiv).children('img').fadeTo(this.fadingDuration, 1);
			$('#' + this.fadingDiv).children('#slider').children('#textContainer').html(this.iFadeSource[this.position][1]);
		}

		setTimeout('iFade.moveDiv()', this.showTime);
	},

	animate : function(){
		if(iFade.sourceCnt > 0){
			if(iFade.position >= iFade.sourceCnt - 1){
				iFade.position = 0;
			} else {
				iFade.position++;
			}
		}
		$('#' + iFade.fadingDiv).children('img').css('opacity', 0);
		$('#' + iFade.fadingDiv).children('img').attr('src', iFade.iFadeSource[iFade.position][0]);
		$('#' + iFade.fadingDiv).children('img').fadeTo(iFade.fadingDuration, 1);
		$('#' + iFade.fadingDiv).children('#slider').children('#textContainer').html(iFade.iFadeSource[iFade.position][1]);
		setTimeout('iFade.moveDiv()', iFade.showTime);
	},

	moveDiv : function(){
	  $('#slider').animate({
  		left: 0
	  });
	  setTimeout('iFade.rmovDiv()', iFade.slideTime);
	},
	rmovDiv : function(){
		$('#' + iFade.fadingDiv).children('#slider').css('left', '-380px');
		iFade.animate();
	}
}