$(function(){

    function isLocalHost() {
        var exp = new RegExp('^(192.|local|127.)');
        return exp.test(location.host)?true:false;
    }
    
    function locationUrl(i,conc) {
        return location.href.split('/')[i]+conc;
    }
    
    function baseUrl() {
        return isLocalHost()?'http://'+locationUrl(2,'/')+locationUrl(3,'/'):'http://'+location.hostname+'/';
    }
    
    var BASE_URL = baseUrl();
   
    $('input[type=text],textarea').focus(function(){
        if (this.value==$(this).attr('title'))
        $(this).val('');
        $(this).addClass('selecionado');
    }).blur(function(){
        if ($(this).attr('title')==this.value || this.value=='')
        $(this).val($(this).attr('title'));
        $(this).removeClass('selecionado');
    }).each(function(){
        $(this).val($(this).attr('title'));
    });
    
    Cufon.replace('h2');
    
    $('.video_grande iframe').attr('width', 874);
    $('.video_grande iframe').attr('height', 420);
    
    $('a[rel="colorbox"], a.ver_detalhes').colorbox(
    	{ 
    		current:  'imagem {current} de {total}',
    		previous: 'anterior',
    		next:	  'proximo',
    		close:    'fechar'
    	}
    );
    
    $('#ver_mais_agenda').click(function() {
    	$.ajax({
			url 		: BASE_URL+'agendas/get_mais_agendas',
			data		: {scape_from_start : $('#agenda dl').length},
			success 	: function(response) {
				$('#agenda_separator').before(response);
				$('#agenda dl').fadeIn(800);
				$('a.ver_detalhes').colorbox();
			}
		});
    	return false;
    });
    
    $('#ver_mais_noticia').click(function() {
    	$.ajax({
			url 		: BASE_URL+'noticias/get_mais_noticias',
			data		: {scape_from_start : $('#conteudo_chamada_noticia dl').length},
			success 	: function(response) {
				$('#conteudo_chamada_noticia').append(response);
				$('#conteudo_chamada_noticia dl').fadeIn(800);
				$('a.ver_detalhes').colorbox();
			}
		});
    	return false;
    });
    

});
