// JavaScript Document
//Author:Khanh Huy at khanhhuyan@yahoo.com
//Created date:February, 11 2009
//For mootools based effects

var nextScrollEffect=1;

function scroll_content(mode) {
	if (!nextScrollEffect)
		return;
		
	imgHeight=$('content1').getSize().y;
	
	mainFrameHeight=$('rightmain').getSize().y;
	
	topNavHeight=$('top_scrollContainer').getSize().y;
	
	bottomNavHeight=$('bottom_scrollContainer').getSize().y;
	
	displayFrameHeight=mainFrameHeight-topNavHeight-bottomNavHeight;
	
	containerHeight=$('hasten-container').getSize().y;
	
	limitMarginTop=displayFrameHeight-containerHeight;

	marginTop=$('hasten-container').getStyle('margin-top').toInt();

	
	switch (mode) {
		case 'up':
			newMarginTop=(marginTop-imgHeight);	
			
			if (limitMarginTop > newMarginTop)
				newMarginTop=limitMarginTop;
			
			var myFxTween=new Fx.Tween('hasten-container',{
								fps:200,
								link:'igore',
								duration:400,
								transition:"quart:in",
								onStart:function() {
									nextScrollEffect=0;
								},
								onComplete:function() {
									nextScrollEffect=1;
								}
								
								});	
			myFxTween.start('margin-top',newMarginTop.toString()+"px");						
			
			
			break;
			
		case 'down':
		
			newMarginTop=(marginTop+imgHeight);	
			
			if (newMarginTop > 0)
				newMarginTop=0;
				
			var myFxTween=new Fx.Tween('hasten-container',{
								fps:200,
								link:'igore',
								duration:500,
								transition:"quart:in",
								onStart:function() {
									nextScrollEffect=0;
								},
								onComplete:function() {
									nextScrollEffect=1;
								}
								});	
			myFxTween.start('margin-top',newMarginTop.toString()+"px");			
			
			break;
			
		default:
		
			break;		
	}
}
function hast_slideIn() {
	
	this.setStyle('left',0);
	//targetLeft=this.getSize().x;
	targetLeft=230;
	myFx=new Fx.Tween(this,
			{mode:'horizontal',
			 fps:200,
			 duration:500,
			 transition:"expo:out"
			 
			});
	this.setStyle('visibility', 'visible');		
	myFx.start('left',0,targetLeft+"px");
	
}
function hast_slideOut() {

	this.setStyles({
				  visibility:'hidden',
				  left     :0
				  });
	
}

window.addEvent('domready',function(){

	$$('#hasten-container div.hast_img').each(function(item){
		descriptionElement=item.getNext('div');	
		item.addEvent('mouseover',hast_slideIn.bind(descriptionElement));
		item.addEvent('mouseout',hast_slideOut.bind(descriptionElement));
	});
	
	
	document.addEvent('mousewheel',function(event){
											
		event.preventDefault();	
		
		if (event.wheel > 0)
			scroll_content('down');
		else
			scroll_content('up');	
		
	});
	
	$('top_scrollButton').addEvent('click',function(){
		scroll_content('down');
		
	});
	
	$('bottom_scrollButton').addEvent('click',function(){
		scroll_content('up');
	
	});
	
});