$(document).ready(function(){
		
	$("div.ckeditorDisplay p > a > img").parent().addClass("fancybox");
	//$("div.ckeditorDisplay img").addClass("borde");
	$("div.ckeditorDisplay img").each(function(){
		if ($(this).css('float') == 'left'){
			$(this).addClass("leftAndMargin");
		}else if ($(this).css('float') == 'right'){
			$(this).addClass("rightAndMargin");
		}else{
			var divWidth  = $(this).parents('div.ckeditorDisplay').width();
			if(divWidth<=$(this).width()){
				$(this).addClass("ajustar");
				$(this).removeAttr('style');//le quitamos el ancho y alto	
				//$(this).addClass("borde");
			}else{
				$(this).parent().addClass("center");
			}
		}
	});	
	
	$("a.fancybox").fancybox({'titlePosition'  : 'over'});
	
	$("a.fancybox img.ajustar").parent().addClass("ajustar");
	
	/*imageLink*/
	//$("a.fancybox img").addClass("imageLink");
	//$("div.galeria_enlace img").addClass("imageLink");

	$(".tabs").tab();
	$(".tabs-vertical").tab();

	$("li:last-child").addClass("last");
	$("li:first-child").addClass("first");
	
	//addStyleSheet("/css/jquery.fancybox-1.3.1.css");
	
});

$(window).load(function(){ 
	//hay que hacerlo aquí para que las imagenes esten cargadas también					
	//$(".equalHeights").equalHeights();					
})

function check_list(span_id){
	var ul = jQuery('#'+span_id).parentsUntil('ul').parent();
	var div = ul.parent();
	
	var contiene = false;
	ul.find('li').each(function() {
			var elem = $(this);
			var span = elem.find('span');
			if(span.html() != ''){
				contiene = true;
			}
	});	

	//alert(div.get(0).tagName);
	div.remove();
	
	if(!contiene){
		//div.remove();
		//div.html('borrar');
		
	}else{
		//div.html('borrar');
		//alert('no borrar');
	}
}

jQuery.fn.tab = function() {
	var div = jQuery(this);
	$(div).find(">div").hide().eq(0).show();
	$(div).find("ul li a").eq(0).addClass('selected');
	$(div).find("ul li a").click(function(){
		$(div).find("ul li a").removeClass('selected');
		$(this).addClass('selected');
		$(div).find(">div").hide();
		$($(this).attr('href')).show();
		return false;
	});
}

function addStyleSheet(stylesheet){
	
	$('<link rel="stylesheet" type="text/css" href="'+stylesheet+'" >').appendTo("head");//falla en ie8
	
	

/*
	var fileref=document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", stylesheet);
	if (typeof fileref!="undefined"){
		document.getElementsByTagName("head")[0].appendChild(fileref);
	}*/

}

function writeFB(){//escribimos el tag para mostrar el widget de facebook, ya que si no, no valida el xhtml
	document.write('<fb:fan profile_id="37299811035" stream="1" connections="4" width="255" height="470" css="http://www.xxxxxxxxxxxxxx.com/css/facebook.css"></fb:fan>');	
}
