var clipTop = 0;
var clipWidth = 750;
var clipBottom = 340;
var topper = 0;
var lyrheight = 0;
var time,amount,theTime,theHeight,DHTML;

var acturl = '';
var actobj = new Object();

function init() {

	// Rechstklick auf Bilder verhindern
	jQuery('img').live('mousedown contextmenu',function(e) {
		if(e.which == 2 || e.which == 3) {	
			if(!e.isDefaultPrevented()) {
				alert('Nicht erlaubt.');
			}
			e.preventDefault();		
			return false;
		} else {
			return true;
		}
	});
	
	/*var href = jQuery('.com-list-image>a').attr('href');
	var pos = href.lastIndexOf("&md5=");
	if(pos > 5) {
		jQuery('.com-list-image>a').attr('href',href.substr(0,pos));
	}*/
	
	if(document.getElementById('scrollcontainer')){
		DHTML = (document.getElementById || document.all || document.layers)
		if (!DHTML) return;
		var x = new getObj('scrollcontainer');
		if (document.layers)
		{
			lyrheight = x.style.clip.bottom;
			lyrheight += 20;
			x.style.clip.top = clipTop;
			x.style.clip.left = 0;
			x.style.clip.right = clipWidth;
			x.style.clip.bottom = clipBottom;
		}
		else if (document.getElementById || document.all)
		{
			lyrheight = x.obj.offsetHeight;
			x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		}
	
		if(lyrheight <= clipBottom+topper){
		
	
			var scroll = new getObj('scrollelemente');
			scroll.style.visibility = 'hidden';	
		}else{
		
			 if (window.addEventListener)
	
		        window.addEventListener('DOMMouseScroll', wheel, false);
	
			window.onmousewheel = document.onmousewheel = wheel;	 	
		}
	}
}

function scrollayer(layername,amt,tim)
{
	layername = 'scrollcontainer';

	tim = 75;
	amt = amt*2;
	
	
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 || clipBottom > lyrheight)
	{
	 	clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return; 
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper + 'px';
	}
	else if (document.layers)
	{
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}
	time = setTimeout('realscroll()',theTime);
}

function stopscroll()
{
	if (time) clearTimeout(time);
}


function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function handle(delta) {
        if (delta < 0){
			scrollayer('scrollcontainer',10,100);
			stopscroll();
		}
        else if(delta > 0){
			scrollayer('scrollcontainer',-10,100);
			stopscroll();
		}
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}



function toggleProduct(id){
		el = document.getElementById(id);		
		if(el.value == ""){
			el.value = 1;	
document.getElementById("button_"+el.name).className = "clickbox1";			
		}
		else{
			el.value = "";				
document.getElementById("button_"+el.name).className = "clickbox0";			
		}
}

function switchProduct(id){
	element = document.getElementById('tx_commerce_pi1[artAddUid]['+id+'][count]');	
	if(element.value == ""){
			element.value = 1;
			document.getElementById("button_"+id).className = "product_selected";			
		}
		else{
			element.value = "";
			document.getElementById("button_"+id).className = "product_select";					
		}	
}



function setURL(obj){
      select(obj);	
      acturl = arr[obj.id];
      document.location.href = acturl; 
}

function select(obj){
      if(obj.className == 'selected'){
          obj.className = 'select';
      }else{
          actobj.className = 'select';
          actobj = obj;
          obj.className = 'selected';
      }
}

function jumpURL(id){
      acturl = arr[id];
      document.location.href = acturl; 
}

function homeListener(){
	if(jQuery('a.home_select')){
		jQuery('a.home_select').click(
		function(){
			val = jQuery(this).attr('rel');
			if(val)
				document.location.href = 'index.php?id='+val;
			else return true;
		}
	);}
}

jQuery.noConflict();
jQuery(init);
jQuery(homeListener);
