var bobThirdEye = {
	
	optBackdrop: { 'background':'#000000' },
	optViewer: { 'background':'#4f5125','border':'2px solid #4f5125' },

	open: function(url) {
		//. translucent background over entire page.
		jQuery('<div id="opsat-te-backdrop" class="opsat-te-ele"></div>')
			.css({
				'position':'fixed',
				'top':'0px','left':'0px',
				'z-index':'6000',
				'width':'100%','height':'100%',
				'opacity':'0.0',
				'background':bobThirdEye.optBackdrop.background,
				'padding':'0px'
			})
			.appendTo('body');

		//. backdroper for iframe.
		var cx = Math.floor(jQuery(window).width() / 2);
		var cy = Math.floor(jQuery(window).height() / 2);
		jQuery('<div id="opsat-te-framecontain" class="opsat-te-ele"></div>')
			.css({
				'border':'0px solid red',
				'position':'fixed','top':cy+'px','bottom':(cy-1)+'px','left':cx+'px','right':(cx-1)+'px',
				'z-index':'6010',
				'display':'none'
		})
			.appendTo('body');
			
		//. close button.
		jQuery('<img id="opsat-te-close" src="/wp-content/themes/opsat/gfx/te-close.png" class="opsat-te-ele" alt="" />')
			.css({
				'position':'fixed',
				'top':'30px','right':'26px',
				'z-index':'6020','display':'none',
				'cursor':'pointer'
			})
			.bind('click',function(){bobThirdEye.close(false);})
			.appendTo('body');

		//. close-n-reload button.
		jQuery('<img id="opsat-te-close-reload" src="/wp-content/themes/opsat/gfx/te-close-reload.png" class="opsat-te-ele" alt="" />')
			.css({
				'position':'fixed',
				'top':'52px','right':'26px',
				'z-index':'6020','display':'none',
				'cursor':'pointer'
			})
			.bind('click',function(){bobThirdEye.close(true);})
			.appendTo('body');
		
		//. iframe.
		jQuery('<iframe id="opsat-te-iframe" frameborder="0" />')
			.css({
				'width':'100%','height':'100%',
				'border':bobThirdEye.optViewer.border,
				'background':bobThirdEye.optViewer.background
			})
			.appendTo('#opsat-te-framecontain');
		
		//. rendering.
		jQuery('#opsat-te-backdrop')
			.animate({'opacity':'0.7'},500,'easeOutCubic')
			.queue(function(){
				jQuery(this).dequeue();
				jQuery('#opsat-te-framecontain')
				.fadeIn()
				.animate({'top':'42px','bottom':'42px','left':'42px','right':'42px'},500,'easeOutBack')
				.queue(function(){
//					jQuery(this)
//					.dequeue()
//					.animate({'left':'42px','right':'42px'},300,'easeOutCubic')
//					.queue(function(){
						jQuery(this).dequeue();
						jQuery('#opsat-te-close, #opsat-te-close-reload').fadeIn();
						jQuery(this).find('iframe').attr('src',url);
//					});
				});
			});
	
		return;
	},
	
	close: function(shouldRefresh) {
		if(!shouldRefresh) shouldRefresh = false;

		var cx = Math.floor(jQuery(window).width() / 2);
		var cy = Math.floor(jQuery(window).height() / 2) ;
		jQuery('#opsat-te-close,#opsat-te-close-reload').fadeOut('fast').queue(function(){
			jQuery(this).dequeue();
			jQuery('#opsat-te-framecontain')
			.animate({'top':cy+'px','bottom':(cy-1)+'px'},250,'easeOutCubic')
			.queue(function(){
				jQuery(this)
				.dequeue()
				.animate({'left':cx+'px','right':(cx-1)+'px'},250,'easeOutCubic')
				.queue(function(){
					jQuery(this).dequeue().remove();
					jQuery('#opsat-te-backdrop').fadeOut('fast').queue(function(){
						jQuery(this).dequeue();
						jQuery('#opsat-te-backdrop,#opsat-te-framecontain,#opsat-te-close,#opsat-te-close-reload').remove();
						if(shouldRefresh) location.reload(true);
					});
				});
			});
		});

	
		return;
	},
	
	onLinkClick: function(e) {
		bobThirdEye.open(jQuery(this).attr('href'));
		e.stopPropagation();
		return false;
	}
}

//. latch onto any links that have the third eye class, and we will
//. make them open the third eye instead of doing their normal tasks.
jQuery(document).ready(function(){
	jQuery('a.third-eye').live('click',bobThirdEye.onLinkClick);
});

