function show_modal(){
	
	update_gray();
	
	
	var width = WindowUtilities.getPageSize().pageWidth;
	
	$('preview_area').style.left=((width/2)-350)+"px";

	$('disable').show();
	
	$('preview_area').show();
	
//	if($('header')){
//	 Effect.ScrollTo('header');
//	}
//	
//	if($('tray')){
//	 Effect.ScrollTo('tray');
//	}

	Event.observe(document, 'scroll', update_gray);
	
	Event.observe(document, 'keypress', function(event){ 
		if(event.keyCode == Event.KEY_ESC){
			 previewClose();
		}
	});
	 
	
}




function update_gray(){
	var width = WindowUtilities.getPageSize().pageWidth;
	var height = WindowUtilities.getPageSize().pageHeight;
	$('disable').style.height=height+"px";
	$('disable').style.width=width+"px";
	
}

function close_modal(){
	
	Event.stopObserving(document, 'scroll', update_gray);
	Event.stopObserving(document, 'keypress');
	$('disable').style.height="0px";
	$('disable').style.width="0px";
	$('disable').show();
}


var WindowUtilities = {  
  getPageSize: function(parent){
    parent = parent || document.body;              
    var windowWidth, windowHeight;
    var pageHeight, pageWidth;
  
      var xScroll, yScroll;

      if (window.innerHeight && window.scrollMaxY) {  
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
      } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
      } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
      }


      if (self.innerHeight) {  // all except Explorer
        windowWidth = self.innerWidth-20;
        windowHeight = self.innerHeight;
      } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
      } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
      }  

      // for small pages with total height less then height of the viewport
      if(yScroll < windowHeight){
        pageHeight = windowHeight;
      } else { 
        pageHeight = yScroll;
      }

      // for small pages with total width less then width of the viewport
      if(xScroll < windowWidth){  
        pageWidth = windowWidth;
      } else {
        pageWidth = xScroll;
      }
                
    return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
  
  }  
}


function previewClose(){
	$('disable').hide();
	$('preview_area').hide();
	
	

//	$('preview_area').update('<img src="'+site_url+'images/agency/blue-loading.gif"> Loading...');


	close_modal();
	$('preview_area').style.height = "";
	return;
}

