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

var iFade2 = {
	fadingDuration : 400,
	showTime : 4000,
	fadingDiv : 'iFader2',
	iFade2Height : '0px;',
	iFade2Width : '0px;',
	fadeIn : true,
	iFade2Source : [],
	sourceCnt : 0,
	position : 0,
	iFade2Zindex : 100,

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

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


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

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

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

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