Ext.onReady(function(){
			
	var hauptcontainer 	= Ext.get('hauptcontainer');
	var award			= Ext.get('award');
	var logo 			= Ext.get('logo');
	var hauptmenue 		= Ext.get('hauptmenue');
	var teamcontainer 	= Ext.get('teamcontainer');
	var loesungencontainer = Ext.get('loesungencontainer');
	var kontaktcontainer= Ext.get('kontaktcontainer');
	var linkeebene1 	= Ext.get('linkeebene1');
	var linkeebene1a 	= Ext.get('linkeebene1a');
	var linkeebene1b	= Ext.get('linkeebene1b');
	var rechteebene1 	= Ext.get('rechteebene1');
	var rechteebene1a 	= Ext.get('rechteebene1a');
	var rechteebene1b	= Ext.get('rechteebene1b');
	var kontaktebene	= Ext.get('kontaktebene');
	var wer				= Ext.get('wer');
	var wie				= Ext.get('wie');
	var was				= Ext.get('was');
	var kunden			= Ext.get('kunden');
	var team			= Ext.get('team');
	var loesungen		= Ext.get('loesungen');
	var kontakt			= Ext.get('kontakt');
	var	rechtemicrosite = Ext.get('rechteebene1c-micro');
	var rechtemicrotext = Ext.get('text-auszug-micro');
	var microback		= Ext.get('micro-back');
	var wissen			= Ext.get('wissen');
	var viewer			= Ext.get('viewer');
		
	var viewport = Ext.create('Ext.container.Viewport', {id: 'viewport'});
			
	var windowWidth 	= viewport.getWidth();
	var windowHeight 	= viewport.getHeight();
			
	var startWidth 		= windowWidth/2-hauptmenue.getWidth()/2;
	var startHeight		= windowHeight/2-hauptmenue.getHeight()/2;
			
	var changeX			= 0;
	var changeY			= 0;
	
	var topbar			= false;
	
	var awardX			= award.getX();
	var awardY			= award.getY();
	var viewerX			= viewer.getX();
	var viewerY			= viewer.getY();
	
	kontaktMarginY 		= 210;
	hauptmenueMarginY 	= 10;
	
	award.hide();
	viewer.hide();
	award.moveTo(awardX,awardY-150);
	viewer.moveTo(viewerX,viewerY-150);
	
	var test = function(zahl) {
		return zahl*2;
	}
	
	var loadMicroSite = function(name) {
		var text = false;
		Ext.Ajax.request({
		    url: 'getData.php',
		    params: {
		        content: name
		    },
		    success: function(response){
		    	rechtemicrotext.update(response.responseText);
		    	showMicroSite();
		    }
		});
	}
			
	var initialization = function(dur) {
		
		windowWidth 	= viewport.getWidth();
		windowHeight 	= viewport.getHeight();
		startWidth 		= windowWidth/2-hauptmenue.getWidth()/2;
		startHeight		= windowHeight/2-hauptmenue.getHeight()/2;
		linkeebene1.hide();
		linkeebene1a.hide();
		linkeebene1b.hide();
		rechteebene1.hide();
		rechteebene1a.hide();
		rechteebene1b.hide();
		kontaktebene.hide();
		rechtemicrosite.hide();
				
		loesungen.removeCls('loesungenover');
		loesungen.addCls('loesungen');
		kontakt.removeCls('kontaktover');
		kontakt.addCls('kontakt');
		team.removeCls('teamover');
		team.addCls('team');
		
		linkeebene1.moveTo(startWidth,startHeight);
		linkeebene1a.moveTo(startWidth,startHeight);
		linkeebene1b.moveTo(startWidth,startHeight);
		rechteebene1.moveTo(startWidth,startHeight);
		rechteebene1a.moveTo(startWidth,startHeight);
		rechteebene1b.moveTo(startWidth,startHeight);
		kontaktebene.moveTo(startWidth,startHeight);
		if (dur > 0) {
			hauptmenue.moveTo(startWidth,startHeight,{duration: dur});
		}else{
			hauptmenue.moveTo(startWidth,startHeight);
		}
		showTopBar();
	}
						
	var checkResolution = function() {
		/*
		if (viewport.getWidth() < 600 || viewport.getHeight() < 500) {
			Ext.MessageBox.show({
				title:'Knapp bemessen!',
				msg:'Monitor zu klein! Wir liefern Ihnen gern den passenden. Tel. 030/206159-30',
				icon: Ext.MessageBox.WARNING
			});
		}
		*/
		initialization();
	}
	
	var hideAll = function() {
		linkeebene1.hide();
		linkeebene1a.hide();
		linkeebene1b.hide();
		rechteebene1.hide();
		rechteebene1a.hide();
		rechteebene1b.hide();
		kontaktebene.hide();
	}
	
	var hideTopBar = function() {
		
		if (topbar == true) {
			award.moveTo(awardX,awardY-150,{duration: 500});
			viewer.moveTo(viewerX,viewerY-150,{duration: 500});
			topbar = false;
		}
	}
	
	var showTopBar = function() {
		if (topbar == false) {
			award.moveTo(awardX,awardY,{duration: 2000, easing: 'bounceOut'});
			viewer.moveTo(viewerX,viewerY,{duration: 2000, easing: 'bounceOut'});
			topbar = true;
		}
	}
	
	var moveAllVisible = function(x,y,dur) {
		
		if (!dur) {
			dur = 500;
		}
		
		hauptmenue.moveTo(hauptmenue.getX()+x,hauptmenue.getY()+y,{duration: dur});
		if (linkeebene1.isVisible()) {
			linkeebene1.moveTo(linkeebene1.getX()+x,linkeebene1.getY()+y,{duration: dur});
		}
		if (linkeebene1a.isVisible()) {
			linkeebene1a.moveTo(linkeebene1a.getX()+x,linkeebene1a.getY()+y,{duration: dur});
		}
		if (linkeebene1b.isVisible()) {
			linkeebene1b.moveTo(linkeebene1b.getX()+x,linkeebene1b.getY()+y,{duration: dur});
		}
		if (rechteebene1.isVisible()) {
			rechteebene1.moveTo(rechteebene1.getX()+x,rechteebene1.getY()+y,{duration: dur});
		}
		if (rechteebene1a.isVisible()) {
			rechteebene1a.moveTo(rechteebene1a.getX()+x,rechteebene1a.getY()+y,{duration: dur});
		}
		if (rechteebene1b.isVisible()) {
			rechteebene1b.moveTo(rechteebene1b.getX()+x,rechteebene1b.getY()+y,{duration: dur});
		}
		if (kontaktebene.isVisible()) {
			kontaktebene.moveTo(kontaktebene.getX()+x,kontaktebene.getY()+y,{duration: dur});
		}
		if (rechtemicrosite.isVisible()) {
			rechtemicrosite.moveTo(rechtemicrosite.getX()+x,rechtemicrosite.getY()+y,{duration: dur});
		}
		
	}
			
	var goLeftOne = function() {
		if (hauptmenue.getActiveAnimation() == false) {			
			if (linkeebene1.isVisible()) {
				hideAll();
				team.removeCls('teamover');
				team.addCls('team');					
				hauptmenue.moveTo(startWidth,startHeight,{duration: 500});
				showTopBar();
			}else{
				rechtemicrosite.hide();
				rechteebene1.hide();
				rechteebene1a.hide();
				rechteebene1b.hide();
				kontaktebene.hide();
				team.removeCls('team');
				team.addCls('teamover');
				loesungen.removeCls('loesungenover');
				loesungen.addCls('loesungen');
				kontakt.removeCls('kontaktover');
				kontakt.addCls('kontakt');
				linkeebene1.moveTo(hauptmenue.getX()-320,hauptmenue.getY()+121);
				linkeebene1.show();
				hauptmenue.moveTo(startWidth+300,startHeight,{duration: 500});
				linkeebene1.moveTo(startWidth-20,startHeight+121,{duration: 500});
				hideTopBar();
			}
		}			
	}
			
	var goLeftTwo = function() {
		if (hauptmenue.getActiveAnimation() == false) {
			if (linkeebene1a.isVisible()) {
				linkeebene1a.hide();
				if (windowWidth < 1050) {
					hauptcontainer.removeCls('hauptcontainer-scroll');
					hauptcontainer.addCls('hauptcontainer');
				}
				moveAllX = -400;
				moveAllY = 0;
			}else{
				linkeebene1a.moveTo(linkeebene1.getX()-830,linkeebene1.getY());
				linkeebene1a.show();
				if (windowWidth < 1050) {
					hauptcontainer.removeCls('hauptcontainer');
					hauptcontainer.addCls('hauptcontainer-scroll');
				}
				moveAllX = 400;
				moveAllY = 0;
			}
			moveAllVisible(moveAllX,moveAllY);
		}			
	}
			
	var goLeftDown= function() {
		if (hauptmenue.getActiveAnimation() == false) {
			if (linkeebene1b.isVisible()) {
				linkeebene1b.hide();
				if (windowHeight < 650) {
					hauptcontainer.removeCls('hauptcontainer-scroll');
					hauptcontainer.addCls('hauptcontainer');
				}
				moveAllX = 0;
				moveAllY = startHeight-hauptmenueMarginY;
			}else{
				linkeebene1b.moveTo(linkeebene1.getX()-20,linkeebene1.getY()+50);
				linkeebene1b.show();
				if (windowHeight < 650) {
					hauptcontainer.removeCls('hauptcontainer');
					hauptcontainer.addCls('hauptcontainer-scroll');
				}
				moveAllX = 0;
				moveAllY = hauptmenueMarginY - hauptmenue.getY();
				
			}
			moveAllVisible(moveAllX,moveAllY);
		}
				
				
	}
			
	var goRightOne = function() {
		if (hauptmenue.getActiveAnimation() == false) {
			if (rechteebene1.isVisible()) {
				hideAll();
				loesungen.removeCls('loesungenover');
				loesungen.addCls('loesungen');
				hauptmenue.moveTo(startWidth,startHeight,{duration: 500});
				showTopBar();
			}else{
				team.removeCls('teamover');
				team.addCls('team');
				loesungen.removeCls('loesungen');
				loesungen.addCls('loesungenover');
				kontakt.removeCls('kontaktover');
				kontakt.addCls('kontakt');
				linkeebene1.hide();
				linkeebene1a.hide();
				linkeebene1b.hide();
				kontaktebene.hide();
				rechteebene1.moveTo(hauptmenue.getX()+232,hauptmenue.getY()+151);
				rechteebene1.show();
				hauptmenue.moveTo(startWidth-172,startHeight-50,{duration: 500});
				rechteebene1.moveTo(startWidth+60,startHeight+101,{duration: 500});
				hideTopBar();
			}
		}				
	}
			
	var goRightTwo = function() {
		if (hauptmenue.getActiveAnimation() == false) {	
			if (rechteebene1a.isVisible()) {
				rechteebene1a.hide();
				if (windowHeight < 800 || windowWidth < 1050) {
					hauptcontainer.removeCls('hauptcontainer-scroll');
					hauptcontainer.addCls('hauptcontainer');
				}
				if (rechteebene1b.isVisible()) {
					moveAllX = 350;
					moveAllY = 0;
				}else{
					moveAllX = 350;
					moveAllY = startHeight-hauptmenueMarginY;
				}				
			}else{
				rechteebene1a.moveTo(rechteebene1.getX()+350,rechteebene1.getY());
				rechteebene1a.show();
				if (windowHeight < 800) {
					hauptcontainer.removeCls('hauptcontainer');
					hauptcontainer.addCls('hauptcontainer-scroll');
				}
				if (rechteebene1b.isVisible()) {
					moveAllX = -350
					moveAllY = 0
				}else{
					moveAllX = -350
					moveAllY = hauptmenueMarginY - hauptmenue.getY();
				}
			}
			moveAllVisible(moveAllX,moveAllY);
		}			
	}
			
	var goRightDown= function() {
		if (hauptmenue.getActiveAnimation() == false) {	
			if (rechteebene1b.isVisible()) {
				rechteebene1b.hide();
				if (windowHeight < 540) {
					hauptcontainer.removeCls('hauptcontainer-scroll');
					hauptcontainer.addCls('hauptcontainer');
				}
				if (rechteebene1a.isVisible()) {
					moveAllX = 0;
					moveAllY = 0;
				}else{
					moveAllX = 0;
					moveAllY = startHeight-hauptmenueMarginY;
				}				
			}else{
				rechteebene1b.moveTo(rechteebene1.getX()+20,rechteebene1.getY()+50);
				rechteebene1b.show();
				if (windowHeight < 540) {
					hauptcontainer.removeCls('hauptcontainer');
					hauptcontainer.addCls('hauptcontainer-scroll');
				}
				if (rechteebene1a.isVisible()) {
					moveAllX = 0;
					moveAllY = 0;
				}else{
					moveAllX = 0;
					moveAllY = hauptmenueMarginY - hauptmenue.getY();
				}
			}
			moveAllVisible(moveAllX,moveAllY);
		}
		
	}
			
	var goDown = function() {
		
		if (hauptmenue.getActiveAnimation() == false) {	
			if (kontaktebene.isVisible()) {
				showTopBar();
				kontaktebene.hide();
				kontakt.removeCls('kontaktover');
				kontakt.addCls('kontakt');
				if (windowHeight < 670) {
					hauptcontainer.removeCls('hauptcontainer-scroll');
					hauptcontainer.addCls('hauptcontainer');
				}
				hauptmenue.moveTo(startWidth,startHeight,{duration: 500});
			}else{					
				hideAll();
				hideTopBar();
				team.removeCls('teamover');
				team.addCls('team');
				loesungen.removeCls('loesungenover');
				loesungen.addCls('loesungen');
				kontakt.removeCls('kontakt');
				kontakt.addCls('kontaktover');
				
				kontaktebene.moveTo(hauptmenue.getX(),hauptmenue.getY()+kontaktMarginY);
				kontaktebene.show();
				if (windowHeight < 670) {
					hauptcontainer.removeCls('hauptcontainer');
					hauptcontainer.addCls('hauptcontainer-scroll');
				}
				hauptmenue.moveTo(startWidth,10,{duration: 500});					
				kontaktebene.moveTo(startWidth,kontaktMarginY+hauptmenueMarginY,{duration: 500});
				
			}
		}
	}
			
	var goToStart = function() {
		if (hauptmenue.getActiveAnimation() == false) {
			showTopBar();
			initialization(500);
		}
	}
	
	var goMicroSite = function(a,b) {
		
		if (hauptmenue.getActiveAnimation() == false && rechtemicrosite.getActiveAnimation() == false) {	
			loadMicroSite(a.getTarget("",1,true).id);
		}
	}
	
	var showMicroSite = function() {
		rechtemicrosite.moveTo(windowWidth +50,50);
		rechtemicrosite.show();
		moveAllVisible(-windowWidth,0,1000);
		if (rechteebene1a.isVisible() == false && linkeebene1a.isVisible() == false) {
				hideTopBar();	
		}
	}
	
	var goMicroBack = function() {

		if (hauptmenue.getActiveAnimation() == false) {	
			moveAllVisible(+windowWidth,0,1000);
			rechtemicrosite.hide({duration: 1000});
			if (rechteebene1a.isVisible() == false && linkeebene1a.isVisible() == false) {
				showTopBar();	
			}
		}
		
	}
			
	viewport.addListener('resize', checkResolution);
	logo.addListener('click', goToStart);
	teamcontainer.addListener('click',goLeftOne);
	wer.addListener('click',goLeftTwo);
	wie.addListener('click',goLeftDown);
	loesungencontainer.addListener('click',goRightOne);
	kunden.addListener('click',goRightTwo);
	was.addListener('click',goRightDown);
	kontaktcontainer.addListener('click',goDown);
	microback.addListener('click',goMicroBack);
	award.addListener('click',goMicroSite);
	wissen.addListener('click',goMicroSite);
	
	award.show();
	viewer.show();
		
	initialization(0);
});
