


function modalDialog(elem){
	//alert ("entro a modal()");
	var t = elem.title || elem.name || null;
	var a = elem.href || elem.alt;
	var g = elem.rel || false;
//alert(this.href);
	layerDrag(t,a,g);
	
	

	//this.blur();
	return false;
}



function layerDrag(caption, url, imageGroup) {
	//alert("ar url:"+url);
	try {
		
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("DL_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='DL_HideSelect'></iframe><div id='DL_overlay'></div><div id='DL_modal'></div>");
				$("#DL_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("DL_overlay") === null){
				$("body").append("<div id='DL_overlay'></div><div id='DL_modal'></div>");
				$("#DL_overlay").click(tb_remove);
			}
		}
		
		/*
		if(tb_detectMacXFF()){
			$("#DL_overlay").addClass("DL_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#DL_overlay").addClass("DL_background");//use background and opacity
		}
		*/

		$("#DL_overlay").addClass("DL_background");//use background and opacity
		$("body").append("<div id='loader'><img src='/imgs/layout/modal-loader2.gif' /></div>");//add loader to the page
		$('#loader').show();//show loader

		// Mostramos la ventana de una, para que los script en el ready dentro corran correctamente
		$("#DL_modal").show();






		var queryString = url.replace(/^[^\?]+\??/,'');
		var params = tb_parseQuery( queryString );

		if(params['width']=='window'){
			var w = jQuery(window).width();
			TB_WIDTH = w - 30;
		}else{
			TB_WIDTH = (params['width']*1) + 30 || 420; //defaults to 630 if no paramaters were added to URL
		}

		if(params['height']=='window'){
			var h = jQuery(window).height();
			TB_HEIGHT = h - 30;
		}else{
			TB_HEIGHT = (params['height']*1) + 40 || 360; //defaults to 440 if no paramaters were added to URL
		}
		


		ajaxContentW = TB_WIDTH - 30;
		ajaxContentH = TB_HEIGHT - 45;


			urlNoQuery = url.split('DL_');
			//alert(urlNoQuery);
			$("#DL_iframe").remove();

				//$("#DL_modal").append("<div id='DL_top'><p>"+caption+"</p><div id='DL_close'><a href='#' id='DL_closeButton' title='Close'><img src='/_ui/desktop/imgs/cerrar.gif' width='6' height='6' alt='cerrar' title='cerrar' /></a> </div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='DL_iframe' name='DL_iframe"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");

				$("#DL_modal").append("<div id='DL_top'><p>"+caption+"</p><div id='DL_close'><a href='#' id='DL_closeButton' title='Close'><img src='imgs/layout/botones/btnModalCerrar.gif' width='50' height='21' alt='cerrar' title='cerrar' /></a> </div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='DL_iframe' name='DL_iframe' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' scrolling='no' > </iframe>");

				$("#DL_modal").draggable({handle:'#DL_top'});
				//$("#DL_top p").disableSelection();





		$("#DL_closeButton").click(tb_remove);

		tb_position();
		if($.browser.safari){//safari needs help because it will not fire iframe onload
			$("#loader").remove();
			$("#DL_modal").css({display:"block"});
		}

		document.onkeyup = function(e){ 	
			if (e == null) { // ie
				keycode = event.keyCode;
			} else { // mozilla
				keycode = e.which;
			}
			if(keycode == 27){ // close
				tb_remove();
			}	
		}


	}
	catch(e){
		alert(e);
	}

}

function tb_showIframe(){
	$("#loader").remove();
	$("#DL_modal").css({display:"block"});

	/*
	var iframe = window.frames['DL_iframe'].document;
	$("div#slider1", iframe).slide()
	*/
}

function tb_remove() {

	$("#DL_closeButton").unbind("click");
	$("#DL_modal").fadeOut("fast",function(){$('#DL_modal,#DL_overlay,#DL_HideSelect').trigger("unload").unbind().remove();});
	$("#loader").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_showIframe(){
	$("#loader").remove();
	$("#DL_modal").css({display:"block"});
}

function tb_position() {
$("#DL_modal").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#DL_modal").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}


function getHeight(){

	var al = $(document).height();
	return al;
}


