
var promotionBox =
{
	currentAnimation: null,
	timer: null,
	currentIndex: 0,
	itemsArray: null,
	dojoObject: null,
	baseURL: '',
	pathToImg: '',
	nl : { 'prd_img':'promocja_zdjecie', 'lnk_name':'promocja_link_nazwa', 
		   'cena':'promocja_cena', 'info_box':'promocja_info', 'prd_desc' : 'promocja_opis' ,
		   'img_lnk' : 'promocja_link_zdjecie'
	     },
	setUpPromotionBox: function( dojo, items, baseUrl, imgPath)
	{
		this.dojoObject = dojo;
		this.baseURL = baseUrl;
		this.itemsArray = items;
		this.pathToImg = imgPath;
	},
	ustawDane: function  (  )
	{
		this.dojoObject.byId( this.nl['prd_img'] ).src = this.baseURL + this.pathToImg + this.itemsArray[ this.currentIndex ]['PRD_Photo'];
	    this.dojoObject.byId( this.nl['lnk_name']).innerHTML = this.itemsArray[ this.currentIndex ]['PRD_Name'];
	    this.dojoObject.byId( this.nl['prd_desc'] ).innerHTML = this.itemsArray[ this.currentIndex ]['PRD_Desc'];
	    var cena = this.itemsArray[ this.currentIndex ]['PRD_PricePromotion']+' zł/ '+ this.itemsArray[ this.currentIndex ]['PRD_Units'];
	    this.dojoObject.byId( this.nl['cena'] ).innerHTML = cena;
	    this.dojoObject.byId( this.nl['lnk_name'] ).href = this.itemsArray[ this.currentIndex ]['PRD_Url'];
	    this.dojoObject.byId( this.nl['img_lnk'] ).href = this.itemsArray[ this.currentIndex ]['PRD_Url'];
	},
	
	next:function ( )
	{
		this.fOut();
		this.timerF();
	},

	prev:function (  )
	{
		this.fOut();
		this.timerB();
	},

	fIn: function (  )
	{
		currentAnimation = this.dojoObject.fadeIn( {node: this.nl['prd_img'] , duration: 1000} );
		currentAnimation.play();
		currentAnimation = this.dojoObject.fadeIn( {node: this.nl['info_box'] , duration: 1000} );
		currentAnimation.play();		
	},

	fOut: function(  )
	{
		currentAnimation = this.dojoObject.fadeOut( {node: this.nl['prd_img'] , duration: 1000} );
		currentAnimation.play();
		currentAnimation = this.dojoObject.fadeOut( {node: this.nl['info_box'] , duration: 1000} );
		currentAnimation.play();
	},

	nastepne: function( )
	{
		this.incIndex();
	    this.ustawDane();
	    this.fIn();
	    clearTimeout( this.timer );
	},

	poprzednie: function ()
	{
		this.decIndex();
		this.ustawDane();
	    this.fIn();
	    clearTimeout( this.timer );
	},

	incIndex: function()
	{
		( this.currentIndex  == this.itemsArray.length-1 ) ? this.currentIndex : this.currentIndex++;
	},

	decIndex: function()
	{
		( this.currentIndex  == 0 ) ? this.currentIndex : this.currentIndex--;
	},
	
	timerF: function ( )
	{
		t = setTimeout("promotionBox.nastepne()", 950);
	},

	timerB: function ()
	{
		t = setTimeout("promotionBox.poprzednie()", 950);
	},
	rand: function  ( n )
	{
	  return ( Math.floor ( Math.random ( ) * n + 1 ) );
	}	
}
