productpage = Object();
productpage.description = false;
productpage.product_description_menu_ul = false;

productpage.init = function() {
	
	this.description = document.getElementById('product_description');
	if(this.description == false) return false;
	
	this.product_description_menu_ul = document.getElementById('product_description_menu_ul');
	if(this.product_description_menu_ul == false) return false;
	
	this.switchToDiv(0);
};

productpage.switchActiveLinkClass = function(childNodeNum) {
	
	var childElements	= this.product_description_menu_ul.getElementsByTagName('li');
	var chLen			= childElements.length;
	var childClassName 	= '';
	
	if(childNodeNum > chLen)	childNodeNum = chLen;
	if(childNodeNum < 0)		childNodeNum = 0;
	
	for (i=0; i < chLen; i++) {
		
		childClassName = '';
		if(i == childNodeNum) childClassName = 'active';
		
		childElements.item(i).className = childClassName;
	}
	
	return true;
};


productpage.switchToDiv = function(div_num) {
	
	// var childElements	= this.description.getElementsByName('divSwitcher');	
	var chLen			= 3;
	var childState 		= 'none';
	
	if(div_num > chLen)	div_num = chLen;
	if(div_num < 1) 	div_num = 0;
	
	var counter;
	$("#product_description").each(function() {
		counter = 0;
		$(this).children(".divSwitcher").each(function() {
			if (counter == div_num) {
				$(this).show();
			} else {
				$(this).hide();
			}
			
			counter++;
	      });
	});	
/*
	for (i=0; i < chLen; i++) {
		
		childState = 'none';
		if(i == div_num) childState = 'block';
		// childElements.item(i).style.display = childState;
		
		
		$('divSwitcher')[i].style.display = childState;
		
		// childElements[i].style.display = childState;
	}
*/
	this.switchActiveLinkClass(div_num);
	return true;
	
};


