// JavaScript Document

var application;

var App = new Class({
    initialize: function(){
		this.currentID = null;
		this._animation = false;
		this._navhidden = false;
		this.fadeInEffect = null;
		this.fadeOutEffect = null;
		this.fadeOutDuration = 200;
		this.fadeInDuration = 500;
		this.movieId = "zeiss_ws";
		// refrence to the instance object
		var classref = this;
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
        var flashMovie = (isIE) ? window[this.movieId] : document[this.movieId];
		
		this.hideNavigation();
		
		// hide container and apply styles
		$$('div.content').each(function(container){
			new Fx.Style(container, 'opacity').set(0);
			
			container.setStyle("position", "absolute");
			// fix ie 7 bug
			if (window.ie) {
				if (container.id=='content1') {
					new Fx.Style(container, 'opacity').set(100);
				}
				container.setStyle("left", ($("sidecol").getSize().size.x) + "px");
				container.setStyle("margin-top", "10px");
			}
		});
		// handle navigation link events
		[1,2,3,4,5].each(function(el) {
			$('linkToVideo'+ el).onclick = function(event){
				var event = new Event(event);
				//classref.fadeContentFromLeft(el);
				flashMovie.sendToFlash(el);
				event.stop();
			};
		});		
    }, // end constructor initialize
    
    fadeContent: function(id){
		this.changeContainer(id);
    }, // end function fadeContent
	
	hideNavigation: function(){
		$$('div#sidecol div').each(function(link){
			new Fx.Style(link, 'opacity').set(0);
		});
		this._navhidden = true;
    }, // end function
    
	showNavigation: function(){
		$$('div#sidecol div').each(function(link){
			new Fx.Style(link, 'opacity').set(100);
		});
		this._navhidden = false;
    }, // end function
    
	fadeContentFromLeft: function(id){
		this.changeContainer(id, "left");
    }, // end function fadeContentFromLeft
	
	fadeContentFromRight: function(id){
		this.changeContainer(id, "right");
    }, // end function fadeContentFromRight
	
	changeContainer: function(id, direction){

		if (!this._animation && this.currentID!=id){
			this._animation = true;
			
			
			// apply highlight to current link
			$$('body a.current').each(function(link){
					link.removeClass('current');
					link.getPrevious().setProperties({src:'/C12567BE00472A5C/ContainerTitel/Efficient_Navigation_LSM-Software/$File/link.gif'});
			});
			$('linkToVideo'+ id).addClass('current');
			$('linkToVideo'+ id).getPrevious().setProperties({src:'/C12567BE00472A5C/ContainerTitel/Efficient_Navigation_LSM-Software/$File/link_current.gif'});
			
			
			if (this.currentID==null) {
				$$('body div.content').each(function(paragraph){
					new Fx.Style(paragraph, 'opacity').set(0);
				});
				this.fadeInEffect = new Fx.Styles( $('content'+id) , {duration: this.fadeInDuration, 
																			   transition:Fx.Transitions.Sine.easeInOut, 
																			   onComplete:function() {application._animation=false;} 
													}).start({'opacity':[0,1]});
				
			} else {
				// fade old content out
				this.fadeOutEffect = new Fx.Style( $('content'+this.currentID) , 'opacity', {duration: this.fadeOutDuration, 
																			   transition:Fx.Transitions.Sine.easeInOut, 
																			   onComplete:function() {
												// fade new content after completion							   
												this.fadeInEffect = new Fx.Styles( $('content'+id), {duration: 600, 
											  	transition:Fx.Transitions.Sine.easeIn, 
												onComplete:function() {application._animation=false;}
												}).start({'opacity':[0,1]});
												application._animation=false;
																				   
				} 
				}).start(1,0);
			}
			
			this.currentID = id;
		
		} else {
			// do nothing
		}
    }// end function changeContainer
});


window.addEvent('domready', function(){
	application = new App();
});
