$(document).ready(function() {
setTimeout(function(){
	jQuery('img[hspace]').each(function(){
		var margen = jQuery(this).attr('hspace') + 'px'; 
		jQuery(this).css('margin-left',margen);
		jQuery(this).css('margin-right',margen);
	});
	jQuery('img[vspace]').each(function(){
		var margen = jQuery(this).attr('vspace') + 'px';
		jQuery(this).css('margin-top',margen);
		jQuery(this).css('margin-bottom',margen);
	});
}, 1000);
    redondearImagenes();

	jQuery('.menu a[href=#2]').click(function(){return false;});
});

function redondearImagenes()
{

    $("img.rounded").load( function () {
            var img = $(this);

            // build wrapper
            var wrapper = $('<div class="rounded_wrapper"></div>');
            wrapper.width(img.width());
            wrapper.height(img.height());

            // move CSS properties from img to wrapper
            wrapper.css('float', 'left');
            img.css('float', 'left');

            wrapper.css('margin-right', img.css('margin-right'));
            img.css('margin-right', '0');

            wrapper.css('margin-left', img.css('margin-left'));
            img.css('margin-left', '0');

            wrapper.css('margin-bottom', img.css('margin-bottom'));
            img.css('margin-bottom', '0px');

            wrapper.css('margin-top', img.css('margin-top'));
            img.css('margin-top', '0');

            wrapper.css('display', 'block');
            img.css('display', 'block');

            img.css('position', 'relative');
            wrapper.css('position', 'relative');

            // wrap image
            img.wrap(wrapper);

            // add rounded corners
            img.after('<div class="tl"></div>');
            img.after('<div class="tr"></div>');
            img.after('<div class="bl"></div>');
            img.after('<div class="br"></div>');
			img.css('cursor','pointer').click(function(){/*esto es un fix para ie 7 ya que no andan los click en la imagen de otra forma*/
				var papa = jQuery(this).parents('a:first');
				if(!papa.length)
					return;
				papa = papa[0];
				papa.click();
			});
    });

}



function ajaxLoadingBUI()
{
	$.blockUI({
		message: '<div class="ajaxLoader">Aguarde un momento por favor...</div>',
		onUnblock: null,
		css: {
			border: 'none',
			padding: '15px',
			backgroundColor: '#000',
			'-webkit-border-radius': '10px',
			'-moz-border-radius': '10px',
			opacity: '1',
			color: '#fff'
		}
	});
}


function bindBtnCloseBUI()
{
	$('.btnCloseBUI').click(function(){
		$.unblockUI();
		$(this).unbind('click');
	});
}


function ajaxError(idContainer)
{
	$('#' + idContainer).ajaxError(function(event, request, settings)
	{
		$.get('/includes/ajaxError.php',
			  {
			   url: settings.url
			  },
			  function(data){
				  $('#' + idContainer).html(data);
		});

	});
	$.unblockUI();
}


function bloquearPantalla(mensaje, autoClose)
{

	if(!autoClose)
		mensaje = mensaje + '<br /><input type="button" class="btnCloseBUI" value="Cerrar" />';

    $.blockUI({
        message: mensaje,
        onUnblock: null,
        css: {
            top: '2px',
            left: '25%',
            width: '50%',
            border: 'none',
            padding: '15px',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px',
            opacity: '1',
            color: '#fff',
			'z-index':10000
        }
    });

	if(!autoClose)
		bindBtnCloseBUI();
}



function habilitarPantalla()
{
    var pos = $("#wrapper").offset();
    $("html").animate(
    {
        scrollTop: pos.top + "px"
    },

    {
        duration: 1000
    }, setTimeout($.unblockUI, 1100)
        );

}




function bindClickImgContent()
{

    $('div.cont img').each(function(){
    	if(!this.complete){
        	this.onload = function(){
				var randclass = 'fancyBox'+parseInt(Math.random()*1000000000000);
        		$(this).replaceWith('<a class="'+randclass+'" href="' + $(this).attr('src') + '" target="_blank"><img src="' + $(this).attr('src') + '" height="' + $(this).height() + '" width="' + $(this).width() + '" align="' + $(this).attr('align') + '" border="' + $(this).attr('border') + '" hspace="' + $(this).attr('hspace') + '" vspace="' + $(this).attr('vspace') + '"></a>');
        		$('.'+randclass).fancybox({'imageScale':true}).removeClass('.'+randclass).addClass('fancyBox');
        	}
        }
        else{
			var randclass = 'fancyBox'+parseInt(Math.random()*1000000000000);
    		$(this).replaceWith('<a class="'+randclass+'" href="' + $(this).attr('src') + '" target="_blank"><img src="' + $(this).attr('src') + '" height="' + $(this).height() + '" width="' + $(this).width() + '" align="' + $(this).attr('align') + '" border="' + $(this).attr('border') + '" hspace="' + $(this).attr('hspace') + '" vspace="' + $(this).attr('vspace') + '"></a>');
    		$('.'+randclass).fancybox({'imageScale':true}).removeClass('.'+randclass).addClass('fancyBox');
		}
    });

    $('.bottomArea .optTargetTamanoTexto img').each(function(){
        if(!this.complete){
        	this.onload = function(){
				var randclass = 'fancyBox'+parseInt(Math.random()*1000000000000);
        		$(this).replaceWith('<a class="'+randclass+'" href="' + $(this).attr('src') + '" target="_blank"><img src="' + $(this).attr('src') + '" height="' + $(this).height() + '" width="' + $(this).width() + '" align="' + $(this).attr('align') + '" border="' + $(this).attr('border') + '" hspace="' + $(this).attr('hspace') + '" vspace="' + $(this).attr('vspace') + '"></a>');
        		$('.'+randclass+' img')
        			.css('display','block')
				;
        		$('.'+randclass)
					.fancybox({'imageScale':true})
					.removeClass(randclass)
					.css('display','inline')
				;
			}
		}
		else{
			var randclass = 'fancyBox'+parseInt(Math.random()*1000000000000);
    		$(this).replaceWith('<a class="'+randclass+'" href="' + $(this).attr('src') + '" target="_blank"><img src="' + $(this).attr('src') + '" height="' + $(this).height() + '" width="' + $(this).width() + '" align="' + $(this).attr('align') + '" border="' + $(this).attr('border') + '" hspace="' + $(this).attr('hspace') + '" vspace="' + $(this).attr('vspace') + '"></a>');
        		$('.'+randclass+' img')
        			.css('display','block')
				;
        		$('.'+randclass)
					.fancybox({'imageScale':true})
					.removeClass(randclass)
					.css('display','inline')
				;
		}
    });
	$('#modulo_noticias .baleft .desarrolloNoticia .textoEstilo_1:eq(0)').css('display','inline').css('float','none').css('clear','none');


    
}