
var sibylla = {
	
	posArray : new Array(0, -540,-1080,-1620,-2160,-2700,-3240,-3780,-4320,-4860,-5400,-5940),
	currentPosition : 0,
	nameArrya : new Array('Sibylla Meal','Bamse Meal', 'Jumbo Meal','Super Meal','Big Meal','Mini Meal','Good Meal','Green Meal','Chicky Meal','Lax Meal','K&ouml;ttbulle Meal','Fun-box'),
	previewImg : new Array('p-meal-0.jpg','p-meal-1.jpg','p-meal-2.jpg','p-meal-3.jpg','p-meal-4.jpg','p-meal-5.jpg','p-meal-6.jpg','p-meal-7.jpg','p-meal-8.jpg','p-meal-9.jpg','p-meal-10.jpg','p-meal-11.jpg'),
	sideOrderPos : new Array(0,-135,-269),
	currSideOrderPos : 0,
	sodaPositions : new Array(0,-135,-269,-403,-537,-671,-805),
	currSodaPos : 0,
	
	setupMenu : function(){	
		$$('ul.menu ul').each(function(target){
			if(window.webkit) target.className = 'webkit';
		});
	},
	
	surpressError : function(){
		return false;	
	},
	
	getQueryString : function (ji) {
		hu = window.location.search.substring(1);
		gy = hu.split("&");
		for (i=0;i<gy.length;i++) {
			ft = gy[i].split("=");
			if (ft[0] == ji) {
				return ft[1];
			}
		}
	},
	
	
	setupBubbleHandles : function(){
		$$('img.grille').each(function(target){
			target.addEvent('mouseenter', function(event){
				sibylla.show('bubble');
				sibylla.write('text',$('text1').innerHTML);
				sibylla.place('bubble',-75,550);				
			});
			
			target.addEvent('mouseleave', function(){
				sibylla.hide('bubble');		
			});
						
		});
		
		$$('img.musse').each(function(target){
			target.addEvent('mouseenter', function(event){
				sibylla.show('bubble');
				sibylla.write('text',$('text2').innerHTML)
				sibylla.place('bubble',-55,600);
				
			});
			
			target.addEvent('mouseleave', function(){
				sibylla.hide('bubble');		
			});
						
		});
		
		$$('img.love').each(function(target){
			target.addEvent('mouseenter', function(event){
				sibylla.show('bubble');
				$('text').innerHTML = this.alt;
				sibylla.place('bubble',195,350);				
			});
			
			target.addEvent('mouseleave', function(){
				sibylla.hide('bubble');		
			});
						
		});
		
		$$('img.caring').each(function(target){
			target.addEvent('mouseenter', function(event){
				sibylla.show('bubble');
				$('text').innerHTML = this.alt;
				sibylla.place('bubble',210,450);				
			});
			
			target.addEvent('mouseleave', function(){
				sibylla.hide('bubble');		
			});
						
		});
		
		if($('bubble') != null){
			$('bubble').addEvent('mouseenter', function(event){
			sibylla.show('bubble');			
			});
			$('bubble').addEvent('mouseleave', function(event){
				(function(){ sibylla.hide('bubble'); }).delay(2500);			
			});
			
		}
		
	},
	
	
	slide : function(){
		//$E('a', 'slider')
		var l = $('workspace').getLeft();
		$('sliderStart').setStyle(
			'background-color', '#f2f1f2');

		$('sliderStart').effects({
			duration: 1000,
			transition: Fx.Transitions.Sine.easeInOut
		}).start({
			'width':[41,940],
			'left':[0]
		}).addEvent('onComplete', function(){
			(function(){ document.location.href="/"; }).delay(500);
		});
	},
	
	startSlideNone : function(){
		if($('sliderStart') != null){
			
			$('sliderStart').style.width = '41px';
			$('sliderStart').style.left = '940px';
			$('sliderStart').style.display = 'block';
		}
	},
	
	startSlide : function(){
		if($('sliderStart') != null){
			$('sliderStart').effects({
				duration: 1000,
				transition: Fx.Transitions.Sine.easeInOut
			}).start({
				'width':[940,41],
				'left':[940]
			}).addEvent('onComplete', function(){
				//(function(){ sibylla.fade($('sliderStart')); }).delay(1000);
			});
		}
		
		if($('sliderStartFront') != null){
			$('sliderStartFront').effects({
				duration: 1000,
				transition: Fx.Transitions.Sine.easeInOut
			}).start({
				'width':[940,41],
				'left':[940]
			}).addEvent('onComplete', function(){
				(function(){ sibylla.fade($('sliderStartFront')); }).delay(100);
			});
		}
		
	},
	
	startSlideToUrl : function(url){
		if($('sliderStart') != null){
			var l = $('workspace').getLeft();
			$('sliderStart').setStyle(
				'background-color', '#f2f1f2');

			$('sliderStart').effects({
				duration: 1000,
				transition: Fx.Transitions.Sine.easeInOut
			}).start({
				'width':[41,940],
				'left':[0]
			}).addEvent('onComplete', function(){
				(function(){ document.location.href=url; }).delay(500);
			});
		}
		if($('sliderStartFront') != null){
			var l = $('workspace').getLeft();
			
			
			
			(function(){ sibylla.fadeIn($('sliderStartFront')); }).delay(100);
			
			$('sliderStartFront').setStyle(
				'background-color', '#f2f1f2');

			$('sliderStartFront').effects({
				duration: 1000,
				transition: Fx.Transitions.Sine.easeInOut
			}).start({
				'width':[41,940],
				'left':[0]
			}).addEvent('onComplete', function(){
				(function(){ document.location.href=url; }).delay(500);
			});
		}
	},
	
	goToStart : function(){
		document.location.href="/";
	},
	
	show : function(target){
		$(target).setStyle('display', 'block');
	},
	
	hide : function(target){
		$(target).setStyle('display', 'none');
	},
	
	fade : function(target){
		target.effect('opacity', {duration: 250, transition: Fx.Transitions.Quart.easeInOut}).start(0);
	},
	
	fadeIn : function(target){
		target.effect('opacity', {duration: 500, transition: Fx.Transitions.Quart.easeInOut}).start(100);
	},
	
	write : function(target,text){
		$(target).innerHTML = text;
	},
	
	place : function(target,t,l){
		$(target).setStyles({  
			top: t, 
			left: l
		});
	},
	
	menuSlider : function(int,pan){
		if(pan) 
			$('menuSlider').effect('left', {duration: 1200, transition: Fx.Transitions.Sine.easeInOut}).start(this.posArray[int]);
		else
			$('menuSlider').effect('left', {duration: 1200, transition: Fx.Transitions.Sine.easeInOut}).set(this.posArray[int]); 
		$('menuTitle').innerHTML = this.nameArrya[int];
		this.currentPosition = int;
		this.reset()
	},
	
	cycle : function(forward){
		if(forward){
			if(this.currentPosition < this.posArray.length-1)
				this.currentPosition++;
			else
				this.currentPosition = 0;
		} else {
			if(this.currentPosition > 0)
				this.currentPosition--;
			else
				this.currentPosition = this.posArray.length-1;
		}
		this.menuSlider(this.currentPosition,true);
	},
	
	setupPreviews : function(){
		$$('div.p-box').each(function(target,index){
			var pImg = new Element('img', {
				'events': {
					'click': function(){
						sibylla.show('popper');
						sibylla.menuSlider(index,false);
					}
				},
				'width': '101',
				'height': '90',
				'src': '/UI/Images/' + sibylla.previewImg[index]
			});
			
			var h4 = new Element('h4', {
				'events': {
					'click': function(){
						sibylla.show('popper');
						sibylla.menuSlider(index,false);
					}
				}
			});
			h4.innerHTML = sibylla.nameArrya[index];
			pImg.injectInside(target);
			h4.injectInside(target);
			if(index == 0 || index == 4 || index == 8)
				target.className = 'p-box-first';
		});
		
		if(window.webkit) $('menuSlider').className = 'webkit';
	},
	
	setupAssets : function(){
		$$('div.overflow div').each(function(target){
			//target.setStyle('position', 'absolute');
			target.setStyles({  
				position: 'absolute', 
				left: '0'
			});
		});
		$$('img.upButton').each(function(target,i){
			target.setProperty('id', 'up-'+i);
			target.addEvent('click', function(){
				if(sibylla.currSideOrderPos < sibylla.sideOrderPos.length-1){
					sibylla.currSideOrderPos++;
					sibylla.assetMove(('asset-'+i),target,('down-'+i))
				}
			});
		});
		$$('img.downButton').each(function(target,i){
			target.setProperty('id', 'down-'+i);
			target.addEvent('click', function(){
				if(sibylla.currSideOrderPos > 0){
					sibylla.currSideOrderPos--;
					sibylla.assetMove(('asset-'+i),('up-'+i),target)
				} 	
			});
		});
		
		$$('img.upButtonSoda').each(function(target,i){
			target.setProperty('id', 'upS-'+i);
			target.addEvent('click', function(){
				if(sibylla.currSodaPos < sibylla.sodaPositions.length-1){
					sibylla.currSodaPos++;
					sibylla.sodaMove(('soda-'+i),target,('downS-'+i))
				}
					
			});
		});
		$$('img.downButtonSoda').each(function(target,i){
			target.setProperty('id', 'downS-'+i);
			target.addEvent('click', function(){
				if(sibylla.currSodaPos > 0){
					sibylla.currSodaPos--;
					sibylla.sodaMove(('soda-'+i),('upS-'+i),target)
				} 	
			});
		});
	},
	
	assetMove : function(target,upbutton,downbutton){
		$(target).effect('top', {
				duration: 1000, 
				transition: Fx.Transitions.Sine.easeInOut
			}).start(
				this.sideOrderPos[this.currSideOrderPos]
			).addEvent('onComplete', function(){
				sibylla.checkButton(upbutton,downbutton);				
			});
	},
	
	sodaMove : function(target,upbutton,downbutton){
		$(target).effect('top', {
				duration: 1000, 
				transition: Fx.Transitions.Sine.easeInOut
			}).start(
				this.sodaPositions[this.currSodaPos]
			).addEvent('onComplete', function(){
				sibylla.checkSodaButton(upbutton,downbutton);				
			});
	},		
	
	disableButton : function(target){
		target.effect('opacity', {duration: 500, transition: Fx.Transitions.Quart.easeInOut}).start(.4);
		target.setStyle('cursor', 'default');
	},
	
	enableButton : function(target){
		target.effect('opacity', {duration: 500, transition: Fx.Transitions.Quart.easeInOut}).start(1);
		target.setStyle('cursor', 'pointer');
	},
	
	checkButton : function(upbutton,downbutton){
		if(this.currSideOrderPos == 0)
			this.disableButton($(downbutton));
		if(this.currSideOrderPos > 0 && this.currSideOrderPos < this.sideOrderPos.length-1){
			this.enableButton($(upbutton))
			this.enableButton($(downbutton))
		}
		if(this.currSideOrderPos == this.sideOrderPos.length-1)
			this.disableButton($(upbutton));
	},
	
	checkSodaButton : function(upbutton,downbutton){
		if(this.currSodaPos == 0)
			this.disableButton($(downbutton));
		if(this.currSodaPos > 0 && this.currSodaPos < this.sodaPositions.length-1){
			this.enableButton($(upbutton))
			this.enableButton($(downbutton))
		}
		if(this.currSodaPos == this.sodaPositions.length-1)
			this.disableButton($(upbutton));
	},
	
	reset : function(){
		this.currSideOrderPos = this.currSodaPos = 0;
		$$('div.sideorder-wrapper div').each(function(target){
			target.effect('top', {duration: 1000, transition: Fx.Transitions.Sine.easeInOut}).start(0);
		});
		$$('img.upButton').each(function(target){
			sibylla.enableButton(target);
		});
		$$('img.downButton').each(function(target){
			sibylla.disableButton(target);
		});
		$$('img.upButtonSoda').each(function(target){
			sibylla.enableButton(target);
		});
		$$('img.downButtonSoda').each(function(target){
			sibylla.disableButton(target);
		});
	},
	
	checkPos : function(log){
		console.debug(log)
	},
	
	init: function(){
		this.setupMenu();
		//this.setupBubbleHandles();
		this.setupPreviews();
		this.setupAssets();
	}

};


window.onDomReady(sibylla.init.bind(sibylla));
window.onload = function(){
	
	if (typeof(noslide) != 'string')
	{
		sibylla.startSlide();
	}
	else
	{
		sibylla.startSlideNone();
	}
};
