jQuery.event.add(window, "load", resizeFrame);
jQuery.event.add(window, "resize", resizeFrame);
function resizeFrame() {
 	var h = $(window).height();
    var w = $(window).width();
	w = w-1000;
	if (w>60&&w<308){
		$('#page-left').css('width',(w/2)+"px");
		$('#page-left').css('margin-left',("-"+(500+(w/2))+"px"));
		$('#page-right').css('width',(w/2)+"px");
	}
	else if (w<=60){
		$('#page-left').css('width',"30px");
		$('#page-left').css('margin-left',("-"+(500+(w/2))+"px"));
		$('#page-right').css('width',"0px");
	}
	else{
		$('#page-left').css('width',"154px");
		$('#page-left').css('margin-left',("-654px"));
		$('#page-right').css('width',"154px");
		$('#page-right').css('margin-left',("500px"));
	}
}
function initSlider(){
	if ($('.pix_diapo').length > 0){
		$('.pix_diapo').diapo({fx: 'scrollHorz', time: '2000', navigation: 'false', thumbs:'false', loader: 'none', pauseOnClick:'false'});
		$(".pix_diapo div").each(function(){
			if ($(this).not().hasClass('pix_relativize')){
				var titulo = "";
				var contenido = "";		
				if ($(this).find("iframe").html()!=null){
					$(this).parent().find("p").remove();
					src = $(this).parent().find("img").attr("src");
					$(this).parent().find("a").remove();
					$(this).find("iframe").attr('data-fake', src);
					$(this).find("iframe").attr('width', 650);
					$(this).find("iframe").attr('height', 366);
					titulo = $(this).find("strong").html();
					$(this).find("strong").remove();
					contenido = $(this).text();
				}
				else if ($(this).find("a").html()!=null){
					titulo = $(this).find("strong").html();
					$(this).find("strong").remove();
					contenido = $(this).text();
					//$(this).html($(this).find("a").html());
				}
				if (titulo != null && contenido != ""){
					$(this).append("<div class=\"caption elemHover fromLeft\"><div>"+titulo+"</div>"+contenido+"</div>");
				}
				else if (titulo == null && contenido != ""){
					$(this).append("<div class=\"caption elemHover fromLeft\">"+contenido+"</div>");
				}
			}
		});
		$(".pix_diapo div").click(function(){
			if ($(this).find("iframe").html()!=null){
				$(this).parent().diapoStop();
				$(".caption").css('visibility','hidden');
				src_iframe = $(this).find("iframe").attr("src");
				if (src_iframe.lastIndexOf("?")==-1){
					src_iframe = src_iframe + "?rel=0&autoplay=1";
				}
				else{
					src_iframe = src_iframe + "&autoplay=1";
				}
				$(this).find("iframe").attr('src', src_iframe);
			}	
		});
	}
	if ($('.proceso').length > 0){
		$(".proceso").click(function(){
			if ($(this).find("iframe").html()!=null){
				src_iframe = $(this).find("iframe").attr("src");
				src_iframe_puro = $(this).find("iframe").attr("src");
				if (src_iframe.lastIndexOf("?")==-1){
					src_iframe = src_iframe + "?rel=0&autoplay=1";
				}
				else{
					src_iframe = src_iframe + "&autoplay=1";
				}
				$(this).find("iframe").attr('src', src_iframe);
				if ($('.pix_diapo').length > 0){
					$(this).find("iframe").attr('width', 650);
					$(this).find("iframe").attr('height', 366);
					$('.pix_diapo').html($(this).find("iframe"));
					$(this).find("span").append("<iframe width=\"650\" height=\"366\" src=\""+src_iframe_puro+"\" frameborder=\"0\" allowfullscreen></iframe>");
				}
				else if ($('.proceso-proceso').length > 0){
					$(this).find("iframe").attr('width', 792);
					$(this).find("iframe").attr('height', 408);
					$('.proceso-proceso').html($(this).find("iframe"));
					$(this).find("span").append("<iframe width=\"792\" height=\"408\" src=\""+src_iframe_puro+"\" frameborder=\"0\" allowfullscreen></iframe>");
					
				}
			}
		});
	}
	if ($('.proceso-proceso').length > 0){
		$(".h2-right span").click(function(){
			if ($(this).find("iframe").html()!=null){
				src_iframe = $(this).find("iframe").attr("src");
				src_iframe_puro = $(this).find("iframe").attr("src");
				if (src_iframe.lastIndexOf("?")==-1){
					src_iframe = src_iframe + "?rel=0&autoplay=1";
				}
				else{
					src_iframe = src_iframe + "&autoplay=1";
				}
				$(this).find("iframe").attr('src', src_iframe);
				if ($('.pix_diapo').length > 0){
					$(this).find("iframe").attr('width', 650);
					$(this).find("iframe").attr('height', 366);
					$('.pix_diapo').html($(this).find("iframe"));
					$(this).find("span").append("<iframe width=\"650\" height=\"366\" src=\""+src_iframe_puro+"\" frameborder=\"0\" allowfullscreen></iframe>");
				}
				else if ($('.proceso-proceso').length > 0){
					$(this).find("iframe").attr('width', 792);
					$(this).find("iframe").attr('height', 408);
					$('.proceso-proceso').html($(this).find("iframe"));
					$(this).find("span").append("<iframe width=\"792\" height=\"408\" src=\""+src_iframe_puro+"\" frameborder=\"0\" allowfullscreen></iframe>");
					
				}
			}
			var ejemplo = $(this).attr('class');
			$(".h2-right > span").each(function(){
				if ($(this).attr('class') == ejemplo){
					$(this).find('img').attr('src',"./wp-content/themes/prosumerlab/images/"+ejemplo+"_hover.png");
				}
				else{
					var ejemplo2 = $(this).attr('class');
					$(this).find('img').attr('src',"./wp-content/themes/prosumerlab/images/"+ejemplo2+".png");
				}
			});
		});
	}
	if ($('.proceso-proceso').length > 0){
		if ($('.proceso-proceso').find("iframe").html()!=null){
			$('.proceso-proceso').find("iframe").attr('width', 792);
			$('.proceso-proceso').find("iframe").attr('height', 408);
			$('.proceso-proceso').find("p").remove();
		}
	}
	$('.menu2 .right .euskara a').attr('rel', 'external').html("Euskara");
	$('.menu2 .right .ingles a').attr('rel', 'external').html("Ingl&eacute;s");
}
function muestraGranDiv(){
	$('#content').css('min-height',"757px");
	var h = $("#page").height();
	$('#page-left').css('height',(h)+"px");
	$('#page-right').css('height',(h)+"px");
	$('body').css('visibility','visible');
	$('h2 .left').css('cssText', 'visibility: visible !important');
	$('.slider .title').css('cssText', 'visibility: visible !important');
	$('#content .slider').css('height','366px');
	initSlider();
	knowHeight();
	setLinks();
}
function knowHeight(){
	var h = $(".tb_tweetlist").height();
	var h2 = $("#content .blog1").height();
	if (h2>h){
		$('#content .blog').css('height',(h2+100)+"px");
	}
	else{
		$('#content .blog').css('height',(h+124)+"px");
	}
	var h = $("#page").height();
	$('#page-left').css('height',(h+0)+"px");
	$('#page-right').css('height',(h-0)+"px");
	h=0;
	$(".posts li").each(function(){
		if (h<=$(this).height()){
			h=$(this).height();
		}
	});
	$(".posts li").each(function(){
		$(this).css('height',(h)+"px");
	});
}

