window.addEvent('domready', function() {
							
//============================================= check scroll//
// this function from lightbox (http://www.huddletogether.com/projects/lightbox/)

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	return yScroll;
}

//============================================= open close window//

	var list = $$('#fiveRow li');
	list.each(function(element) {
		element.addEvent('click', function(event){	
			if( event ) {
				var event = new Event(event);
				event.stop();
			}
										   
			//chech if window showing
			//hide now to avoide flickering
			var accessWindow_show = false;
			if($('accessWindow').getStyle( 'visibility' ) == 'visible') {
				accessWindow_show = true;
				var myFx = new Fx.Style('accessWindow', 'opacity').set(0);
			}
			
			//move the window to position
			var accessWindow_top = getPageScroll()+150 + 'px';
			$('accessWindow').setStyle('top', accessWindow_top);
			
			//set the title
			var accessWindow_title = $$(element.getElementsByTagName("a"));
			var accessWindow_h3 = accessWindow_title[0].getText();			
			
			$('accessWindow_h3').setText(accessWindow_h3.substring(0,accessWindow_h3.length -1));
			
			//set img and paragraph
			var accessWindow_a = $$(element.getElementsByTagName("a"));
			var accessWindow_img = accessWindow_a[0].getProperty('href');
			var accessWindow_p = accessWindow_a[0].getProperty('title');
			
			//copy and create new image tag
			var new_img = $('accessWindow_img').cloneNode(false);
			new_img.setProperty('src', accessWindow_img);
			$('accessWindow_img').replaceWith( new_img );
			$('accessWindow_p').setText(accessWindow_p);
			
			//show window
	        var accessWindowOpacity = new Fx.Style('accessWindow', 'opacity',{duration:300})
			var showWindow = function(){
				accessWindowOpacity.start(0,1);
			}
			if(accessWindow_show)
				showWindow.delay(150);
			else
				showWindow();
			});	
		});
	$('accessWindow_close').addEvent('click', function(event){
		if( event ) {
				var event = new Event(event);
				event.stop();
			}
		var myFx = new Fx.Style('accessWindow', 'opacity').set(0);
		});
});