/*
reflection.js for jQuery v1.03
(c) 2006-2009 Christophe Beyls <http://www.digitalia.be>
MIT-style license.
*/
(function(a){a.fn.extend({reflect:function(b){b=a.extend({height:1/3,opacity:0.5},b);return this.unreflect().each(function(){var c=this;if(/^img$/i.test(c.tagName)){function d(){var g=c.width,f=c.height,l,i,m,h,k;i=Math.floor((b.height>1)?Math.min(f,b.height):f*b.height);if(a.browser.msie){l=a("<img />").attr("src",c.src).css({width:g,height:f,marginBottom:i-f,filter:"flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+(b.opacity*100)+", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy="+(i/f*100)+")"})[0]}else{l=a("<canvas />")[0];if(!l.getContext){return}h=l.getContext("2d");try{a(l).attr({width:g,height:i});h.save();h.translate(0,f-1);h.scale(1,-1);h.drawImage(c,0,0,g,f);h.restore();h.globalCompositeOperation="destination-out";k=h.createLinearGradient(0,0,0,i);k.addColorStop(0,"rgba(255, 255, 255, "+(1-b.opacity)+")");k.addColorStop(1,"rgba(255, 255, 255, 1.0)");h.fillStyle=k;h.rect(0,0,g,i);h.fill()}catch(j){return}}a(l).css({display:"block",border:0});m=a(/^a$/i.test(c.parentNode.tagName)?"<span />":"<div />").insertAfter(c).append([c,l])[0];m.className=c.className;a.data(c,"reflected",m.style.cssText=c.style.cssText);a(m).css({width:g,height:f+i,overflow:"hidden"});c.style.cssText="display: block; border: 0px";c.className="reflected"}if(c.complete){d()}else{a(c).load(d)}}})},unreflect:function(){return this.unbind("load").each(function(){var c=this,b=a.data(this,"reflected"),d;if(b!==undefined){d=c.parentNode;c.className=d.className;c.style.cssText=b;a.removeData(c,"reflected");d.parentNode.replaceChild(c,d)}})}})})(jQuery);

//AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
// jQuery(function($) {$("img.reflect").reflect({/* Put custom options here */});});


function debug(debugContent) {
	$('#debugContent').css('display', 'block');
	$('#debugContent').html($('#debugContent').html()+'['+debugContent+'] ');
}


function setMyBumper() {
	
	var el = this;
	el.reflected			= false;
	el.isFinalized			= new Date().getTime();
	
	if($.browser.mozilla || $.browser.webkit) {
		$("a.dock-item2 img").reflect({height:0.3,opacity:0.2});
		el.reflected		= true;
	}

	el.elementDimensions 	= new Array();
	el.totalWidth			= 0;
	el.startTime			= 500;
	
	$('a.dock-item2').each(function(index) {
		var thisId	= $(this).attr('id');

		var paddingTop	= ($('#dockCanvas').height() / 2) - ($(this).height() / 2);
		$(this).css('padding-top', paddingTop);
		
		el.elementDimensions[thisId] = new Array();
		el.elementDimensions[thisId]['width'] 		= $(this).width();
		el.elementDimensions[thisId]['height']		= $(this).height();
		el.elementDimensions[thisId]['padding']		= paddingTop;
		
		el.totalWidth								+= $(this).width();
		
		$(this).css('display','none');
		el.startTime += 80;
		window.setTimeout("$('#"+$(this).attr('id')+"').fadeIn('slow');", el.startTime);
	});

	var dock2Width			= el.totalWidth + ($('a.dock-item2').length * 30);
	$('#dock2').css('width',	dock2Width);
	var dock2Left			= ($('#dockCanvas').width() / 2) - ($('#dock2').width() / 2);

	$('#dock2').css('width', dock2Width);
	$('#dock2').css('left', dock2Left);
	
	// $('a.dock-item2').css('margin-left', 2000);
	$('#ajaxLoader').fadeOut("slow");
	
	// $('#dock2').animate({ left: dock2Left }, 1000);
	// $('a.dock-item2').animate({marginLeft: 10 }, {duration: 4000});
	// $('#dock2').animate({ width: dock2Width }, 4000);
	el.isFinalized	+= 1000;	
	
	$(document).mousemove(function(e){
		var myTime	= new Date().getTime();
		if(el.isFinalized > myTime) return false;
		
		$('#mouseContent').css('top', (e.pageY - 30));
		$('#mouseContent').css('left', e.pageX - ($('#mouseContent').width() / 2) - 5 - $('#dockCanvas').offset().left);
		
		if(
				e.pageX > $('#dockCanvas').offset().left 
				&&
				e.pageX < ($('#dockCanvas').offset().left + $('#dockCanvas').width())
				&&
				e.pageY > $('#dockCanvas').offset().top 
				&&
				e.pageY < ($('#dockCanvas').offset().top + $('#dockCanvas').height())
		) {
		
			if($('#dock2').width() < $('#dockCanvas').width()) return true;
			var containerWidth	= $('#dockCanvas').width() / 2;
			var halfDock		= $('#dock2').width() / 2;
			
			// Mausposition relativ zur Mitte berechnen
			var mousePointerX	= e.pageX - $('#dockCanvas').offset().left - (containerWidth);
			if(mousePointerX < -containerWidth) mousePointerX = -containerWidth;
			if(mousePointerX > containerWidth) mousePointerX = containerWidth;
			
			// Unterschied zwischen innerem und äusserem Container
			var containerDiff	= containerWidth - halfDock;
			
			// Mausposition relativ zum Container zur Verschiebung des inneren Containers berechnen
			var elementMoveX	= ((mousePointerX * 100) / (halfDock)) / 100;
	
			// Ursprüngliche Berechnung "über den Haufen" werfen, damit die Bewegung an den Rändern
			// schneller ist als in der Mitte
			elementMoveX = elementMoveX * elementMoveX * ($('a.dock-item2').length * elementMoveX / 2);
			
			// Nicht übertreiben und Werte eingerenzen
			if(elementMoveX > 0.8) elementMoveX = 0.8;
			if(elementMoveX < -0.8) elementMoveX = -0.8;
			
			var moveXdiff		= 0;
			moveXdiff			= Math.round(elementMoveX * ($('#dock2').width() / 2));

			// Div-Position eingrenzen, damit es nicht aus dem Ruder läuft
			if(moveXdiff < containerDiff-50) moveXdiff = containerDiff-50;
			if(moveXdiff > -containerDiff+50)moveXdiff = -containerDiff+50;
			
			// Position-Left berechnen
			moveXdiff			= containerDiff - moveXdiff;
			
			$('#dock2').css('left', moveXdiff);
		}
		
	});

	
	
	$('a.dock-item2').hover(function() {

		var myTime	= new Date().getTime();
		if(el.isFinalized > myTime) return false;

		var thisId = $(this).attr('id');

		// Tooltip befüllen und einblenden
		$('#mouseContent').text($('#'+thisId+' span.itemText').text());
		$('#mouseContent').css('display','block');
		
		var wmax =  Math.round(el.elementDimensions[thisId]['width'] * 1.2);
		var hmax =  Math.round(el.elementDimensions[thisId]['height'] * 1.2);
		var pmax =  Math.round(el.elementDimensions[thisId]['padding'] * 0.8);

		$('#'+thisId).stop().animate({'paddingTop': pmax }, 500);
		if(el.reflected) {
			$('#'+thisId+' span.reflect').stop().animate({ width: wmax, height:hmax }, 500);
			$('#'+thisId+' span.reflect img').stop().animate({ width: wmax }, 500);
			$('#'+thisId+' span.reflect canvas').stop().animate({ width: wmax }, 500);
		} else {
			$('#'+thisId+' img').stop().animate({ width: wmax, height:hmax }, 500);
		}
		
	}, function() {

		var myTime	= new Date().getTime();
		if(el.isFinalized > myTime) return false;

		var thisId = $(this).attr('id');
		
		// Tooltip verbergen
		$('#mouseContent').css('display','none');

		var wmin 	= el.elementDimensions[thisId]['width'];
		var hmin 	= el.elementDimensions[thisId]['height'];
		var pmin 	= el.elementDimensions[thisId]['padding'];
	
		$('#'+thisId).stop().animate({ 'paddingTop': pmin }, 500);
		if(el.reflected) {
			$('#'+thisId+' span.reflect').stop().animate({ width: wmin, height:hmin }, 500);
			$('#'+thisId+' span.reflect img').stop().animate({ width: wmin }, 500);
			$('#'+thisId+' span.reflect canvas').stop().animate({ width: wmin }, 500);
		} else {
			$('#'+thisId+' img').stop().animate({ width: wmin, height:hmin }, 500);
		}
	});
}


