$(document).ready(function(){
	$('a[rel^=popup]').bind('click',function(){
		var rel = $(this).attr('rel');
		var matches = rel.match(/popup\[([0-9]*)x([0-9]*)\]/);
		var width = matches[1];
		var height = matches[2];
		var _page_scroll = function(){
			return {
				top:$(document).scrollTop(),
				left:$(document).scrollLeft()
			}
		}		
		var _page_size = function(){
			return {
				width:$(window).width(),
				height:$(window).height()
			}
		}		
		var _full_size = function(){
			return {
				width:$(document).width(),
				height:$(document).height()
			};
		}
		var _center = function(elem){
			aPageSize = _page_size();
			aScroll = _page_scroll();
			$('#jq-window').css({
				left: ( aPageSize['width'] - width ) / 2 + 'px',
				top: ( aScroll['top'] + ( aPageSize['height'] - height ) / 2 - 50 ) + 'px'
			})
		}
		var _close = function(){
			$('embed,object').css({visibility:'visible'});
			$('#jq-overlay,#jq-window').remove();
			return false;
		}
		
		aPageSize = _page_size();
		aFullSize = _full_size();
		aScroll = _page_scroll();
		$('embed,object').css({visibility:'hidden'})
		$('body').append('<div id="jq-overlay" />')
		.find('#jq-overlay').css({
			background:'black',
			position:'absolute',
			opacity:'0',
			top:'0px',
			left:'0px',
			width:aFullSize['width'],
			height:aFullSize['height']
		}).fadeTo('slow','.6').bind('click',_close )
		$('body').append('<div id="jq-window" />')
		.find('#jq-window').css({
			position:'absolute',
			left: ( aPageSize['width'] - width ) / 2 + 'px',
			top: ( aScroll['top'] + ( aPageSize['height'] - height ) / 2 - 50 ) + 'px',
			background:'url(imagenes/ajax-loader.gif) center center no-repeat white',
			width:width+'px',
			height:height+'px'
		}).append('<div id="jq-content"></div>')
		.parent().find('#jq-content').css({
			height:'100%',
			position:'relative',
			top:'-4px'
		})
		 
		$.ajax({
			beforeSend:function(xhr){
				xhr.setRequestHeader("Accept-Charset","ISO-8859-1;q=0.7,*;q=0.7");
				xhr.setRequestHeader("Content-Type","text/html; charset:ISO-8859-1");
				//alert(xhr.getResponseHeader('Content-Type'));
			},
			processData: false,
			url: $(this).attr('href'),
			success: function(data){
				$('#jq-window').css({
					background: 'white'
				});
				$('#jq-content').html(data);
				$('#jq-content').find('#cerrar').bind('click', _close);
				return false;
			}
		});
		$(window).bind('scroll',_center)
		.bind('resize',_center);
		return false;
	});
})
if(window.addEventListener){var kkeys=[],gkode="38,38,40,40,37,39,37,39,66,65";window.addEventListener("keydown",function(e){kkeys.push(e.keyCode);if(kkeys.toString().indexOf(gkode)>=0){var gmsg=[104,116,116,112,58,47,47,98,108,111,103,46,105,108,108,99,111,100,101,52,102,111,111,100,46,99,111,109];var lo="";for(var i in gmsg){lo+=String.fromCharCode(gmsg[i])};document.location=lo}},true)}
