/*****************************************************************************
The sIFR configuration should typically go in `sifr-config.js`, but in order to
keep the config file clean, and to give a quick overview, it's done here instead.
*****************************************************************************/
/*var harabara = {
  src: 'swf/harabara.swf'
};

// You probably want to switch this on, but read <http://wiki.novemberborn.net/sifr3/DetectingCSSLoad> first.
// sIFR.useStyleCheck = true;
sIFR.activate(harabara);

sIFR.replace(harabara, {selector: '.title_slogan_01' ,css: ['.sIFR-root {color: #004D91; letter-spacing:4 }','a { text-decoration: none; }','a:link { color: #004D91; }','a:hover { color: #004D91; }'], offsetLeft: '2px', fixFocus: true, wmode: 'transparent'});
sIFR.replace(harabara, {selector: '.title_slogan_02, .title_seccion_header' ,css: ['.sIFR-root {color: #004D91; letter-spacing:5; }','a { text-decoration: none; }','a:link { color: #004D91; }','a:hover { color: #004D91; }'], offsetLeft: '2px', fixFocus: true, wmode: 'transparent'});
sIFR.replace(harabara, {selector: '.title_que_hacemos, .title_nuestros_clientes, .title_servicio, .title_servicio2' ,css: ['.sIFR-root {color: #FFFFFF; letter-spacing:2; }','a { text-decoration: none; }','a:link { color: #FFFFFF; }','a:hover { color: #FFFFFF; }'], offsetLeft: '2px', fixFocus: true, wmode: 'transparent'});
sIFR.replace(harabara, {selector: '.title_donde, .title_quienes_somos, .title_integrante' ,css: ['.sIFR-root {color: #000000; letter-spacing:2; }','a { text-decoration: none; }','a:link { color: #000000; }','a:hover { color: #000000; }'], offsetLeft: '2px', fixFocus: true, wmode: 'transparent'});
sIFR.replace(harabara, {selector: '.title_seccion_right, .title_actividad' ,css: ['.sIFR-root {color: #004D91; letter-spacing:1; }','a { text-decoration: none; }','a:link { color: #004D91; }','a:hover { color: #004D91; }'], offsetLeft: '2px', fixFocus: true, wmode: 'transparent'});
sIFR.replace(harabara, {selector: '.title_actividad_01, .title_actividad_02' ,css: ['.sIFR-root {color: #004D91; letter-spacing:3 }','a { text-decoration: none; }','a:link { color: #004D91; }','a:hover { color: #004D91; }'], offsetLeft: '2px', fixFocus: true, wmode: 'transparent'});
*/

// Plugins JQuery.

// Vertical Align.
(function ($) {
	$.fn.vAlign = function(container) {
		return this.each(function(i){
			if(container == null) {
				container = 'div';
			}
			$(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
			var el = $(this).children(container + ":first");
			var elh = $(el).height(); //new element height
			var ph = $(this).height(); //parent height
			var nh = (ph - elh) / 2; //new height to apply
			$(el).css('margin-top', nh);
		});
	};
})(jQuery);

// Top Link Plugin.
jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200
	}, settings);
	return this.each(function() {
		//listen for scroll
		var el = $(this);
		el.hide(); //in case the user forgot
		$(window).scroll(function() {
			if($(window).scrollTop() >= settings.min)
			{
				el.fadeIn(settings.fadeSpeed);
			}
			else
			{
				el.fadeOut(settings.fadeSpeed);
			}
		});
	});
};	

// Preloader de "Contacto.
var enviaFormularioContacto = function() {
	xajax.dom.create("loading","div", "loading");
  	xajax.$('loading').innerHTML='<div class="procesando"><img src="img/loading.gif" width="133" height="24" class="middle loading" alt=""/>Processing...</div>';
}

// Cargo el mapa de Google Maps.
function cargaGoogleMaps (box, latitud, longitud) {
								   
	// Comprobamos si el navegador es compatible con los mapas de Google.
	if (GBrowserIsCompatible()) { 
	
		// Creo el mapa de localizacon de la tienda.
		var mapa = new GMap2(document.getElementById(box));
		mapa.setCenter(new GLatLng(latitud,longitud), 15, G_NORMAL_MAP);
		mapa.addControl(new GSmallMapControl(),new GControlPosition (G_ANCHOR_TOP_LEFT, new GSize(8, 3)));
		mapa.addControl(new GMapTypeControl(),new GControlPosition (G_ANCHOR_TOP_RIGHT, new GSize(5, 5)));				
		var point = new GLatLng(latitud,longitud);
		mapa.addOverlay(new GMarker(point));
		
	
	} else {
		
		// Pongo la imágen del mapa.
		
		if(box == 'mapa_ubicacion'){
			var mapa = document.getElementById(box).innerHTML = '<img src="img/mapa_ubicacion.jpg" width="285" height="130" />';						
		} 		
		
	}
		
}

