$j(document).ready( function() {

	/* ## VIEWER ## */
	$j("#wrapper-viewer a.close").bind("click", function(e) {
	    e.preventDefault();
	    closeViewer();
	});

	$j(document).keyup(function(e) {
    	if (e.which == 27) { closeViewer(); }
    });
	// esta es una opción:
	// a:not([href*='javascript:']):not([href*='?lang']):not([href*='/wp-admin/']):not([href*='/wp-login.php']):not([href$='/feed/'])
	$j(".entry h4 a, a[rel=popup], a[href*='page_id'], a[href*='post'], a[href*='p=']").bind( "click", function(e) {
	    e.preventDefault();
	    scaleViewer();
		$j("#navmenu a").removeClass("navmenuselected");
		$j(this).addClass("navmenuselected");
	    target = $j(this).attr("href");
		loadIframe(target);
	});
	$j(window).bind( "resize", function() {
    	scaleViewer();
	});
	if (window.location.href.indexOf("page_id") > 0) {
		var iURL = "/?" + window.location.href.substring(window.location.href.indexOf("page_id"));

		 
		if (window.location.href.indexOf("lang=it")>0) {
			re = /lang=..(\&)/g;
			iURL = iURL.replace(re, "&");
			re = /(\&)lang=../g;
			iURL = iURL.replace(re, "");
			re = /lang=../g;
			iURL = iURL.replace(re, "");

			iURL+="&lang=it";
		} 
		loadIframe(iURL);
	}
	scaleViewer();
});
