
window.addEvent('domready', function() {

//alert('test2');
//alert($('analyseauszug'));

if($type($('analyseauszug')) != false) {


$('analyseauszug').setStyle('opacity', 0);

var analyseFX = new Fx.Tween('analyseauszug', {
	property: 'opacity',
	duration: 500, 
	transition: Fx.Transitions.Quart.easeInOut
});

var analyseMove = new Fx.Move('analyseauszug', {
  relativeTo: $('analyse'),
  position: 'bottomLeft',
  edge: 'upperLeft',
  duration: 1
}).start();

var clickMove = new Fx.Move($('analyseauszug'), {
  relativeTo: $('text'),
  position: 'upperRight',
  edge: 'upperLeft',
  duration: 500,
  offset: {x: 10, y: 0}
  //,transition: Fx.Transitions.Quad.easeOut
});



	
	//analyseFX.hide();
	toggled = 0;

 //////console.log($defined($('analyseauszug')));
	
  	
	$('analyse').addEvent('mouseenter', function() {
	$('analyseauszug').position({
		relativeTo: $('text')
  		,position: 'upperRight'
  		,edge: 'upperLeft'
		,offset: {x: 10, y: 0}  		
  	});

	
	//$('analyseauszug').setStyle('display', 'block');
		//alert('you clicked the button');
		if(toggled == 0) {
			//alert(toggled);
			analyseFX.start(1);
			//clickMove.start();
			toggled = 1;
			$('analyse').setStyle('background-position', '0% -26px');
		}
		
	
		
		//clickMove.start();
		//else analyseMove.start('duration', 300);
	}); // ende mouseenter
	
	
	
	$('analyseauszug').addEvent('mouseleave', function() {
			//alert(toggled);
			//alert('ausblenden');
			$('analyse').setStyle('background-position', '0% 0%');
			analyseFX.start(0);
			toggled = 0;
	});
		
	

      

	//sliding tabs definition
	 //slider variables for making things easier below
 
    
    

  /* var itemsHolder = $('produktdetail');
    var myItems = $$(itemsHolder.getElements('.flasche'));
    
    
    //create instance of the slider, and start it up        
    var mySlider = new SL_Slider({
        slideTimer: 4000,
        orientation: 'horizontal',
        fade: true,
        isPaused: true,
        container: itemsHolder, numNavActive: false, 
        items: myItems
    });
    mySlider.start();*/


} //end of if type(element)

if($type($('miniproducts')) != false) {

	//tips for the horizontal mini menu 
      	var miniBottleTips = new Tips($$('div.produktklein'), {
		timeOut: 700,
		showDelay: 200,
		maxTitleChars: 50,
		maxOpacity: .6,
		fixed: false,
		className: 'miniBottleTip'
		
	});
	
	miniBottleTips.addEvent('show', function(tip, el){
	    tip.fade('0.85');
	});
	miniBottleTips.addEvent('hide', function(tip, el){
	    tip.fade('out');
	});	

}

if($type($('produktdetail')) != false) {

 




//count how many items are inside the scroller
    itemCount = $$('div.flasche').length;
    singleItemWidth = $('flasche').getStyle('width').toInt();
	//console.log(singleItemWidth);
	produktSliderWidth = itemCount * singleItemWidth + 50;	
    
    if(itemCount >= 4)
		$('produktslider').setStyle('width', 9999);
	else if (itemCount == 4 ){
		$('produktslider').setStyle('width', 4 * singleItemWidth + 50);
	}
	else if ( itemCount < 4) {
		$('produktslider').setStyle('width', itemCount * singleItemWidth + 20);
		$('produktslider').position({relativeTo: $('produktdetail')
	  		, position: 'center' 
		});
	}
	
    //$('produktdetail').setStyle('width', 4 * singleItemWidth + 20);

/**back-button produktdetaildarstellung*******/
if($type($('buttonback')) != false) {        
        btnback = $('buttonback');
        
       // btnback.setStyle('border', '1px solid black');
	btnback.setStyle('opacity', '0');
	btnback.setStyle('width', '143px');        
	btnback.setStyle('height', '25px'); 
	btnback.setStyle('display', 'block'); 
	btnback.position({relativeTo: $('produktdetail'),
		position: 'upperRight',
		edge: 'upperRight'
	});
       
	(function(){ btnback.fade('0.9') }).delay(1000);
       
       /*	btnback.addEvent('click', function() {
       		history.go(-1);
       	});*/       

}  
/***********/

	
    //if there are more than 4 items, display a scroller arrow
    if(itemCount > 4) {
        
		//how many divs need to be created?
		divCount = Math.ceil(itemCount / 4);
		//alert(divCount);
		
		//oldDivs = $$('produktslider div'); //.getElements('div');
		oldDivs = $('produktslider').getChildren().clone();
		//alert(oldDivs);
		
		//clear the product slider
		$('produktslider').empty();
		
		/*$('produktdetail').position({relativeTo: $('text')
	  		, position: 'right' 
	  		, edge: 'left'
			, offset: {x: 10, y: 0}
		});*/
				
		//alert($('produktslider'));
		
		//alert(oldDivs);
		bottleDivs = new Array();
		counter = 0;
		
		//create divCount new divs
		for (x = 0; x<divCount; x++) {
			
			//create a wrapper div for each group
			bottleWrap = new Element('div', {
			    //here you set all the element parameters
			    'class': 'groupWrapper group'+x
				, 'id': 'groupWrapper'+x
			    //'text': 'I am a new div',
			    
			});
			if(x>0) { //initially hide all groups except for the first one
				//bottleWrap.setStyle('display', 'none');
			}
			
			//place the single bottles inside the productSlider
			$('produktslider').grab(bottleWrap);
		
			//grab four of the child divs, inject them into the wrapper div	
			for(y = 0; y<4; y++) {
				//alert('y: '+y);
				//alert(oldDivs[y].innerHTML);
				//alert(counter + " / " + oldDivs[counter]);
				if(counter<oldDivs.length) {
					$('produktslider').getElements('.groupWrapper')[x].grab(oldDivs[counter], 'bottom');
				}
				//alert(bottleDivs[x].innerHTML);
				counter++;
			}
		
			
		
			
		}
		$$('.groupWrapper').setStyles({ float: 'left'});
		$$('.flasche').setStyles({ float: 'left' });
		//alert($('produktslider').getElements('.groupWrapper')[0]); 
		//alert(bottleDivs);
		//$('produktslider').inject(bottleDivs);
		
		btn = $('button');
        btnleft = $('buttonleft');



     
 		btn.setStyle('opacity', '0'); 
 	
	    btn.position({relativeTo: $('produktdetail'),
	  		position: 'centerRight',
	  		edge: 'upperRight'
		});
		
		btnleft.position({relativeTo: $('produktdetail'),
	  		position: 'centerLeft',
	  		edge: 'upperLeft'
		});
		

		
		
		$('button').setStyle('display', 'block');	
		
		(function(){ $('button').fade('0.9') }).delay(1500);
		//(function(){ $('button').highlight() }).delay(2000);

		//currentGroup holds the value of the currently visible group
		currentGroup = 0;
		var slidingTabs = new Fx.Scroll('produktdetail');
		//console.log('divcount: '+divCount);
		for (x = 0; x<divCount; x++) {
					if(x>0) {
						//console.log('positioning groupWrapper'+ x + ' relative to groupWrapper'+(x-1));
						//$('groupWrapper'+x).position({relativeTo: 'groupWrapper'+(x-1), position: 'upperRight', edge: 'upperLeft'});
						//$('groupWrapper'+x).setStyle('top', 0); //{relativeTo: 'groupWrapper'+(x-1), position: 'upperRight', edge: 'upperLeft'});
					}
		}
		
		var toggleDisplay = function() {
			if(currentGroup+arguments[0] < divCount) {
				currentGroup += arguments[0];
				
				//alert(currentGroup);
				//alert('now i switch to group '+currentGroup);	
				
				//loop over all groups, hiding them all except the current one
				/*for (x = 0; x<divCount; x++) {
					if(x>0) {
						$$('groupWrapper'+x).position({relativeTo: 'groupWrapper'+x-1, position: 'right', edge: 'left'});
						//console.log('positioning groupWrapper'+x + ' relative to groupWrapper'+x-1);
					}
				/*
					if(x != currentGroup) {
					//alert($$('.group'+x));
					//$$('.group'+x).setStyles({ display: 'none'});
					$$('.group'+x).fade('out');
					//$$('.group'+x).position({relativeTo: 'produktslider', position: 'right', edge: 'left'});
					////console.log('moving group ' + x + ' outside');
					}
					else {
					////console.log('moving group ' + x +' inside');
					$$('.group'+x).setStyles({ opacity: 0, display: 'block'});
					//$$('.group'+x).position({relativeTo: 'produktdetail', position: 'right', edge: 'left'});
					$$('.group'+x).fade('in');
					$$('.group'+x).set('move', {relativeTo:'text', position: 'rightCenter', edge: 'leftCenter',  duration: 'long', transition: 'linear', offset: {x: 10, y: 0}});
					$$('.group'+x).move();

					}
					
					
					
				}	*/	
				
			} //end of if currentgroup < divcount
			else {
				//alert('max numbers of groups reached: '+currentGroup);
			}
			slideTarget = 'groupWrapper'+currentGroup; 
			
			//console.log($(slideTarget).getPosition());
			//console.log('slide to element '+slideTarget);
			////console.log(578*currentGroupu);
			//slidingTabs.toElement(slideTarget);
			slidingTabs.start(578*currentGroup, 0);
			if(currentGroup > 0) {
						$('buttonleft').setStyle('display', 'block');
			   			 $('buttonleft').fade('0.9');
					}
					else {
						$('buttonleft').fade('out');
			   			 btn.fade('in');
					}
					if(currentGroup == divCount-1) {
						//$('buttonleft').setStyle('display', 'block');
			   			 btn.fade('out');
					}
					
					
		} //end funciton
		
		//add the click event to the buttons
		btn.addEvent('click', toggleDisplay.pass(1));
		btnleft.addEvent('click', toggleDisplay.pass(-1));
	
	

	
		
    } // end if
    
   
   //tips for each single bottle
      	var bottleTips = new Tips($$('div.flasche'), {
		timeOut: 700,
		showDelay: 600,
		maxTitleChars: 50,
		maxOpacity: .9,
		fixed: false,
		className: 'bottleTip'
		
	});

bottleTips.addEvent('show', function(tip, el){
    tip.fade('0.9');
});
bottleTips.addEvent('hide', function(tip, el){
    tip.fade('out');
});
    
    //alert(itemCount * singleItemWidth);
   //$('produktslider').setStyle('width', itemCount * singleItemWidth );

  /* var myScroller = new Scroller('produktdetail',{
   	
   	onChange: function(x,y){
   	 // $('
   	// ////console.log(x + ' ' + y);
   	 $('produktdetail').scrollTo(x,y);
   	 	if(x >= 50) { 
		   	 $('buttonleft').setStyle('display', 'block');
   			 $('buttonleft').fade('0.9');
   		 }
 
   		 else {
   			$('buttonleft').fade('out');
   		 }
   		 

   	}   
   }); 
   myScroller.start();*/

};

});

