var resource = {
    searchFocus: function() {
        var el = document.getElementById('search');
        var old = el.value;
        el.onfocus = function() {
            old = this.value;
            this.value = '';
        }
        el.onblur = function() {
            if (this.value === "" || this.value === " ") {
                this.value = old;
            }
        }
    },
    labeler: function() {
        $('.search .option label').click(function() {
            $('.search .option label').removeClass('active');
            $(this).addClass('active');
        });
    },
    activeLinks: function() {
        ////ja esta sendo feito no servidor;
        var loc = window.location.href.replace($('base').attr('href'), '');
        $('a[href=' + loc + ']').each(function(e) {
            $(this).addClass('active');
            $(this).parents('ul:first').prev().addClass('active');
        });
    },
    sideMenu: function() {
        $('.side-menu > li a').click(function() {
            if ($(this).next().css('display') === 'block') {
                $(this).next().hide();
                $(this).removeClass('active')
            } else {
                $('.side-menu > li a').removeClass('active');
                $('.side-menu ul').hide();
                $(this).next().show();
                $(this).addClass('active')
            }
        });
    },
    start: function() {
        //this.searchFocus();
        //this.labeler();
        //this.activeLinks();
        //this.sideMenu();
    }
};

$(document).ready(function() {
    resource.start();
});

function galeria(){
	$('.gallery > ul li:first-child').addClass('active');
	$('.gallery > ul li').click(function(){
		$(this).parent().children('li').removeClass('active');
		$(this).addClass('active');
		var novaImagem = 'milenium/imagens/espacos/' + $(this).children('img').attr('alt') + '_' + $(this).prevAll().size() + '.jpg';
		var novoLink = 'milenium/imagens/espacos/zoom/' + $(this).children('img').attr('alt') + '_' + $(this).prevAll().size() + '.jpg';
		$(this).parent().prev('div').children('img').attr('src', novaImagem);
		$(this).parent().prev('div').children('img').attr('alt', $(this).children('img').attr('alt'));
		$(this).parent().prev('div').children('a').attr('href', novoLink);
		$('.gallery > div a').removeClass('cboxElement');
		ampliar();
	});
}

function zoom(){
	$('a[rel="galeria"]').colorbox({title: function(){return "";}})
}
function ampliar(){
	$('.gallery > div > a.over').colorbox({title: function(){return $(this).prev('img').attr('alt');}})
}

(function()
{
	$.accordion = function(quem, velocidade){
		$(quem).children('dt').click(function(){
			if($(this).next('dd').css('display') == 'none'){
				$(quem).children('dt').removeClass('active');
				$(this).addClass('active');
				$(quem).children('dd').slideUp(velocidade);
				$(this).next('dd').stop();
				$(this).next('dd').slideDown(velocidade);
			}else{
				$(quem).children('dt').removeClass('active');
				$(quem).children('dd').slideUp(velocidade);
			}
		});
	}
})(jQuery)

function bannerMilenium(){
	$('.banner').cycle({
		timeout: 10000,
		speed: 2000,
		activePagerClass: 'active',
		pause: true,
		before: fechaBanner,
		after: abreBanner,
		delay: -1000
	});
}
function fechaBanner(){
	$('.banner .desc').animate({
		right: -452 + 'px',
		opacity: 0
	}, 1200);
}
function abreBanner(){
	$('.banner .desc').animate({
		right: 0 + 'px',
		opacity: 1
	}, 1200);
}
