window.addEvent('domready',function(){






var open_modal = $$('.open_modal');
var close_modal= $$('.close_modal');




var store_templates = [
						
						'abergele.html',
						'buckley.html',
						'colwynbay.html',
						'denbigh.html',
						'eastham.html',
						'flint.html',
						'gwersyllt.html',
						'heswall.html',
						'holywell.html',	
						'mold.html',	
						'moreton.html',	
						'neston.html',	
						'newferry.html',	
						'prenton.html',
						'westkirby.html',	
						'whitby.html',	

						];





var modal_container= $('modal_container');
var height = 600;
var width = 754;
//var flash = $('open_modal').getProperty('href');


function load_modal(index) {
	
	//alert(index);
	
	var overlay = $('overlay');
	var form_window = $('master_container');
	var x = new Chain();
	var one = function(){
	
var viewport = document.getElement('body').getScrollSize();

overlay.setStyles({
width: viewport.x,
height: viewport.y	
});

overlay.fade(0.6);

form_window.fade('in');
$('close_modal').fade('in');

var template = store_templates[index];

//console.debug(template);

var myHTMLRequest = new Request.HTML({
									 
									 url: template,
									 update: modal_container,
									 noCache: true,
									 evalScripts: true
									 
									 }).send();


modal_container.setStyle('display','block');



// this get's the flash objects with and height then applies it to animation




//figure out negative margin left based on width of movie

var nmargin = '-'+width/2+'px';
//console.debug(nmargin);

form_window.setStyle('margin-left', nmargin);

var myEffect = new Fx.Morph(form_window, {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
myEffect.start({
'height': [0, height], //Morphs the 'height' style from 10px to 100px.
'width': [0, width]  //Morphs the 'width' style from 900px to 300px.
});


		
}; // end function one




	x.chain(one);
	x.callChain();


}


function closemodal(){

	var overlay = $('overlay');
	var form_window = $('master_container');
	overlay.fade('out');
	form_window.fade('out');
	$('close_modal').fade('out');
	modal_container.setStyle('display','none');

}



// list events


open_modal.each(function(openbtn,i){
						 

openbtn.addEvent('click',function(e){
	e.stop();
	load_modal(i);

})

})



close_modal.addEvent('click',function(e){
	
	e.stop();
	closemodal();

})

// end list events




})// end domready