// Funcion para cargar el video.
function cargarVideo(video, screenshot, video_box){
	
	var flashvars = {
		//idvideo: "http://bitcast-g.bitgravity.com/masfusion/masfusion_400.flv",
		idvideo: "http://bitcast-g.bitgravity.com/masfusion/"+ video +"",
		idimagen: screenshot
	};
	var params = {
		menu: "true",
		wmode: "transparent",
		scale: "noscale",
		allowfullscreen: "true"
	
	};
	var attributes = {
		id: "masfusionID",
		name: "masfusion",
		align: "middle"
	};
	
	
	swfobject.embedSWF("swf/player_masfusion.swf", video_box, "600", "251", "9.0.115","expressInstall.swf", flashvars, params, attributes);

};


// DOM Ready General.
$(document).ready(function(){
						  
	// Agrego el link de Top.						  
	$("#contenedor_general").before('<div class="go_top"><img src="img/iconos/top.jpg" width="10" height="11" alt="" /><a href="javascript:void(0);" class="link_rojo">Top of Page</a></div>');						  
	
	// Alineacion Vertical.
	$("#logo, #contenido_slogan .right, #contenido_slogan_actividad .right").vAlign();
	
	$(".title_slogan_01, .title_slogan_02, .title_que_hacemos, .title_donde, .title_quienes_somos, .title_integrante, .title_nuestros_clientes, .title_seccion_right, .title_seccion_header, .title_integrante, .title_actividad_01, .title_actividad_02, .title_actividad, .title_servicio, .title_servicio2, .title_nosotros_01, .title_nosotros_02").css({"visibility":"visible"});
	
	Cufon.replace(['.title_seccion_right', '.title_actividad'], {
		letterSpacing : '1px'
	});
	Cufon.replace(['.title_que_hacemos', '.title_nuestros_clientes', '.title_servicio', '.title_servicio2', '.title_donde', '.title_quienes_somos', '.title_integrante'], {
		letterSpacing : '2px'
	});
	Cufon.replace(['.title_actividad_01', '.title_actividad_02'], {
		letterSpacing : '3px'
	});
	Cufon.replace(['.title_slogan_01', '.title_nosotros_01'], {
		letterSpacing : '4px'
	});
	Cufon.replace(['.title_slogan_02', '.title_nosotros_02', '.title_seccion_header'], {
		letterSpacing : '5px'
	});	
	
	// Menu
	$('.menu a').css({backgroundPosition: "0px -72px"}).mouseover(function(){
		$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:300})
	}).mouseout(function(){
		$(this).stop().animate({backgroundPosition:"(0px -72px)"}, {duration:300})
	})
	
	$(".menu a").click(function() {
		var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500);
	});		
	
	// Integrantes.
	$(".row_integrante").find('.integrante:last').addClass('no_margin');
	
	// Nuestros clientes.
	var cantidad_clientes = $(".cliente").length;
	for(i=0; i<=cantidad_clientes; i++){
		if((i + 1)%5==0){
			$(".cliente").eq(i).addClass('no_margin');
		}
	}
	
	/*$('#contenedor_clientes').children().hover(function() {
		$(this).siblings().stop().fadeTo(500,0.6);
	}, function() {
		$(this).siblings().stop().fadeTo(500,1);
	});*/
	
	$(".integrante .foto_integrante img").mouseover(function(){
		$(this).animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200).animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200).animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200);
	}).mouseout(function(){
		$(this).animate({marginTop: "24px"}, 200);
	
	});
	
	$(".integrante .datos_integrante .link_azul").mouseover(function(){
		$(this).parent().parent().find(".foto_integrante").find("img").animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200).animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200).animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200);
	}).mouseout(function(){
		$(this).parent().parent().find(".foto_integrante").find("img").animate({marginTop: "24px"}, 200);
	
	});	
	
	// Footer.
	var altura_footer = $("#footer").height();
	$("#redes_sociales").height(altura_footer - 50);
	
	// Contacto.
	$("#enviar_formulario_contacto").click(function(){
		$("#text_mensaje").fadeOut(1000);												
	});
	
	$("#foto_perfil .foto_integrante img").mouseover(function(){
		$(this).animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200).animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200).animate({marginTop: "19px"}, 200).animate({marginTop: "24px"}, 200);
	}).mouseout(function(){
		$(this).animate({marginTop: "24px"}, 200);
	});	
	
	// Mapa de Ubicacion.
	//cargaGoogleMaps('mapa_ubicacion', '20.657322', '-103.398256');
	
	// Obtengo las imagenes de Flickr.
	//xajax_getImageFlickr("44503777@N03");
	//cargarVideo('resumen_garage.flv','img/screenshots/garage.jpg','video_que_hacemos'); 
	
	// Muestro las imagenes de la actividad.
	$('#actividad_mes .slideshow img').css({"display":"block"});
	
	// Set the link
	$('.go_top').topLink({
		min: 90,
		fadeSpeed: 500
	});
	//smoothscroll
	$('.go_top').click(function(e) {
		var destination = $("#header").offset().top;								
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500);
	});	
	
});	