/*
	*spliurl = document.URL.split('/');
	*var APP_URL = spliurl[0]+"/"+spliurl[1]+"/"+spliurl[2]+"/";
*/
jQuery.noConflict();

jQuery(document).ready(function() {
	
	jQuery('a[class*=facebook_listado]').live('click', function(e) {
		e.stopPropagation();

		var title = $(this).parent().parent().parent().children("p").children("a").text();
		var body = $(this).parent().parent().parent().children("p").text();
		var cliente = $(this).parent().parent().parent().children("a").text();
		var imagen = $(this).parent().parent().parent().children("a").children("img").attr("src");
		
//		alert(imagen);
//		alert(title);
//		alert(body.substr(title.length+4));
		
		$('meta[name=title]').attr('content',title + ' (' + $.trim(cliente) + ') - edencomunicacion.com');
		$('meta[name=description]').attr('content',body.substr(title.length+4));
		$('link[rel=image_src]').attr('href', imagen);
		
//		alert($('meta[name=title]').attr('content'));
//		alert($('meta[name=description]').attr('content'));
//		alert($('link[rel=image_src]').attr('href'));
	});

	jQuery('a[class*=twitter_url]').live('click', function() {
		
		var url 		= jQuery(this).attr('twitter');
		var urlFinal 	= 'http://api.bitly.com/v3/shorten?login=zurbit&apiKey=R_2f72ae875f2445c8572a02f5619ae2b9&longUrl='+url+'&format=json';
		var titulo 		= jQuery(this).attr('titulo');
		
		jQuery.ajax({
				url			: urlFinal,
				type		:'get',
				dataType	:'json',
				data		:{},
				success		:function (data, textStatus, XMLHttpRequest) {
				
					if (data.status_txt == 'OK') {
					
						window.open('http://twitter.com?status=Leyendo ' + titulo + ' – ' + data.data.url + ' vía @eden_com');

					}
					else {

						window.open('http://twitter.com?status=Leyendo ' + titulo + ' – ' + url + ' vía @eden_com');
					}
				}
		});

	});
		
	/*
	DOC: En la carga de la pagina se realizan las siguientes acciones:
	*/

/*
	jQuery('img').each(function(elem){
		jQuery(this).attr('longdesc',jQuery(this).attr('src'));
		jQuery(this).attr('src',APP_URL+'img/1pxtrans.gif');
		jQuery(this).addClass('img-ondemand');
	});
*/

	//Calculo cada vez que redimensione
	jQuery( window ).resize(function(){
		onWindowResize();
	});
	//Llamo a la funcion la primera vez en la carga
	new onWindowResize();

	/**Acepto las condiciones de uso - checkbox**/
	jQuery(".field_acepto1").bind("change", function(){
		if(jQuery(".field_acepto1").attr('checked')){
			jQuery(".field_acepto_label1").addClass('checked');
		}else{
			jQuery(".field_acepto_label1").removeClass('checked');
		}
	});
	jQuery(".field_acepto2").bind("change", function(){
		if(jQuery(".field_acepto2").attr('checked')){
			jQuery(".field_acepto_label2").addClass('checked');
		}else{
			jQuery(".field_acepto_label2").removeClass('checked');
		}
	});
	jQuery(".field_acepto3").bind("change", function(){
		if(jQuery(".field_acepto3").attr('checked')){
			jQuery(".field_acepto_label3").addClass('checked');
		}else{
			jQuery(".field_acepto_label3").removeClass('checked');
		}
	});
	jQuery(".field_acepto4").bind("change", function(){
		if(jQuery(".field_acepto4").attr('checked')){
			jQuery(".field_acepto_label4").addClass('checked');
		}else{
			jQuery(".field_acepto_label4").removeClass('checked');
		}
	});
	
	//Carga de eventos pasados
	jQuery('#eventos_pasados > a').live('click', function(eve){
		eve.preventDefault();
		
		var link = jQuery(this).attr("href");
		
		var link_split= link.split("/");
		
		var page = link_split[link_split.length-1];
		
		jQuery(this).parent().hide();
		
		$.ajax({
			url: link,
			type: "GET",
			dataType: "html",
			beforeSend: function(){
//				showBusy(page);
			},	
		  	success: function(html) {
		    	updatePasados(html,page);
		 	}
		});	

	});	
	
	//Carga de eventos proximos
	jQuery('#mas_proximos_eventos > a').live('click', function(eve){
		eve.preventDefault();
		
		var link = jQuery(this).attr("href");
		
		var link_split= link.split("/");
		
		var page = link_split[link_split.length-1];
		
		jQuery(this).parent().hide();
		
		$.ajax({
			url: link,
			type: "GET",
			dataType: "html",
			beforeSend: function(){
//				showBusy(page);
			},	
		  	success: function(html) {
		    	updateProximos(html,page);
		 	}
		});	

	});	

	//Carga de tweets pasados
	jQuery('.barra_ver_mas > a').live('click', function(eve){
		eve.preventDefault();
		
		var link = jQuery(this).attr("href");
		
		var link_split= link.split("/");
		
		var page = link_split[link_split.length-1];
				
		jQuery(this).parent().hide();
		
		$.ajax({
			url: link,
			type: "GET",
			dataType: "html",
			beforeSend: function(){
//				showBusy(page);
			},	
		  	success: function(html) {
		    	updatePasados(html,page);
		 	}
		});	

	});	
	
});


