
	var oController = Class.create({
		initialize:function(userID){
			this.instID = 'oController.' + parseInt(Math.random()*1000000);
			this.pageObjects = $H({});
			this.pageObjects.set(1, new page1($('orderPage1'), this));
			this.pageObjects.set(2, new page2($('orderPage2'), this));
			this.pageObjects.set(3, new page3($('orderPage3'), this));
			this.pageObjects.set(4, new page4($('orderPage4'), this));
			this.pageObjects.set(5, new page5($('orderPage5'), this));
			this.pageObjects.set(6, new page6($('orderPage6'), this));
			this.pageObjects.set(7, new page7($('orderPage7'), this));
			this.pageObjects.set(8, new page8($('orderPage8'), this));
			this.pageObjects.set(9, new page9($('orderPage9'), this));
			this.pageObjects.set(10, new page10($('orderPage10'), this));
			this.orderID = 0;
			this.userID = userID;
		},

		cancelOrder : function(orderID, pageIndex){
			if (confirm('Weet je zeker dat je deze bestelling wilt annuleren?')){
				this.currPage = 1;
				var wpsRPC = new wps.rpc;
				wpsRPC.debug=true;
				wpsRPC.createCall('order', function(){
					window.location.href = "http://" + window.location.hostname + "/Je Bestelling/";
				});
				wpsRPC.call('cancelOrder', 'orderID='+orderID);				
			}
		},
		
		resumeOrder : function(orderID, pageIndex){
			if (pageIndex == 0) pageIndex = 1;
			this.orderID= orderID;
			this.pageIdx = pageIndex;
			this.loadData();
		},
		
		loadData : function(){
			var wpsRPC = new wps.rpc;
			wpsRPC.debug=true;
			wpsRPC.createCall('order', this.setData.bind(this));
			wpsRPC.call('getOrderJSON', 'orderID='+this.orderID);
		},
		
		setData : function(req){
			this.orderData = req.responseJSON;
			
			this.drawPage();
		},
		
		newOrder : function(productID, userID){
			this.userID = userID;
			this.productID = productID;
			this.pageIdx = 1;
			this.drawPage();
		},
		
		drawPage : function(){
			$('orders').hide();
			$('orderContainer').show();
			this.pageObjects.values().each(
				function(obj){
					obj.hidePage();
				}
			)
			this.currPage = this.pageObjects.get(this.pageIdx);
			this.currPage.showPage();
			this.currPage.start();
		},
		
		next : function(){
			if (this.currPage.validate()){
				if (this.pageIdx == 6) this.pageIdx++; // disable to enable page5
				this.pageIdx++;
				this.currPage.save( this.drawPage.bind(this) )
			}
			
		},

		previous : function(){
			if (this.pageIdx == 8) this.pageIdx--; // disable to enable page5
			this.pageIdx--;
			this.drawPage();
		},
		
		overboeking : function(){
			window.location.href = "http://"+window.location.hostname+"/pickupOrder.php?orderID=" + this.orderID + "&action=overboeking";
		}

		
	})
