var showPreview = function(name){
	if(toggle==name){closeContent();return;}
	if(!location.href.match("default.mspx")){
		location.href = "/optimization/default.mspx";
	}
	new Json.Remote("/optimization/xml/model/"+name+"Preview.js",{method:'get',onComplete:function(response){openPreview(response);}}).send();
	toggle=name;
}

var fx = false;
var container = false;
var modelImage = false;
var modelText = false;
var modelTitle = false;
var toggle = false;
var openPreview = function(response){
	if(!container){
		container = new Element('div',{'class':'modelPreview'}).setOpacity(0);
		modelTitle = new Element('h2').injectInside(container);
		modelImage = new Element('img').injectInside(container);
		modelText = new Element('p').injectInside(container);
		container.injectInside($('Content'));
		fx = container.effect('opacity',{wait:false});
		setContent(response);
	}else{
		setContent(response);
	}
}

var setContent = function(response){
	modelImage.src = response.image;
	modelText.innerHTML = response.text;
	modelTitle.innerHTML = response.title;
	fx.start(window.ie?.9:1);
}

var closeContent = function(){
	fx.start(0);
	toggle=false;
}