// JavaScript Document

function ManageMainBanner( args ) {
	this.num = args.total_banners;
	this.picturepath = (args.picturepath ? args.picturepath : 'images/');
	this.pic = args.image_container;
	this.btitle = (args.title_container ? args.title_container : '');
	this.bdesc = (args.desc_container ? args.desc_container : '');
	this.delay = args.delay;
	this.strobj = args.string_name_obj;
	this.first = 0;
	this.numop = 0;
	this.npic = 0;
	this.oldpic = 0;
	this.num_banner = 0;
	this.banner = new Array();
	this.idInterval = null;
}

ManageMainBanner.prototype.changePic = function( current ) {
	this.setCurrentPicture( current );
	this.changePicture( current, true );
}

ManageMainBanner.prototype.changePicture = function( current, clicked ) {
	var currImage = document.getElementById( this.pic );
/*	var currTitle = document.getElementById( this.btitle );
	var currContent = document.getElementById( this.bdesc );*/

	var oldBanner = this.getOldBanner();
	var currBanner = this.getCurrentBanner(current);
/*	currTitle.innerHTML = currBanner.title;
	currContent.innerHTML = currBanner.desc;*/
	currImage.src = this.picturepath + currBanner.image;
	
	if(!clicked) {
		currImage.style.opacity  =  0;
		currImage.style.filter  =  'alpha(opacity = 0)';
	}

	this.changeCurrentBannerNumber(currBanner.id);
	this.changeOldBannerNumber(oldBanner.id);
}

ManageMainBanner.prototype.changeCurrentBannerNumber = function( id ) {
	var curr_num_banner = document.getElementById(id).src;
	document.getElementById(id).src = curr_num_banner.replace(/_over/,'');
}

ManageMainBanner.prototype.changeOldBannerNumber = function( id ) {
	var old_num_banner = document.getElementById(id).src;
	document.getElementById(id).src = old_num_banner.replace(/.png/,'_over.png');
}

ManageMainBanner.prototype.getOldBanner = function() {
	return this.banner[this.oldpic];
}

ManageMainBanner.prototype.getCurrentBanner = function( current ) {
	return this.banner[current];
}

ManageMainBanner.prototype.setCurrentPicture = function( current ) {
	this.oldpic = this.npic;
	this.npic = current;
}

ManageMainBanner.prototype.changeOpacity = function( current ) {
	if( this.numop == 1 )
		this.numop = 0;
	
	this.numop += 0.1;

	this.setOpacity(this.pic);
/*	this.setOpacity(this.btitle);
	this.setOpacity(this.bdesc);*/
}

ManageMainBanner.prototype.setOpacity = function(id) {
	var obj = document.getElementById( id )
	obj.style.opacity  =  this.numop;
	obj.style.filter  =  'alpha(opacity = ' + this.numop * 100 + ')';
}

ManageMainBanner.prototype.addBanner = function(newbanner) {
	this.banner.push(newbanner);
	document.getElementById(newbanner.id).onclick = function() {
		newbanner.object.changePic( newbanner.ord );
	};
	this.num_banner++;
}

ManageMainBanner.prototype.play = function() {
	setInterval( this.strobj + ".slideOn()", this.delay );
}

ManageMainBanner.prototype.slideOn = function() {
	var picturename = '';
	var localnpic = this.npic;
	this.oldpic = this.npic;
	
	try {
		clearInterval( this.idInterval );
//		clearInterval( manageMainBannerObject.idInterval );
	}
	catch(err) {
	// nothing to do
	}

	if( localnpic >= (this.num - 1) )
		this.npic = this.first;
	else
		this.npic = ++localnpic;
	
	this.numop = 0;
	this.idInterval = setInterval( this.strobj + '.changeOpacity()', 100 );
	this.changePicture( this.npic, false );
}

app.ManageMainBanner = ManageMainBanner;
