// JavaScript Document
var envioHabilitado = true;
var envioCVHabilitado = true;
	
$(document).ready(function(){
	$('input').focus(function(){
		if ($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	});
	$('input').blur(function(){
		if ($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
	$('textarea').focus(function(){
		if ($(this).val() == $(this).attr('title')){
			$(this).val('');
		}
	});
	$('textarea').blur(function(){
		if ($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
});


//FUNCIONES **************************************************************************************************************************************

function cargarMapas(){
	var myOptionsAr = {
		zoom: 15,
		center: latlngAr,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		navigationControl: true,
		mapTypeControl: false,
		scaleControl: false
	};
	map = new google.maps.Map(document.getElementById("mapa"), myOptionsAr);
	var markerAr = new google.maps.Marker({
											position: latlngAr,
											icon: "./images/logo_wr_mapa.gif",
											title: "Workroom Argentina",
											map: map
										});
	var markerBr = new google.maps.Marker({
											position: latlngBr,
											icon: "./images/logo_wr_mapa.gif",
											title: "Workroom Brasil",
											map: map
										});
}

function showMapa(pais){
	$("#mapa").parent().removeClass("pop-up-mapa_ar");
	$("#mapa").parent().removeClass("pop-up-mapa_br");
	if(pais == "Ar"){
		map.setCenter(latlngAr);
		$("#mapa").parent().addClass("pop-up-mapa_ar");
	} else {
		map.setCenter(latlngBr);
		$("#mapa").parent().addClass("pop-up-mapa_br");
	}
}


function ajustarHeight(){
	//trabajamos con tamaño de display del browser para dejar cada seccion ocupando todo el lugar		
	$("#fdo_home").css('min-height', $(window).height() + 'px');
	$("#fdo_partners").css('min-height', $(window).height() + 'px');
	$("#fdo_contenido_partners").css('min-height', $(window).height() + 'px');
	$("#matias").css('min-height', $(window).height() + 'px');
	$("#fdo_nuestro_equipo").css('min-height', $(window).height() + 'px');
	
	$("#fdo_home").css('_min-height', $(window).height() + 'px');
	$("#fdo_partners").css('_min-height', $(window).height() + 'px');
	$("#fdo_contenido_partners").css('_min-height', $(window).height() + 'px');
	$("#matias").css('_min-height', $(window).height() + 'px');
	$("#fdo_nuestro_equipo").css('_min-height', $(window).height() + 'px');
}

function listenLastTweet(){
	$(".twitter_matias").tweet({
		join_text: "auto",
		username: "matiasfeldman",
		avatar_size: 40,
		count: 1,
		refresh_interval: 10
	});
	
	$("#twitterWR").tweet({
		join_text: "auto",
		username: "workroomdigital",
		avatar_size: 40,
		count: 1,
		refresh_interval: 10
	});
}

function getFlickrImages(){
	/*
	id (Optional)     A single user ID. This specifies a user to fetch for.
	ids (Optional)    A comma delimited list of user IDs. This specifies a list of users to fetch for.
	tags (Optional)    A comma delimited list of tags to filter the feed by.
	tagmode (Optional)    Control whether items must have ALL the tags (tagmode=all), or ANY (tagmode=any) of the tags. Default is ALL.
	format (Optional)    The format of the feed. See the feeds page for feed format information. Default is Atom 1.0.
	lang (Optional)    The display language for the feed. See the feeds page for feed language information. Default is US English (en-us). 
	*/
	
	var id="39325294@N06";

	var url_flickr_wr = "http://flickr.com/photos/workroomdigital"
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id="+id+"&format=json&jsoncallback=?", function(data){
		$.each(data.items, function(i,item){
			var image_path = (item.media.m).replace("_m.jpg", "_s.jpg");
			var aux = image_path.split('/');
			var image_name = aux[aux.length-1];
			if(i < 9) {
				//$("<img/>").attr("src", image_path).attr('height', '62').attr('width', '62').attr('border', 'none').appendTo('#fotosFlickr').wrap("<a class='boton_foto' rel='lightbox[flickr]' href='" + image_path.replace('_s.jpg', '_z.jpg') + "'></a>");
				
				var ancla = document.createElement("a");
				ancla.setAttribute('class','boton_foto');
				ancla.setAttribute('rel','lightbox[flickr]');
				ancla.setAttribute('href',image_path.replace("_s.jpg", "_z.jpg"));
				
				var oImg=document.createElement("img");
				oImg.setAttribute('src', image_path);
				oImg.setAttribute('alt', '');
				oImg.setAttribute('height', '62');
				oImg.setAttribute('width', '62');
				oImg.setAttribute('border', '0');
				
				ancla.appendChild(oImg);
				$("#fotosFlickr").prepend(ancla);

			} else {
				/*$("<img/>").attr("src", image_path).attr("height", '62').attr("width", '62').attr("border", 'none').appendTo("#fotosFlickr").wrap("<a class='boton_foto' style='display:none' rel='lightbox[flickr]' href='" + image_path.replace("_s.jpg", "_z.jpg") + "'></a>");*/
				return;
			}
		});
		setSlideshow();
	});
}

function setSlideshow(){
	$('#fotosFlickr a').lightBox();
}

function setEfectosBotonera(){
	//botonera home
	$("#botonera_partners").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$("#botonera_que_hacemos").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$("#botonera_matias").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$("#botonera_equipo").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$("#botonera_contacto").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$("#botonera_rrhh").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	
	//botonera partners
	$(".sitios").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$(".campanias").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$(".mobile").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$(".social").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$(".innovacion").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
	$(".audiovisual").hover(function() {
		$(this).stop().animate({ opacity: 0.0 }, 0);
		$(this).animate({ opacity: 1.0 }, 300);
	});
}

function setearFormContacto(){
	$("#contactoForm").submit(function(){ 
		var hubo_error = false;
		
		$('#errorFormContacto').hide();
		$('#nombreContacto').removeClass('errorForm');
		$('#emailContacto').removeClass('errorForm');
		$('#asuntoContacto').removeClass('errorForm');
		$('#comentarioContacto').removeClass('errorForm');
		
		if($('#nombreContacto').val() == '' || $('#nombreContacto').val() == $('#nombreContacto').attr("title")) {
			$('#nombreContacto').addClass('errorForm');
			hubo_error = true;
		}
		if($('#emailContacto').val() == '' || $('#emailContacto').val() == $('#emailContacto').attr("title")) {
			$('#emailContacto').addClass('errorForm');
			hubo_error = true;
		}
		if($('#asuntoContacto').val() == '' || $('#asuntoContacto').val() == $('#asuntoContacto').attr("title")) {
			$('#asuntoContacto').addClass('errorForm');
			hubo_error = true;
		}
		if($('#comentarioContacto').val() == '' || $('#comentarioContacto').val() == $('#comentarioContacto').attr("title")) {
			$('#comentarioContacto').addClass('errorForm');
			hubo_error = true;
		}
		
		if(!hubo_error && envioHabilitado){
			envioHabilitado = false;
			$.ajax({
				type: "POST",
				url: "acc_contacto.php",
				data: "nombre=" + $('#nombreContacto').val() + "&email=" + $('#emailContacto').val() + "&asunto=" + $('#asuntoContacto').val() + "&comentario=" + $('#comentarioContacto').val(),
				success: function(msg) {						
					if (msg == "ok") {
						$('#nombreContacto').val($('#nombreContacto').attr("title"));
						$('#emailContacto').val($('#emailContacto').attr("title"));
						$('#asuntoContacto').val($('#asuntoContacto').attr("title"));
						$('#comentarioContacto').val($('#comentarioContacto').attr("title"));
						
						$('#pop_up_envio_mail').fadeIn(600, function(){
							window.setTimeout(function(){
								$('#pop_up_envio_mail').fadeOut(1500);
							},3000);
						});
						
					} else {
						$('#errorFormContacto').show();
						var errores  = msg.split('|');
						for(i=0; i<errores.length; i++){
							if(i>0){
								$('#'+errores[i]+'Contacto').addClass('errorForm');
							}
						}
					}
					envioHabilitado = true;
				}
			});
		} else if(hubo_error){
			$('#errorFormContacto').show();
		}
	 	return false;
	});  
  
}

function validarFormCV(){
	var hubo_error = false;
		
	//$('#errorFormContacto').hide();
	$('#nombreCV').removeClass('errorForm');
	$('#puestoCV').removeClass('errorForm');
	$('#archivoCV').removeClass('errorForm');
	
	if($('#nombreCV').val() == '' || $('#nombreCV').val() == $('#nombreCV').attr("title")) {
		$('#nombreCV').addClass('errorForm');
		hubo_error = true;
	}
	if($('#puestoCV').val() == '' || $('#puestoCV').val() == $('#puestoCV').attr("title")) {
		$('#puestoCV').addClass('errorForm');
		hubo_error = true;
	}
	if($('#archivoCV').val() == '' || $('#archivoCV').val() == $('#archivoCV').attr("title")) {
		$('#archivoCV').addClass('errorForm');
		hubo_error = true;
	}
	
	if(!hubo_error && envioCVHabilitado){
		envioHabilitado = false;
		document.formCV.submit();
	}
}

function responseFormCV(msg){
	if(msg == "ok"){
		$('#nombreCV').val($('#nombreCV').attr("title"));
		$('#puestoCV').val($('#puestoCV').attr("title"));
		$('#archivoCV').val('');
		
		$('#pop_up_subir_archivo').fadeIn(600, function(){
			window.setTimeout(function(){
				$('#pop_up_subir_archivo').fadeOut(1500);
			},3000);
		});
		alert("a");
	} else {
		var errores  = msg.split('|');
		for(i=0; i<errores.length; i++){
			if(i>0){
				$('#'+errores[i]+'CV').addClass('errorForm');
			}
		}
	}
	envioCVHabilitado = true;
}

function showDivPartners(index){
	$('#texto_partners div').hide();
	$('#texto_partners div').each(function (i,item){
		if(i == parseInt(index)){
			if(videosQueHacemos[i] == ''){
				$('#videoQueHacemos').hide();
				$('#videoQueHacemosProximamente').show();
			} else {
				$('#videoQueHacemosProximamente').hide();
				$('#videoQueHacemos').attr('src', videosQueHacemos[i]);
				$('#videoQueHacemos').show();
			}
			$('#fbQueHacemos').attr('href', fbQueHacemos[i]);
			$('#lnQueHacemos').attr('href', lnQueHacemos[i]);
			$('#twQueHacemos').attr('href', twQueHacemos[i]);
			$(this).show();
		}
	});
}

function setaearPuestoyBusqueda(puesto, idbusqueda){
	$('#busquedaCV').val(idbusqueda);
	$('#puestoCV').val(puesto)
}
