function Ship(){
	
	var galleryOpen = false;
	var shipDetailOpen = false;	
	var cabinsAndSuitsOpen = false;	
	var equipmentOpen = false;	
	var shipSections = new Array();
	var shipSectionsImages = new Array();
	var currentShipKey = false;
	var timer = new Object();
	
    this.init = function(){
    	if(dojo.byId('characteristics')) {
			dojo.style("characteristics","opacity","0");
			dojo.style("cabinsAndSuits","opacity","0");
			dojo.style("equipment","opacity","0");
			window.setTimeout("ship.showGallery()", 500);
			
			if (shipSections == 0) {
			}
			else {
				timer = window.setTimeout("ship.hideGallery()", 4000);
			}
			
			if(shipSections.length > 0)
			self.showByKey(0);
    	}
    	
    	dojo.style("sectionHolder","visibility","visible");
    	
    }
    
    this.test = function() {
    	alert(shipSectionsImages[0].src)
    }
    
    this.stopTimer = function() {
		window.clearTimeout(timer);
    }
	
	this.showSectionNo = function(key) {
		sectionNo = (key + 1) + " / " + shipSections.length;
		//dojo.byId('sectionNo').innerHTML = sectionNo;
	}
	
	this.showPreviousSection = function(){
		if(currentShipKey == 0){
			self.showByKey(shipSections.length - 1);
		}
		else {
			self.showByKey(currentShipKey - 1);
		}
	}
	
	this.showNextSection = function(){
		if(currentShipKey == shipSections.length - 1){
			self.showByKey(0);
		}
		else {
			self.showByKey(currentShipKey + 1);
		}
	}
	
	this.showById = function(id) {
		window.clearTimeout(timer);
		for (var i = 0; i < shipSections.length; i++) {
			if (shipSections[i] == id) {
				self.showByKey(i);
				return true;
			}
		}
		
		return false;
	}
	
	this.showByKey = function(key){
		//load current
		dojo.query('#'+shipSections[key]+' > *')[0].src = shipSectionImages[key].src;
		
		// preload Previous and Next 2
		// previous
		if(key > 1)
			dojo.query('#'+shipSections[key-1]+' > *')[0].src = shipSectionImages[key - 1].src;
		else
			dojo.query('#'+shipSections[shipSections.length - 1]+' > *')[0].src = shipSectionImages[shipSections.length - 1].src;
			
		if(key + 1 < shipSections.length)
			dojo.query('#'+shipSections[key+1]+' > *')[0].src = shipSectionImages[key + 1].src;

		
    	if(key !== currentShipKey) {
			if(currentShipKey !== false)
			self.hideSection(currentShipKey);
			
			self.showSection(key);
			self.showSectionNo(key)
		}
    	
		ship.hideGallery();
		ship.hideShipDetails();
		ship.hideEquipment();
		ship.hideCabinsAndSuits();
		
    }
    
	this.showSection = function(key){
		 dojo.style(shipSections[key],"opacity","0");
		 dojo.style(shipSections[key],"display","block"); 
		 
		 var fxShowSection = dojo.animateProperty({
            node: shipSections[key],
            duration: 500,
			easing: dojo.fx.easing.quadInOut,
            properties: {
				opacity: {
                    end: 1
                }
            },
			onEnd: function(){
        		currentShipKey = key;
        		 //alert("T");
        		 if(shipDetailOpen)
        			 dojo.style('sectionSpacer',"height", dojo.marginBox("characteristics").h + 397 + 50 +"px");
        		 else
        			 dojo.style('sectionSpacer',"height",dojo.marginBox(shipSections[key]).h +10+ "px");
    		}
        });
		
        fxShowSection.play();
	}
	
	this.hideSection = function(key){
		 var fxHideSection = dojo.animateProperty({
            node: shipSections[key],
            duration: 500,
			easing: dojo.fx.easing.quadInOut,
            properties: {
				opacity: {
                    end: 0
                }
            },
			onEnd: function(){
				dojo.style(shipSections[key],"display","none");
    		}
        });
		
        fxHideSection.play();
	}
	
	this.setShipSections = function(mySections){
		shipSections = mySections;
	}
	
	this.setShipSectionsImages = function(mySectionImages){
		shipSectionsImages = mySectionImages;
	}
	
    /*
     *Gallery
     */
	
    this.triggerGallery = function(){
		if(galleryOpen){
			self.hideGallery();
		}
		else {
			self.showGallery();
		}
    }

    this.showGallery = function(){
        var fxshowGallery = dojo.animateProperty({
            node: "galleryWrapper",
            duration: 800,
			easing: dojo.fx.easing.quadInOut,
            properties: {
                height: {
                    end: 265,
					 unit: "px"
                },
				opacity: {
                    end: 1
                }
            },
			onEnd: function(){
        		galleryOpen = true;
    		}
        });
		document.getElementById('galleryArrow').src = 'themes/ocean/images/buttonArrowDown.gif';
        fxshowGallery.play();
    }
    
    this.hideGallery = function(){
        var fxhideGallery = dojo.animateProperty({
            node: "galleryWrapper",
            duration: 800,
			easing: dojo.fx.easing.quadInOut,
            properties: {
                height: {
                    end: 0,
					unit: "px"
                },
				opacity: {
                    end: 0
                }
            },
			onEnd: function(){
        		galleryOpen = false;
    		}
        });
        document.getElementById('galleryArrow').src = 'themes/ocean/images/buttonArrowRight.gif';
        fxhideGallery.play();
    }
    
    
    /*
     *Shipdetails
     */
	
	 this.triggerShipDetails = function(){
    	
        if (document.getElementById('characteristics').style.marginTop == "0px") {
            self.hideShipDetails();
        }
        else {
			self.showShipDetails();
        }
    }
	
	
	this.getElementsByClass = function(searchClass,node,tag) {
		var classElements = new Array();
		if ( node == null )
			node = document;
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}
	
	
	
    this.showShipDetails = function(){
    	document.getElementById('characteristics').style.display = "block";
		
        var fxShowShipDetails = dojo.animateProperty({
            node: "characteristics",
            duration: 800,
			easing: dojo.fx.easing.quadInOut,
            properties: {
                marginTop: {
                    end: 0,
                    unit: "px"
                },
				opacity: {
                    end: 1
                }
            },
			onEnd: function(){
        		shipDetailOpen = true;
        		dojo.style('sectionSpacer',"height",dojo.byId("characteristics").clientHeight + 397 + 50 +"px");
    		}
        });
        
		
		document.getElementById('characteristicArrow').src = 'themes/ocean/images/buttonArrowDown.gif';
        fxShowShipDetails.play();
		


		var sectionTypographies = self.getElementsByClass("sectionTypography");
		var divHeight = (-1)*(document.getElementById("characteristics").clientHeight);

		//console.log(divHeight);
		for (i = 0; i < sectionTypographies.length; i++ ){
			var sectionTypography = dojo.animateProperty({
	            node: sectionTypographies[i],
	            duration: 800,
				easing: dojo.fx.easing.quadInOut,
	            properties: {
					opacity: {
                    end: 0
                }
	            },
				onEnd: function(){
	        		shipDetailOpen = true;
	    		}
	        });
			sectionTypography.play();
		}
		
		

    }
    
    this.hideShipDetails = function(){		
    
        var fxHideShipDetails = dojo.animateProperty({
            node: "characteristics",
            duration: 800,
			easing: dojo.fx.easing.quadInOut,
            properties: {
                marginTop: {
                    end: -269,
                    unit: "px"
                },
				opacity: {
                    end: 0
                }
				
            },
			onEnd: function(){
        		shipDetailOpen = false;
				var sectionTypographies = self.getElementsByClass("sectionTypography");
				//console.log(sectionTypographies);
				for (i = 0; i < sectionTypographies.length; i++ ){
					sectionTypographies[i].style.display = "block";
				}
				 dojo.style('sectionSpacer',"height",dojo.byId(shipSections[currentShipKey]).clientHeight+10+"px");

    		}
        });
        document.getElementById('characteristicArrow').src = 'themes/ocean/images/buttonArrowRight.gif';
        fxHideShipDetails.play();
		
		var sectionTypographies = self.getElementsByClass("sectionTypography");
		var divHeight = document.getElementById("characteristics").clientHeight;

		//console.log(divHeight);
		for (i = 0; i < sectionTypographies.length; i++ ){
			var fxSectionTypography = dojo.animateProperty({
	            node: sectionTypographies[i],
	            duration: 800,
				easing: dojo.fx.easing.quadInOut,
	            properties: { 
					opacity: {
                    end: 1
               		}
	            },
				onEnd: function(){
	        		shipDetailOpen = true;
	    		}
	        });
			fxSectionTypography.play();
		}
	
		

    }
	

    
    
    /*
     *Equipment
     */


this.triggerEquipment = function(){
    	
        if (document.getElementById('equipment').style.marginTop == "0px") {
            self.hideEquipment();
        }
        else {
			self.showEquipment();
        }
    }
	
	
	this.showEquipment = function(){
    	document.getElementById('equipment').style.display = "block";
		
        var fxShowEquipment = dojo.animateProperty({
            node: "equipment",
            duration: 800,
			easing: dojo.fx.easing.quadInOut,
            properties: {
                marginTop: {
                    end: 0,
                    unit: "px"
                },
				opacity: {
                    end: 1
                }
            },
			onEnd: function(){
        		equipmentOpen = true;
        		dojo.style('sectionSpacer',"height",dojo.byId("equipment").clientHeight + 397 + 50 +"px");
    		}
        });
		
		document.getElementById('equipmentArrow').src = 'themes/ocean/images/buttonArrowDown.gif';
        fxShowEquipment.play();

		var sectionTypographies = self.getElementsByClass("sectionTypography");
		var divHeight = (-1)*(document.getElementById("equipment").clientHeight);

		//console.log(divHeight);
		for (i = 0; i < sectionTypographies.length; i++ ){
			var fxSectionTypography = dojo.animateProperty({
	            node: sectionTypographies[i],
	            duration: 800,
				easing: dojo.fx.easing.quadInOut,
	            properties: {
					opacity: {
                    end: 0
                }
	            },
				onEnd: function(){
	        		equipmentOpen = true;
	    		}
	        });
			fxSectionTypography.play();
		}
		
		

    }
    
    this.hideEquipment = function(){		
    
        var fxHideEquipment = dojo.animateProperty({
            node: "equipment",
            duration: 800,
			easing: dojo.fx.easing.quadInOut,
            properties: {
                marginTop: {
                    end: -269,
                    unit: "px"
                },
				opacity: {
                    end: 0
                }
				
            },
			onEnd: function(){
        		equipmentOpen = false;
				var sectionTypographies = self.getElementsByClass("sectionTypography");
				//console.log(sectionTypographies);
				for (i = 0; i < sectionTypographies.length; i++ ){
					sectionTypographies[i].style.display = "block";
				}
				 dojo.style('sectionSpacer',"height",dojo.byId(shipSections[currentShipKey]).clientHeight+10+"px");

    		}
        });
        document.getElementById('equipmentArrow').src = 'themes/ocean/images/buttonArrowRight.gif';
        fxHideEquipment.play();
		
				var sectionTypographies = self.getElementsByClass("sectionTypography");
		var divHeight = document.getElementById("equipment").clientHeight;

		//console.log(divHeight);
		for (i = 0; i < sectionTypographies.length; i++ ){
			var sectionTypography = dojo.animateProperty({
	            node: sectionTypographies[i],
	            duration: 800,
				easing: dojo.fx.easing.quadInOut,
	            properties: { 
					opacity: {
                    end: 1
               		}
	            },
				onEnd: function(){
	        		equipmentOpen = true;
	    		}
	        });
			sectionTypography.play();
		}
	
    }
	
    
    /*
     *Cabin and Suiten
     */
	
	
	this.triggerCabinsAndSuits = function(){
    	
        if (document.getElementById('cabinsAndSuits').style.marginTop == "0px") {
            self.hideCabinsAndSuits();
        }
        else {
			self.showCabinsAndSuits();
        }
    }
	
	
	this.showCabinsAndSuits = function(){
    	document.getElementById('cabinsAndSuits').style.display = "block";
		
        var fxShowCabinsAndSuits = dojo.animateProperty({
            node: "cabinsAndSuits",
            duration: 800,
			easing: dojo.fx.easing.quadInOut,
            properties: {
                marginTop: {
                    end: 0,
                    unit: "px"
                },
				opacity: {
                    end: 1
                }
            },
			onEnd: function(){
        		cabinsAndSuitsOpen = true;
        		dojo.style('sectionSpacer',"height",dojo.byId("cabinsAndSuits").clientHeight + 397 + 50 +"px");
    		}
        });
		
		document.getElementById('cabinsAndSuitsArrow').src = 'themes/ocean/images/buttonArrowDown.gif';
        fxShowCabinsAndSuits.play();

		var sectionTypographies = self.getElementsByClass("sectionTypography");
		var divHeight = (-1)*(document.getElementById("cabinsAndSuits").clientHeight);

		//console.log(divHeight);
		for (i = 0; i < sectionTypographies.length; i++ ){
			var fxSectionTypography = dojo.animateProperty({
	            node: sectionTypographies[i],
	            duration: 800,
				easing: dojo.fx.easing.quadInOut,
	            properties: {
					opacity: {
                    end: 0
                }
	            },
				onEnd: function(){
	        		cabinsAndSuitsOpen = true;
	    		}
	        });
			fxSectionTypography.play();
		}
		
		

    }
    
    this.hideCabinsAndSuits = function(){		
    
        var fxHideCabinsAndSuits = dojo.animateProperty({
            node: "cabinsAndSuits",
            duration: 800,
			easing: dojo.fx.easing.quadInOut,
            properties: {
                marginTop: {
                    end: -269,
                    unit: "px"
                },
				opacity: {
                    end: 0
                }
				
            },
			onEnd: function(){
        		cabinsAndSuitsOpen = false;
				var sectionTypographies = self.getElementsByClass("sectionTypography");
				//console.log(sectionTypographies);
				for (i = 0; i < sectionTypographies.length; i++ ){
					sectionTypographies[i].style.display = "block";
				}
				 dojo.style('sectionSpacer',"height",dojo.byId(shipSections[currentShipKey]).clientHeight+10+"px");

    		}
        });
        document.getElementById('cabinsAndSuitsArrow').src = 'themes/ocean/images/buttonArrowRight.gif';
        fxHideCabinsAndSuits.play();
		
				var sectionTypographies = self.getElementsByClass("sectionTypography");
		var divHeight = document.getElementById("cabinsAndSuits").clientHeight;

		//console.log(divHeight);
		for (i = 0; i < sectionTypographies.length; i++ ){
			var sectionTypography = dojo.animateProperty({
	            node: sectionTypographies[i],
	            duration: 800,
				easing: dojo.fx.easing.quadInOut,
	            properties: { 
					opacity: {
                    end: 1
               		}
	            },
				onEnd: function(){
	        		cabinsAndSuitsOpen = true;
	    		}
	        });
			sectionTypography.play();
		}
	
		

    }
	

    
    var self = this;
}

//var scrollbar = new Scrollbar();
var ship = new Ship();


dojo.addOnLoad(function(){
    //ship.init();
});