function showBusy(page){
	$('#mostrarPasados'+page).block({
		message: '<h1>Processing</h1>',
		css: {border:'3px solid #000'}
	});
}

function updatePasados(html,page){
	
	var mostrar = $(html).find("#mostrarPasados");
	$('#mostrarPasados'+page).html(mostrar);
//	window.setTimeout( function(){
//		
//	}, 500);
	
	
}

function updateProximos(html,page){
	
	var mostrar = $(html).find("#mostrarProximos");
	$('#mostrarProximos'+page).html(mostrar);
//	window.setTimeout( function(){
//		
//	}, 500);
	
	
}




function onWindowResize(){
	//Cuento los altos de todos los elementos
	var altototal=0;
	var altototal_contenedor_web=jQuery('#contenedor_web').innerHeight();
	var altototal_cabecera_top=jQuery('#cabecera_top').innerHeight();
	var altototal_publicidadtop_content=jQuery('#publicidadtop_content').innerHeight();
	var altototal_contenedor_pie=jQuery('#contenedor_pie').innerHeight();
	altototal+=altototal_contenedor_web;
	altototal+=altototal_cabecera_top;
	altototal+=altototal_publicidadtop_content;
	altototal+=altototal_contenedor_pie;

	//calculo el alto disponible de la ventana
	var w = jQuery( window );
	myvarw = w.width(); // window.innerWidth;
	myvarh = w.height(); // window.innerHeight;

	/*
	console.log( 'myvarw: ' + myvarw );
	console.log( 'myvarh: ' + myvarh );
	console.log( 'altototal_contenedor_web: ' + altototal_contenedor_web );
	console.log( 'altototal_cabecera_top: ' + altototal_cabecera_top );
	console.log( 'altototal_publicidadtop_content: ' + altototal_publicidadtop_content );
	console.log( 'altototal_contenedor_pie: ' + altototal_contenedor_pie );
	console.log( 'altototal: ' + altototal );
	*/

	//Si el alto de la ventana es mayor que el del conjunto de los elementos, le anhado la clase que me lleva el pie abajo
	if(altototal>myvarh){
		jQuery('#contenedor_pie').removeClass('fullbottom');
	}else{
		jQuery('#contenedor_pie').addClass('fullbottom');
	}
}

function getFlashMovieObject(movieName)
{
	if (window.document[movieName])
	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName];
	}
	else
	{
		return document.getElementById(movieName);
	}
}


/**Funcion para el menu de productos**/
function menu_productos(){
	jQuery('.menu_productos').toggle('fast');
	jQuery('.item_menu_productos').toggleClass('item_menu_productos_activo');
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
	}
	function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
	}
	function PNG_loader() {
		   for(var i=0; i<document.images.length; i++) {
		      var img = document.images[i];
		      var imgName = img.src.toUpperCase();
		      if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
		         var imgID = (img.id) ? "id='" + img.id + "' " : "";
		         var imgClass = (img.className) ? "class='" + img.className + "' " : "";
		         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
		         var imgStyle = "display:inline-block;" + img.style.cssText;
		         if (img.align == "left") imgStyle += "float:left;";
		         if (img.align == "right") imgStyle += "float:right;";
		         if (img.parentElement.href) imgStyle += "cursor:hand;";
		         var strNewHTML = "<span " + imgID + imgClass + imgTitle
		            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
		         img.outerHTML = strNewHTML;
		         i--;
		      }
		   }
		}
		
		if(window.attachEvent)
			window.attachEvent("onload", PNG_loader);


function mostrar(capa){ 
	var obj = document.getElementById(capa) 
	if(obj.style.display == "block") obj.style.display = "none" 
	else obj.style.display = "block" 
	}
	

// JavaScript Document

    //jQuery.noConflict();
     
	var $jQ = jQuery.noConflict();
    // Use jQuery via $j(...)
    $jQ(document).ready(function(){
     	//$jQ("div").hide();
		
		/*NOSIRVE ESTO ES PARA EL JEDIT QUE NO SE UTILIZA
		$jQ("#contenido_web").editable("save.php", { 
			indicator : "<img src='img/indicator.gif'>",
			loadurl   : "http://www.appelsiini.net/projects/jeditable/php/load.php",
			type      : "textarea",
			submit    : "OK",
			cancel    : "Cancel",
			tooltip   : "Click to edit..."
		});
		*/
  
    });
     
    // Use Prototype with $(...), etc.

function loadTooltip()
{
	jQuery.extend($jQ.fn.Tooltip.defaults, {
		track: true,
		delay: 2,
		showURL: false,
		showBody: " - "
	});
	jQuery('#galerias_detalle .fotografias_listado_item_mosca a').Tooltip();
}

/* Si se lo pongo da error el carrusel. Pero si no se lo dejo lo llama el subir archivos. Adem�s creo que lo necesita para el cargando. 
$jQ(function() {
	// modify global settings
	$jQ.extend($jQ.fn.Tooltip.defaults, {
		track: true,
		delay: 2,
		showURL: false,
		showBody: " - "
	});
	$jQ('#galerias_detalle .fotografias_listado_item_mosca a').Tooltip();
});
*/
