
//declaring a new class 'chestOfDrawers' (ladenkast)
function chestOfDrawers(){

this.frameRate=15;
this.speed=10;
this.begin=123;
this.end=-13;
this.pos=this.begin;

	this.moveUp = function(inst, id){
		if(this.act=='allowUp'){
		//sw.console("moveUp pos="+this.pos);
		$(".drawers #"+id+" .sub .cnt").css({"background-color":"#0074FD"});
			if(this.pos>this.end+this.speed){
			this.pos=this.pos-this.speed;
			$(".drawers #"+id+" .sub").css({"margin-top":""+this.pos+"px"});	
			var t=setTimeout(inst+".moveUp('"+inst+"','"+id+"')",this.frameRate);
			}
			else{
			//placing clip at end position
			this.pos=this.end;
			$(".drawers #"+id+" .sub").css({"margin-top":""+this.pos+"px"});
			}
		}
	}
	this.moveDown = function(inst, id){
		if(this.act=='allowDown'){
			if(this.pos<this.begin-this.speed){
			this.pos=this.pos+this.speed;
			$(".drawers #"+id+" .sub").css({"margin-top":""+this.pos+"px"});	
			var t=setTimeout(inst+".moveDown('"+inst+"','"+id+"')",this.frameRate);
			}
			else{
			//placing clip at begin position
			this.pos=this.begin;
			$(".drawers #"+id+" .sub").css({"margin-top":""+this.pos+"px"});
			$(".drawers #"+id+" .sub .cnt").css({"background-color":"#333333"});
			}
			
		}
	}
}

	$(document).ready(function() {				  
	var numOfInst = $('.drawers .bl').length;
							  
		//declaring instances on the fly
		for(i=1; i<=numOfInst; i++){
		window["instb"+i] = new chestOfDrawers();//window because of global scope
		}
	
		$('.drawers .bl').hover(
			// mouseover 
			 function(){
				var id= $(this).attr('id');
				eval("inst"+id).act='allowUp';
				eval("inst"+id).moveUp('inst'+id, id);	
			 },
			 // mouseout 
			 function(){
				var id= $(this).attr('id');
				eval("inst"+id).act='allowDown';
				eval("inst"+id).moveDown('inst'+id, id);
			 } 
		 );
		
		
		///
		$(".drawers .bl").bind("click", function() {
		var url=$(this).find("a").attr("href");
		sw.goto_url("",url,"");
		});

	});



