(function($){
	$.Galeria = {

		__constructor : function(){
			var me = this;
			me.initConfig();

			// targets (bind em elementos)
			$('#arrowtop').click(me.moveTop);
			$('#arrowbot').click(me.moveBottom);
			$('#arrowleft').click(me.moveLeft);
			$('#arrowright').click(me.moveRight);
			$('#fotodestaque .fotos li a').click(function(e){
				e.preventDefault();
				me.trocarImagem(e);
			});
			$('.foto img').load(function(){
				$(this).loadHide();
			});
		},

		atualBastidores: 2,
		totalBastidores:null,
		alturaFoto:108,

		moveTop: function() {
			me = $.Galeria;
			atual = me.atualBastidores;
			total = me.totalBastidores.length;
			//$("#debug").html('<div style="color: #900">atual: '+atual+" - total: "+total+"</div>");

			if (atual > 2) {
				//$("#debug").html($("#debug").html()+'<div style="color: #009">caiu no if</div>');
				me.atualBastidores--;
				$('#fotodestaque div.box').scrollTo({top:'-='+me.alturaFoto, left:0}, 600);
			} else {
				//$("#debug").html($("#debug").html()+'<div style="color: #009">caiu no else</div>');
				$('#fotodestaque div.box').scrollTo(me.alturaFoto*(total-3), 1000);
				me.atualBastidores = total-1;
			}
			//$("#debug").html($("#debug").html()+'<div style="color: #090"> atual: '+me.atualBastidores+" - total: "+me.totalBastidores.length+"</div>");
		},

		moveBottom: function() {
			me = $.Galeria;
			atual = me.atualBastidores;
			total = me.totalBastidores.length;
			//$("#debug").html('<div style="color: #900">atual: '+atual+" - total: "+total+"</div>");

			if ((total > 2) && (atual != total-1)) {
				//$("#debug").html($("#debug").html()+'<div style="color: #009">caiu no if</div>');
				me.atualBastidores++;
				if (atual == 2) alturaFoto = 90;
				$('#fotodestaque div.box').scrollTo({top:'+='+me.alturaFoto, left:0}, 600);
			} else {
				//$("#debug").html($("#debug").html()+'<div style="color: #009">caiu no else</div>');
				me.atualBastidores = 2;
				$('#fotodestaque div.box').scrollTo({top:0, left:0}, 1000);
			}
			//$("#debug").html($("#debug").html()+'<div style="color: #090"> atual: '+me.atualBastidores+" - total: "+me.totalBastidores.length+"</div>");
		},

		atualBlog: 3,
		totalBlogs:null,
		larguraFoto:208,

		moveLeft: function() {
			me = $.Galeria;
			atual = me.atualBlog;
			total = me.totalBlogs.length;

			if (atual > 3) {
				me.atualBlog--;
				$('#galeriascrollH div.box').scrollTo({left:'-='+me.larguraFoto, top:0}, 600);
			} else {
				me.atualBlog = total;
				$('#galeriascrollH div.box').scrollTo(me.larguraFoto*(total-3), 1000);
			}
		},

		moveRight: function() {
			me = $.Galeria;
			atual = me.atualBlog;
			total = me.totalBlogs.length;

			if ((total > 3) && (atual < total)) {
				me.atualBlog++;
				$('#galeriascrollH div.box').scrollTo({left:'+='+me.larguraFoto, top:0}, 600);
			} else {
				me.atualBlog = 3;
				$('#galeriascrollH div.box').scrollTo(0, 1000);
			}
		},

		trocarImagem : function (e){
			var me = this;
			if(e.target.tagName == "IMG"){
				var $o = $(e.target);
			} else {
				var $o = $(e.target).find('img');
			}
			$('.foto img').loadShow();
			$('.foto img').attr('src',$o.attr('src').replace("_2","_3").toString());
		},

		initConfig: function() {
			var me = this;

			$.scrollTo.defaults.axis = 'xy';
			$('#fotodestaque div.box').scrollTo(0);
			me.totalBastidores = $("#fotodestaque ul li");
			me.totalBlogs = $("#galeriascrollH ul li");
		}

	}
})(jQuery);