var banner = {
	
	offset: 0,
	size: null,
	ant: 0,
	i: 0,
	interval: null,
	tipos: new Array(),
	timeout: null,
	flashs: new Array(),
	
	start: function(){
		
		if ($('.ban').length < 1) return false;
		
		$($('#buttons a')[0]).css('background-position','center 0px');
		
		/*
		$('#banner a.left').bind('click',this.move_right);
		$('#banner a.right').bind('click',this.move_left);
		*/
		$('#buttons a').bind('click',function(e){
			return banner.move_to($(this).attr('name'));
		});
		this.size = $('#mascara .ban').length;

		var x = 0;
		$('#mascara .ban').each(function(){
			if ($(this).hasClass('flash')) banner.tipos[x] = 'flash'; else banner.tipos[x] = 'image';
			banner.flashs[x] = $(this).find('object').attr('id') ? $(this).find('object').attr('id') : 0;
			x++;
		});
		setTimeout(function(){
			if (banner.tipos[banner.i] != 'flash') {
				banner.timer();
			} else {
				banner.playmovie(banner.flashs[banner.i]);
			}
		},2000);
	},
	
	thisMovie: function(movieName){
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window.document[movieName];
		} else {
			return document[movieName];
		}
	},
	
	playmovie: function(obj){
		if (obj != '' && obj != null) {
			if (document.getElementById(obj).tagName == 'OBJECT') {
				try {
					this.thisMovie(obj).start_animation();
				} catch(e) {
					setTimeout(function(){
						banner.playmovie(obj);
					},1000);
				}
			}
		}
	},
	
	stopmovie: function(obj){
		if (obj != '' && obj != null) {
			if (document.getElementById(obj).tagName == 'OBJECT') {
				try {
					this.thisMovie(obj).stop_animation();
				} catch(e) {
					setTimeout(function(){
						banner.stopmovie(obj);
					},1000);
				}
			}
		}
	},
	
	timer: function(){
		this.interval = setInterval(this.move_left, 10000);
	},
	
	move_banner: function(){
		clearInterval(banner.interval);
		$('#buttons a').removeClass('selected');
		$($('#buttons a')[banner.i]).addClass('selected');
		
		var cor = $('.ban_'+banner.i).attr('name');


		//console.log(banner.ant+"-"+banner.i);
		$('.ban_'+banner.ant).hide();
		$('.ban_'+banner.i).show();
		
		$($('#buttons a')[banner.ant]).css('background-position','center -50px');
		$($('#buttons a')[banner.i]).css('background-position','center 0px');
		
		/*
		$($('#buttons a')[banner.ant]).animate({ backgroundPosition: "(0 0px)" });
		$($('#buttons a')[banner.i]).animate({ backgroundPosition: "(0 -72px)" });
		*/ 
		
		$('body').animate({ backgroundColor: '#'+cor },400);
		
		if (banner.tipos[banner.i] != 'flash') {
			banner.timer();
		} else {
			banner.playmovie(banner.flashs[banner.i]);
		}

		//alert(banner.i);
		/*
		$('#scroller .slice').animate({ 'left': banner.offset + 'px' }, 400, function(){
			clearInterval(banner.interval);
			
		});
		*/
	},
	
	move_left: function(){
		clearInterval(this.timeout);
		banner.stopmovie(banner.flashs[banner.i]);
		if (banner.i < banner.size - 1) {
			banner.ant = banner.i;
			banner.i++;
		} else {
			banner.ant = 3;
			banner.i = 0;
		}
		banner.move_banner();
		return false;
	},
	
	move_right: function(){
		clearInterval(this.timeout);
		if (banner.i > 0) {
			banner.stopmovie(banner.flashs[banner.i]);
			banner.offset += 960;
			banner.i--;
			banner.move_banner();
		}
		return false;
	},
	
	move_to: function(i){
		clearInterval(this.timeout);
		banner.stopmovie(banner.flashs[banner.i]);
		
		banner.ant = banner.i;
		banner.i = i;
		banner.move_banner();
		return false;
		

		banner.i = i - 1;
		banner.offset = banner.i * 960 * (-1);
		banner.move_banner();

	},
	
	finish: function(){
		this.timeout = setTimeout(function(){
			banner.move_left();
		},2000);
	}

};
