

host = 'http://www.prodemel.es';


// MENSAGES
var msg = new Array();
msg['prueba'] = 'bla';

$(document).ready(function() {
	
	
	//$('#dialog').dialog({modal: true,resizable: false,draggable: false,width: 600,height:500});
	
	// OPCION PRINCIPAL
	//var navP = $('#nav-principal').attr('title');
	var navP = $('#nav-principal').text();
	
	// IDIOMA
	var lg = $('#lg').text();
	if (lg == false) lg = 'es';
	
	// LAS IMAGENES SON CARGADAS A PARTE
	var l = $(jQuery.makeArray(document.images)).size();
                
	$(document.images).each(function(n, v) {
		var img = new Image();
		$(img).attr({'src': $(v).attr('src')});
		
		// APARECE CONTENIDO
		if (n == l-1) $('#contenido').css({'display':'block'});
                
		})
	
	// CAMBIO IMAGEN PORTADA
	/*
	$('#puente').click( function () {
		if (this.src == host+'/media/comun/portada_pipe.png') {$(this).attr({'src' :this.src.replace(/_pipe\.png/,'_fotos.jpg') });}
		else if (this.src == host+'/media/comun/portada_fotos.jpg') {$(this).attr({'src' :this.src.replace(/\_fotos\.jpg/,'_pipe.png') });}
		});
	
	*/	
	// SCROLL VOLVER ARRIBA
	$('a.control').live('click',function () {
		if ($(this).attr('href') == '#arriba') {
			$('body, html').animate({scrollTop:0})
			}
			
		return false;
		})
	
	// IMAGEN PROYECTOS GRANDE

	$.fn.image = function(src,i, f){ 
		return this.each(function(){ 
			//var i = new Image();
			i.onload = f;
			i.src = src;
			this.appendChild(i);
			}); 
		} 
	
	$('.imagen-proyectos').click(function(){
		var i = new Image()
		var s = this.src.replace(/.jpg/,'_l.jpg')
		var t = $(this).attr('title')
		
		$('body').espera();
		
		//$(i).attr({'src': s});
		//$('#basura').append(i);
		//$.get(host+'/js/miscripts/imagen.php',{imagen: s}, function(data) {
		
		$("#basura").image(s,i,function(){
			
			var h = i.height;
			var w = i.width;
			
			if($(window).height() < h ) h = $(window).height()-20;
			if($(window).width() < w ) w = $(window).width()-20;
			
			if (h) {
				$('body').espera(1)
				$('#dialog')
					.css({
						'background':'center center url('+s+') no-repeat',
						'width':w+'px',
						'height':h+'px'
						})
					.dialog({
						modal: true,
						resizable: false,
						draggable: false,
						title: t,
						height: h,
						width: w,
						close: function(event, ui) {
							$(this).dialog('destroy')
							$('#dialog, #basura').html('')
							}
						})
				}
			})
	});
	
	// MARCAR SUBMENU PROYECTOS PAPEL
	
	if($('#proyectos') && $('.sub-nav').children('a').hasClass('activo') == false) {
		$('.sub-nav a:first').attr({'class':'activo'})
		}
		
	// IMPIDE PETICIONES REPETIDAS
	$('.activo').click(function(){return false})
	
	// HACER EL CAMBIO DE CUALQUIERA IMAGEN
	$.fn.cambiazo = function(src){
	
			i = new Image();
			i.src = src;
			
			$(this)
				.animate({'opacity':0.6})
                		.attr({'src':i.src})
                		.animate({'opacity':1});	
                     
		}
	
	// LOADER
	
	$.fn.espera = function(remove) {
		
		if (remove == 1){
			$('#bloquear').remove();
			
		} else {
			
			$('body').append('<div id="bloquear"/>');
			$('#bloquear')
				.height($(document).height())
				.click(function() {$(this).remove()})
				.css({
					'background-position':'50% '+($(window).height()/2+$('body').scrollTop()-24) +'px',
					opacity: 0.30
					})
			if ($.browser.safari) {
				$('#bloquear').css({'background-attachment':'scroll'})
				}
			}
		}
	
	// IGUALAR COLUMNAS DEL CONTACTO
	
	// if ($('#right').is('div')) { $('#right').height($('#fullright').height() - 50);}
	 if (($('#comunes').height() - $('#left').height()) < 0) {
	 	//$('#footer').before('<div style="height:'+ ($('#comunes').height() - $('#left').height()) +'px;width:100%;background-color:#CCC;">bla </div>');
	 	}
	
	
	// FIN JQUERY
});

