/* ObjectScroller */
var clickForIframe = 0;
var ObjectScrollerMethods = {
	pixelBase: '',
	contentElement: null,
	buttonUp: null,
	buttonDown: null,
	imageEvent: new Object(),
	ScrollPx:0,
	imageCount:0,
	imageon : new Array(),
	clearNoDisplay:false,
	delta:0,
	clearMouseWheel : function(deltaWert)	{ if(deltaWert < 0) { delta = -1 * (deltaWert  / deltaWert); } else { delta = deltaWert  / deltaWert; } if(Prototype.Browser.Gecko) { delta = -1 * delta;	 }	return delta; }			
};

var ObjectScroller = Class.create(ObjectScrollerMethods, {
  initialize: function(contentElement, toScrollElement, buttonUp, buttonDown, defaultStepweite, pixelBaseStr) {
  	ObjectScrollerMethods.pixelBase = pixelBaseStr;
  	ObjectScrollerMethods.contentElement = contentElement;
  	ObjectScrollerMethods.toScrollElement = toScrollElement;
  	ObjectScrollerMethods.buttonUp = buttonUp;
  	ObjectScrollerMethods.buttonDown = buttonDown;
  	ObjectScrollerMethods.ScrollPx = 0;
  	ObjectScrollerMethods.clearNoDisplay = false;
  	ObjectScrollerMethods.buttonUp.observe('click', this.moveUp);
  	ObjectScrollerMethods.contentElementSize = ObjectScrollerMethods.contentElement.getDimensions(); 
  	ObjectScrollerMethods.toScrollElementSize = ObjectScrollerMethods.toScrollElement.getDimensions();
		ObjectScrollerMethods.aktivScrollMethod = ObjectScrollerMethods.initScroll;
  	ObjectScrollerMethods.schrittweite = defaultStepweite;
		if(Prototype.Browser.Gecko) { ObjectScrollerMethods.contentElement.observe('DOMMouseScroll', this.mouseWheel); } else { ObjectScrollerMethods.contentElement.observe('mousewheel', this.mouseWheel); }
		if(Prototype.Browser.Gecko) { ObjectScrollerMethods.contentElement.observe('DOMMouseScroll', this.stopEvent); } else { ObjectScrollerMethods.contentElement.observe('mousewheel', this.stopEvent); }			
  	ObjectScrollerMethods.buttonDown.observe('click', this.moveDown);
  	ObjectScrollerMethods.contentElement.observe('mousewheel', this.stopEvent);
  },
  addImage : function(imageConfigObj) { 	
		if(imageConfigObj['displayOn']) {  	
			try {
				
			var ZufallImg = 1 + 1000 *(Math.random());
			ZufallImg = Math.round(ZufallImg);
			
	  	var imageObj = new Image();
	  	imageObj.src = imageConfigObj['thumbImg'] + (document.all ? '?t=' + ZufallImg : '');
	  	imageObj.border = 0;
	  	imageObj.width 	= imageConfigObj['thumbImgSize'][0];
	  	imageObj.height = imageConfigObj['thumbImgSize'][1];
	  	imageObj.alt = '';
	  	imageObj.title = '';
	  	imageObj.className = 'alternativeImg';
	  	imageObj.id = imageConfigObj['id'];
	  	imageObj.onerror = function() {
				this.parentNode.style.display = 'none';		
	  	}
	  	imageObj.onload = function() {
	  		ObjectScrollerMethods.imageon.push(this.src);
	  		ObjectScrollerMethods.imageon = ObjectScrollerMethods.imageon.uniq();
	  		if(ObjectScrollerMethods.imageon.length > 1) {
	  			$('alternativeAnsichten').style.display = '';
	  		}	  		
	  		if(ObjectScrollerMethods.imageon.length <= 1) {
	  			$('alternativeAnsichten').style.display = 'none';
	  		}
	  		if(ObjectScrollerMethods.imageon.length > 1) {
	  			$('alternativeAnsichten').style.display = '';
	  		}
	  	}
	  	ObjectScrollerMethods.imageEvent[imageConfigObj['id']] = imageConfigObj['event'];	  	
	  	var imageListElement = new Element('div', {'id': 'li_' + imageConfigObj['id']});
	  	//Movie Background
	  	if(imageConfigObj['background'] != undefined) {
	  		imageListElement.style.backgroundImage = 'url("'+imageConfigObj['background']+'")';
	  		imageListElement.setStyle('background-repeat: no-repeat');
	  		imageListElement.setStyle('background-position: 24px 24px');
	  		imageListElement.setStyle('overflow: hidden');
	  		imageListElement.style.height = '114px';
	  		imageListElement.setStyle('margin-bottom: 4px');
	  	}	  	
	  	imageListElement.setStyle('cursor: pointer; width: 116px');
	  	imageListElement.appendChild(imageObj);
	  	imageListElement.observe('click', this.onImageClick);
	  	$('alternativeLinks').appendChild(imageListElement);
	  	//Alternative -- ICON - Start
      
	  	if(imageConfigObj['id'].indexOf('PicThumbListAlternative') != -1) {        
	  		var zoomListButton = new Element('img', { 'src':'../../Img/Product/us/zoom_button.gif' }).setStyle('position: relative; right:-10px; top:-24px; cursor: pointer;');
	  		zoomListButton.observe('click', function() {
	  			detailImageClicked();
	  		});
        if(Division != 'jewelry') // Zoom Button ausbleden - AH 01.12.2010
        {
          imageObj.parentNode.appendChild(zoomListButton);
        }	  		
	  	}	  	
	  	if(imageConfigObj['id'].indexOf('360') != -1) {
	  		var zoomListButton = new Element('img', { 'src':'../../Img/Product/us/360_view_btn.gif' }).setStyle('position: relative; right:0px; top:-24px; cursor: pointer;');
	  		imageObj.parentNode.appendChild(zoomListButton);
	  	}	  	
	  	
	  	} catch(e) {}
	  	//Alternetive -- ICON - Ende
	  	
		}
  },
  stopEvent : function(e) {
		if(!e) var e = window.event;
		
		//e.cancelBubble is supported by IE - this will kill the bubbling process.
		e.cancelBubble = true;
		e.returnValue = false;
	
		//e.stopPropagation works only in Firefox.
		if (e.stopPropagation) {
			e.stopPropagation();
			e.preventDefault();
		}
		return false;
	},  
  onImageClick : function(event) {
  	
		indexArray =  this.id.split('_');
		clickForIframe = indexArray[2];
		
		if(indexArray[1].indexOf('PicThumbListAlternative') != -1 && ProductTemplate != '_Tapete') {
			$('vergroessern').src = '../../Img/Product/us/zoom_button.gif';
		} else {
			$('vergroessern').src = '../../Img/Product/us/StandartV2/bottom-middle.gif';
		}

		
  	eval(ObjectScrollerMethods.imageEvent[this.id.replace('li_', '')]+'("'+indexArray[(indexArray.length - 1)]+'");');  	
  	if(ObjectScrollerMethods.ScrollPx == $('alternativeLinks').positionedOffset()[1]) {
  		alternativeElementToScroll.scrollDown();
  	}  	  	
  },  
  moveUp : function() {
  	if(ObjectScrollerMethods.ScrollPx == $('alternativeLinks').positionedOffset()[1]) {
  		alternativeElementToScroll.scrollUp();
  		wt_sendinfo(strLng + '.cat.ansicht.PicThumbList.scrollup', 'click');  		
  	}
  },
  reRender: function(configArray) {  	
		ObjectScrollerMethods.imageon = new Array();
		$('alternativeLinks').innerHTML = '';
		$('alternativeLinks').style.top = 0;
		ObjectScrollerMethods.ScrollPx = 0;
		ObjectScrollerMethods.imageCount = 0;
		
  	for(var i=0; i < configArray.length; ++i) { 
			this.addImage(configArray[i]);
  	}
  	if(ProductTemplate != 'SonnenbrillenV2') {
	  	for(var i=0; i < configArray.length; ++i) { 
				this.addImage(configArray[i]);
	  	}  	
  	}
  },  
  mouseWheel : function(event) {
  	delta = 0;
  	if(event.detail == 0 || event.detail == undefined || Prototype.Browser.Opera) { delta =  ObjectScrollerMethods.clearMouseWheel(event.wheelDelta); } else { delta = ObjectScrollerMethods.clearMouseWheel(event.detail); }
  	if(ObjectScrollerMethods.ScrollPx == $('alternativeLinks').positionedOffset()[1]) {
			if(delta == -1) {
				alternativeElementToScroll.scrollDown();
			} else if(delta == 1) {
				alternativeElementToScroll.scrollUp();
			}	
			wt_sendinfo(strLng + '.cat.ansicht.PicThumbList.mousewheel', 'click');	
		}	
  },
  scrollUp : function() {
  	alternativeElementToScroll.clearNoneDisplay();
		if($('alternativeLinks').positionedOffset()[1] == 0) {
			$('alternativeLinks').insertBefore($('alternativeLinks').childElements()[($('alternativeLinks').childElements().length-1)], $('alternativeLinks').childElements()[0]);
			$('alternativeLinks').setStyle('top: '+($('alternativeLinks').childElements()[0].getHeight() *-1 )+'px');
		}
		ObjectScrollerMethods.ScrollPx = $('alternativeLinks').positionedOffset()[1] + $('alternativeLinks').childElements()[0].getHeight();
		alternativeElementToScroll.scrollen(ObjectScrollerMethods.ScrollPx);  	
	},
	scrollDown : function() {
		alternativeElementToScroll.clearNoneDisplay();
		if($('alternativeLinks').positionedOffset()[1] < 0) {
			$('alternativeLinks').appendChild($('alternativeLinks').childElements()[0]);
			$('alternativeLinks').setStyle('top: 0px');
		}			
		alternativeElementToScroll.scrollen(($('alternativeLinks').childElements()[0].getHeight() * -1));
		ObjectScrollerMethods.ScrollPx = $('alternativeLinks').childElements()[0].getHeight() * -1;		
	},
	scrollen : function(topY) {		
		new Effect.Morph($('alternativeLinks'), {
		  style: 'top:'+topY+'px;',
		  duration: 0.4
		});
	},
	clearNoneDisplay : function() {
		for(var i=0; i < $('alternativeLinks').childElements().length; ++i) {
			if($('alternativeLinks').childElements()[i].style.display == 'none') {
				$($('alternativeLinks').childElements()[i].id).remove();
			}
		}	
	},
  moveDown : function() {
		if(ObjectScrollerMethods.ScrollPx == $('alternativeLinks').positionedOffset()[1]) {
			alternativeElementToScroll.scrollDown();
			wt_sendinfo(strLng + '.cat.ansicht.PicThumbList.scrolldown', 'click');
		}
  }
 });
