
/*

JavaScript
FrameWork - Jquery
NOVEMBRO S.L.
2009/01/22

SIMELEC SL
efectos.js

*/

var host = 'http://simelec.es';

$(document).ready(function() {

	
	// lenguaje
	var lg = $('meta[name="language"]').attr('content');
	if (lg == '') {lg = 'es'};
	
	// NOTICIAS QUITAR IMAGENS DEL DIV
	$('.texto-noticia').append($('.texto-noticia div').find('img'));
	
	
	// REDONDEAR
	//$('#ahora-estamos').corner("tr br");
		
	// QUITAR AHORA-ESTAMOS
	
	if ($('#etiquetas,.etiquetas').is('div')) {
		$('#ahora-estamos').remove()
		}
	
	
	
	// AJUSTAR EN UNA LINEA
	else {
		lon = $('#ahora-estamos').text().length
		if (lon > 37) {
			str = $('#ahora-estamos').text()
			var arr = new Array()
			
			arr =  jQuery.makeArray(str.split('.: '))
			ultimo = arr.pop()
			
			//alert(ultimo)
			nuevoTexto = '.: ';
			jQuery.each(arr, function(i,val){
				if (i!=0) nuevoTexto += val.substr(0,5) + '.. .: ';
				})
				
			$('#ahora-estamos > h5')
				.text(nuevoTexto + ultimo)
				.css({'font-size': '14px'})
			}	
		}
	
	// CORTINA EN LOS PRODUCTOS
	$('h3').click(function () {
	
		var o = $(this).next();
		var down = 0;
		
		if (o.css('display') == 'none') o.slideDown("slow");
		else o.slideUp("slow");
			
		
	});
	
	// DESPLEGAR PRIMERA OPCION SI SOLO HAY UNA
	var contar;
	$("h3").each(function(i){contar = i})
	
	if (contar < 4) {
		$("h3").next().show()
		$('h3').unbind('click').css({'cursor':'default'})
		}
	else {
		//setTimeout('$("h3:last").next().slideDown("slow")',500)
		}

		
	
	// GALERIA DE IMAGENES
	$('a.fancy').fancybox({});
	
	// ROLLOVERS - LA PROPRIA IMAGEN
	
	$('.rollover').mouseover( function () {
		img = $(this).attr('src')
		$(this).attr({'src':img.replace( /.png/, '-h.png')})
		}).mouseout( function () {
			$(this).attr({'src':img})	
			});
	
	// ROLLOVERS - IMAGEN ESTA CONTENIDA EN ...
	
	$('.rollover-dentro').mouseover( function () {
		$('img', this).each( function () {
			img = $(this).attr('src')
			$(this).attr({'src':img.replace( /.png/, '-h.png')})
			})
		}).mouseout( function () {
			$('img', this).each( function () {
				$(this).attr({'src':img})	
				})
			});
	
	// MARCAR IDIOMAS
	
	$('img[alt="lang"]').each(function() {
		
		if( $('#lang').attr('name') == $(this).attr('title') ) {
			img = $(this).attr('src')
			$(this).parent().replaceWith('<img src="'+img.replace( /.png/, '-h.png"')+' />')
			}
		})
	
	// MARCAR SUBMENU REFERENCIAS PROYECTOS
	if($('#menu-proyecto') && $('#menu-proyecto').children('a').hasClass('activo') == false) {
		$('#menu-proyecto a:first').attr({'class':'activo'})
		}
	
	// BOTON DEMO MONITORIZACION
	$('a:contains("Monitorización"), a:contains("Monitoring")').attr({'href':'#'})
	
	$('a:contains("Monitorización"), a:contains("Monitoring")').click( function() {
		acceder();
		return false
		})
		
	function acceder () {
		//x=window.open("/templates/formGPM.htm","GPM","channelMode=yes,fullscreen=yes,location=0,menubar=0,status=0,titlebar=0,toolbar=0")
		var x=window.open(host + "/templates/formGPM.htm","GPM","fullscreen=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
		x.resizeTo(screen.availWidth,screen.availHeight);
		x.moveTo(0,0);
		x.resizeTo (screen.availWidth,screen.availHeight);
		}
		
	// REFERENCIAS INSTALACIONES
	$('#referencias_instalaciones > img').click(function (){
	
		img = $(this).attr('src').replace(/thumb/,'slide');
		
		$(new Image()).load(function() {
			$('<img width="450" src="' + img +'" />').fancybox();
			}).attr('src',img);
		})
	
	// CLIENTES
	
	$('#acceso-clientes').live('click', function(){
	
		jQuery.get(host + '/templates/login.htm', function(data){
			form = data.replace(/\$base/g, host);
			$.fancybox(form);
			}); 
		});
	
	
	// AVISO LEGAL
	
	$('#aviso-legal').live('click', function(){
		
		jQuery.get(host + '/contenidos/es/aviso_legal.html', function(data){
			form = data.replace(/\$base/g, host) 
			$.fancybox(form)
			}) 
		return false;
		})
		
	// CONTROLES DE NAVEGACION ARRIBA VOLVER
	
	$('#volver, #arriba').click(function(){
		if (this.id == 'arriba') {
			$('body, html').animate({'scrollTop':'0px'},500)
			}
		if (this.id == 'volver') {
			history.back(1);
			}
			
		return false;
		})
		
	// GOOGLE TRANSLATOR
	if (lg != 'es') {
		
		$('body').translate( { from: 'es', to: lg , fromOriginal: true, not: $('.notr, .imgNum, .imgSim, .fsim, img')} );
		    		
		};
		
	
});

