// inicialización
var buscarBaseURL = "http://www.derecho.com/buscar/";
jQuery(document).ready( function() {
	
	if ( jQuery('#rowContent3 .cabecera h2').length > 0 ) {
		if ( jQuery('#rowContent3').height() > jQuery('#rowRelated3').height() ){
		    jQuery('#rowRelated3').css('height', jQuery('#rowContent3').height() );
		}		
	}
	
	jQuery('#faq p').click(function(){
		jQuery('#faq span').hide();
		jQuery(this).next('span').show();
	});

	lastBlock = jQuery("#accordion_last");

	jQuery("#banner_accordion ul li a").hover( function() {
		jQuery(lastBlock).animate( {
			width : 60 + "px"
		}, {
			queue : false,
			duration : 400
		});
		jQuery(this).animate( {
			width : 860 + "px"
		}, {
			queue : false,
			duration : 400
		});
		lastBlock = this;
	});

	// simil accordion
		jQuery("#menuCategorias a.handler").each( function() {
			jQuery(this).click( function() {
				jQuery("#" + this.id).parent().children("ul").slideToggle();
				return false;
			});
		});
		jQuery(".this_editor p a").click( function() {
			if (!jQuery("#editor_list").hasClass("hide")) {
				jQuery("#editor_list").slideUp();
				jQuery("#editor_list").addClass("hide");
				jQuery("#editor_list").css("color", "");
			} else {
				jQuery("#editor_list").slideDown();
				jQuery("#editor_list").removeClass("hide");
				jQuery("#editor_list").css("color", "blue");
			}
		});

		jQuery("#hoy_cab").html((new Date()).toLocaleDateString());
		// jQuery("#label_q").html('');
		if ((jQuery("#origen").attr("value") != null)
				&& (jQuery("#origen").attr("value") != "")
				&& (jQuery("#" + jQuery("#origen").attr("value")).size() > 0)) {
			jQuery("#" + jQuery("#searchIn").attr("value")).removeClass(
					"selected");
			jQuery("#" + jQuery("#origen").attr("value")).addClass("selected");
			jQuery("#searchIn").attr("value", jQuery("#origen").attr("value"));
			jQuery("#search").attr("action",
					buscarBaseURL + jQuery("#origen").attr("value"));
		}
		jQuery("#search_mas").click( function() {
			jQuery("#menuMore").toggle();
		});
		jQuery("#cerrarMenuMore").click( function() {
			jQuery("#menuMore").toggle();
		});
		jQuery("div#mainMenu ul li").hover( function() {
			jQuery("ul", this).fadeIn(200);
		}, function() {
		});
		if (document.all) {
			jQuery("div#mainMenu ul li").hoverClass('hoverMenu');
		}
		jQuery("#searchMenu a").click(
				function() {
					if ((this.id.indexOf("More") == -1)
							&& (this.id.indexOf("_") == -1)
							&& jQuery("#searchIn").attr("value") != this.id) {
						jQuery(this).addClass("selected");
						jQuery("#" + jQuery("#searchIn").attr("value"))
								.removeClass("selected");
						jQuery("#searchIn").attr("value", this.id);
						jQuery("#search").attr("action",
								buscarBaseURL + this.id);
						jQuery("#menuMore").hide();
					}
				});
		var ct = jQuery("meta[http-equiv='Content-Type']");
		var IEct = jQuery("meta[httpEquiv='Content-Type']");
		if (IEct.length == 1) {
			ct = IEct;

		}
		if (ct.attr("content").toLowerCase().indexOf("utf-8") != -1) {
			jQuery("#form-encoding").val("UTF-8");
			jQuery("#ie").val("UTF-8");
		}
		jQuery("#mostrar_ficha").click( function() {
			if (jQuery(this).html() == 'Mostrar ficha') {
				jQuery("#ficha").slideDown();
				jQuery(this).addClass("ocultar");
				jQuery(this).html('Ocultar ficha');
			} else {
				jQuery("#ficha").slideUp();
				jQuery(this).removeClass("ocultar");
				jQuery(this).html('Mostrar ficha');
			}
		});
		jQuery("#mostrar_indice").click( function() {
			if (!jQuery(this).hasClass("ocultar")) {
				jQuery("#indice").slideDown("normal", doSeparator);
				jQuery(this).addClass("ocultar");
				jQuery(this).html('Ocultar Índice');
			} else {
				jQuery("#indice").slideUp("normal", doSeparator);
				jQuery(this).removeClass("ocultar");
				jQuery(this).html('Mostrar Índice');
			}
		});
		doSeparator();
		for ( var i = 1; i <= 5; i++) {
			try {
				if (typeof (window["onload_" + i]) != 'undefined') {
					eval("onload_" + i + "()");
				}
			} catch (e) {
			}
		}
	});
function doSeparator() {
	var indice = jQuery("#indice");
	var rowRelated = jQuery("#rowRelated");
	var bIndice = indice.length == 0 ? 0 : indice[0].offsetHeight
			+ findPos(indice[0])[1];
	var bRowRelated = rowRelated.length == 0 ? 0 : rowRelated[0].offsetHeight
			+ findPos(rowRelated[0])[1];
	if (bIndice >= bRowRelated) {
		jQuery("#indice_sep").removeClass("hide");
	} else {
		jQuery("#indice_sep").addClass("hide");
	}
}

//funcion del menu
jQuery.fn.hoverClass = function(c) {
	return this.each( function() {
		jQuery(this).hover( function() {
			jQuery(this).addClass(c);
		}, function() {
			jQuery(this).removeClass(c);
		});
	});
};

function popUp(url, nombre, alto, ancho) {
	window.open(url, "", "height = " + alto + " , width=" + ancho);
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [ curleft, curtop ];
}