function initialize() {
	var map;
	var panorama;
	var astorPlace = new google.maps.LatLng(43.30357,-2.008481);
	var mapOptions = {
		zoom: 16,
		center: astorPlace,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
	    navigationControl: true,
	    navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
		streetViewControl: false
	};
	map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);
			
	var companyLogo = new google.maps.MarkerImage('wp-content/themes/prosumerlab/images/google.png',
	    new google.maps.Size(27,37),
	    new google.maps.Point(0,0),
	    new google.maps.Point(27,37)
	);
	/*var companyShadow = new google.maps.MarkerImage('img/maps/logo_shadow.png',
	    new google.maps.Size(130,50),
	    new google.maps.Point(0,0),
	    new google.maps.Point(65, 50)
	);*/
	var companyPos = new google.maps.LatLng(43.302008,-2.011871);
	var companyMarker = new google.maps.Marker({
	    position: companyPos,
	    map: map,
	    icon: companyLogo,
	    //shadow: companyShadow,
	    title:"Prosumerlab"
	});
				
	panorama = map.getStreetView();
	panorama.setPosition(astorPlace);
	panorama.setPov({
	  	heading: 168,
	   	zoom:2,
	   	pitch:0}
	);
}

function menu_casos(){
	$('.casos-lista ul li').each(function(){
		background = $(this).find("img").attr("src");
		$(this).find("img").remove();
		$(this).css('background-image',"url('"+background+"')");
		$(this).css('background-repeat',"no-repeat");
		$(this).css('background-position',"center center");
	});
	$('.casos-lista ul li a').mouseover(function() {
		$(this).parent().find('.text').css('-ms-filter','progid:DXImageTransform.Microsoft.Alpha(Opacity=100)');
		$(this).parent().find('.text').css('filter',"alpha(opacity=100)");
		$(this).parent().find('.text').css('-moz-opacity',1.0);
		$(this).parent().find('.text').css('-khtml-opacity',1.0);
		$(this).parent().find('.text').css('opacity',1.0);	
	}).mouseout(function(){
    	$(this).parent().find('.text').css('-ms-filter','progid:DXImageTransform.Microsoft.Alpha(Opacity=70)');
		$(this).parent().find('.text').css('filter',"alpha(opacity=70)");
		$(this).parent().find('.text').css('-moz-opacity',0.7);
		$(this).parent().find('.text').css('-khtml-opacity',0.7);
		$(this).parent().find('.text').css('opacity',0.7);	
  	});
  	$('.casos-lista ul li .text').mouseover(function() {
		$(this).css('-ms-filter','progid:DXImageTransform.Microsoft.Alpha(Opacity=100)');
		$(this).css('filter',"alpha(opacity=100)");
		$(this).css('-moz-opacity',1.0);
		$(this).css('-khtml-opacity',1.0);
		$(this).css('opacity',1.0);	
	}).mouseout(function(){
    	$(this).css('-ms-filter','progid:DXImageTransform.Microsoft.Alpha(Opacity=70)');
		$(this).css('filter',"alpha(opacity=70)");
		$(this).css('-moz-opacity',0.7);
		$(this).css('-khtml-opacity',0.7);
		$(this).css('opacity',0.7);	
  	});
	$('.casos a').each(function(){
		$(this).attr('rel', 'lightbox');
	});
	$(function() {
		$('.casos a').lightBox();
	});
	$("#menu-item-38").addClass("current_page_item");
	$('.casos-lista ul').each(function(){
		 var n = $(this).find("li").length;
		 size = ((parseInt(n/4)+1)*260);
		 size2 = (parseInt(n/4)*20);
		 $(this).css('height', (size + size2)+"px");
	});
}
function setLinks() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	if (links.length == 0) return false;
	for (var i = 0; i < links.length; i++) {
		var relation = links[i].getAttribute("rel");
		if (relation == "external") {
			links[i].onclick = function() {
				return !window.open(this.href);
			}
		}     
	}
}
function fotos_equipo(){
	$('<div class="imagen"></div>').insertBefore("#content .equipo ul li p");
	$('<div class="texto"></div>').insertBefore("#content .equipo ul li p");
	$("#content .equipo ul li").each(function(){
		$(this).find('.imagen').html($(this).find('img'));
		imagen = $(this).find('.imagen').html();
		$(this).find('.imagen').remove();
		$(this).find('.texto').html($(this).find('p'));
		texto = $(this).find('.texto').html();
		$(this).find('.texto').remove();
		$(this).html("<div class=\"cada-equipo\"><div class=\"imagen\">" + imagen + "</div><div class=\"texto\">" + texto + "</div></div>");
	});
}
