

var __isIE = (document.all) ? true : false;
var __isNS = (document.layers) ? true : false;
  
var __isNetscape6 = (navigator.userAgent.indexOf("Netscape6") > 0) ? true: false;
var __isNetscape7 = (navigator.userAgent.indexOf("Netscape/7") > 0) ? true: false;
var __isNetscape6_0 = (navigator.userAgent.indexOf("Netscape6/6.0") > 0) ? true: false;
var __isOpera = (window.opera) ? true: false;
var __isKonquerror = (navigator.userAgent.indexOf("Konquerror") > 0) ? true: false;
var __MousePosition = new Object();
__MousePosition.xpos = 0;
__MousePosition.ypos = 0;
var __tooltipActive = false; 
var __tooltipOver = false; 
var __checkTooltip = false;
var __checkTooltipOut = false;

document.onmousemove = getMousePosition;

var __productListingPage = 0;

function getMousePosition(e) {
  __MousePosition.xpos = (__isIE) ? event.clientX :  e.pageX - window.pageXOffset;
  __MousePosition.ypos = (__isIE) ? event.clientY :  e.pageY - window.pageYOffset;
  
	if( __checkTooltip ){
		var offsetX = (typeof(window.pageXOffset) != 'undefined') ? pageXOffset : getBody(window).scrollLeft;
		var offsetY = (typeof(window.pageYOffset) != 'undefined') ? pageYOffset : getBody(window).scrollTop;
		var mousex = __MousePosition.xpos + offsetX;
		var mousey = __MousePosition.ypos + offsetY;

		__tooltipOver = ProductTooltip.isIn( mousex,mousey );
		if( __checkTooltipOut ){
			if( !__tooltipOver ) ProductTooltip.fadeOut( -0.2 );
		} else {
			if( __tooltipOver ) __checkTooltipOut = true;
		}
	} else {
		__tooltipOver = false;
		__checkTooltipOut = false;
	}
}

function getBody(w){
    return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ?
    w.document.documentElement :
    w.document.body || null;
}

function getWindowHeight () {
    var win = window;
	if(typeof win.innerHeight != 'undefined') return(win.innerHeight);
	else {
		var obj = getBody(win);
		return(parseInt(obj.clientHeight));
	}
}

function getWindowWidth () {
	var win = window;
	if(typeof win.innerWidth != 'undefined') return(win.innerWidth);
	else {
		var obj = getBody(win);
		return(parseInt(obj.clientWidth));
	}
}

/**********************/
/* CLASS TooltipDiv */
/**********************/

function TooltipDiv (id, self, width, height) {
   this.id = id;
   this.self = self;
   try {this.div = document.getElementById(id);} catch(e) { /*alert('err');*/ }
   this.fetchDiv = TooltipDivFetchDiv;
   this.fadeIn = TooltipDivFadeIn;
   this.fadeOut = TooltipDivFadeOut;
   this.showToolTip = TooltipDivShowToolTip;
   this.lock = TooltipDivLock;
   this.unlock = TooltipDivUnlock;
   this.isIn = TooltipDivIsIn;
   this.setPosition = TooltipDivSetPosition;
   this.faderThread = null;
   this.opacity = 0;
   this.width = width;
   this.height = height;
   this.left = 0;
   this.top = 0;
   this.locked = false;
   this.productIndex = -1;
}

function TooltipDivLock() {
   this.locked = true;
}

function TooltipDivUnlock() {
  this.locked = false;
}

function TooltipDivFetchDiv (property, id) {
   try {this[property] = document.getElementById(id);}
   catch (e) {;}
}

function TooltipDivFadeIn(step) {
	if (this.locked || __isNetscape6_0) {return;}
	if (this.faderThread != null) {window.clearTimeout(this.faderThread); this.faderThread = null;}
	
	var Div = this.div;
	Div.style.display = "block";
	var actOpacity = this.opacity;
	  
	if (actOpacity + step < 0.99) {
	  actOpacity += step;
	  Div.style.filter = "Alpha(Opacity="+(actOpacity * 100)+")";
	  Div.style.MozOpacity = actOpacity;
	  Div.style.KhtmlOpacity = actOpacity;
	  this.opacity = actOpacity;
	  this.faderThread = window.setTimeout(this.self+'.fadeIn('+step+')', 40);
	  return;
	} else {
	  __checkTooltip = true;
	  Div.style.filter = "Alpha(Opacity="+0.99 * 100+")";
	  Div.style.MozOpacity = 0.99;
	  Div.style.KhtmlOpacity = 0.99;
	  this.opacity = 0.99;
	}

}

function TooltipDivFadeOut(step) {
	__tooltipActive = false;
	__checkTooltip = false;
	if (this.locked || __isNetscape6_0) {return;}
	if (this.faderThread != null) {window.clearTimeout(this.faderThread); this.faderThread = null;}
	var Div = this.div;
	var actOpacity = this.opacity;
	this.productIndex = -1;

	if (actOpacity + step > 0) {
	  actOpacity += step;
	  Div.style.filter = "Alpha(Opacity="+(actOpacity * 100)+")";
	  Div.style.MozOpacity = actOpacity;
	  Div.style.KhtmlOpacity = actOpacity;
	  Div.style.display = "block";
	  this.opacity = actOpacity;
	  this.faderThread = window.setTimeout(this.self+'.fadeOut('+step+')', 40);
	  return;
	} else {
	  this.prodName.innerHTML = '&nbsp;';
	  this.prodImage.innerHTML = '&nbsp;';
	  this.prodPrice.innerHTML = "&nbsp;";
	  this.opacity = 0;
	  this.prodDescription.innerHTML = "&nbsp;";
	  Div.style.display = "none";
	  Div.style.filter = "Alpha(Opacity="+0+")";
	  Div.style.MozOpacity = 0;
	  Div.style.KhtmlOpacity = 0;
	}

}

function TooltipDivIsIn(left, top) {
   var isIn = ((left >= this.left) && (left <= this.left+this.width) && (top >= this.top) && (top <= this.height+this.top)) ? true : false;
   return (isIn);
}

function TooltipDivSetPosition() {
    
    // --------------------------------------------------
    // Tooltip Position
    // --------------------------------------------------
    
	var actWidth = getWindowWidth();
	var actHeight = getWindowHeight();
	var offsetX = (typeof(window.pageXOffset) != 'undefined') ? pageXOffset : getBody(window).scrollLeft;
	var offsetY = (typeof(window.pageYOffset) != 'undefined') ? pageYOffset : getBody(window).scrollTop;
	
	if (__MousePosition.ypos + this.height + 10 < actHeight) {
	  this.top = __MousePosition.ypos + 10 + offsetY;
	} else if (__MousePosition.ypos - this.height - 10 >= 0) {
	  this.top = __MousePosition.ypos - this.height - 10 + offsetY;
	} else {
	  this.top = actHeight - this.height - 10 + offsetY;
	}

	if (__MousePosition.xpos + this.width + 10 < actWidth) {
	  this.left = __MousePosition.xpos + 10 + offsetX;
	} else if (__MousePosition.xpos-this.width - 10 >= 0) {
	  this.left = __MousePosition.xpos - this.width - 10 + offsetX;
	} else {
	  this.left = actWidth - this.width - 10 + offsetX;
	}
   
	this.div.style.left = this.left+'px';
	this.div.style.top = this.top+'px';
}

function TooltipDivShowToolTip(productlist, index) {
	//if( __tooltipOver ) return;
	if( __tooltipActive && index == this.productIndex ) return;
	this.productIndex = index;
	
	var produkt = productlist[index];
	var Div = this.div;
	Div.style.display = 'block';
	Div.style.width = this.width + 'px';
	//Div.style.height = this.height + 'px';
	
	// füllen
	if (produkt.name != '') this.prodName.innerHTML = produkt.name;
	else this.prodName.innerHTML = '&nbsp;';

	this.prodName.innerHTML = '<a href="'+produkt.link+'"> '+produkt.name+ '</a>';
	this.prodImage.innerHTML = produkt.image;
	this.prodPrice.innerHTML = produkt.price;
	this.prodDescription.innerHTML = produkt.description_short;
    
    var button_html = '<div class="infobox_button" style="width:180px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
	button_html += '<td class="infobox_button_left"><img src="/templates/default/images/spacer.gif" alt="" border="0"  height="6" width="6" /></td>';
	button_html += '<td class="infobox_button_right"><a class="infobox_button" href="#LINK#">#TEXT#</a></td>';
	button_html += '</tr></table></div>';
	
	var buttons = '';
	var button = '';
	
	button = button_html;
	button = button.replace(/#LINK#/g, produkt.link);
	if( str_details ) button = button.replace(/#TEXT#/g, str_details);
	else button = button.replace(/#TEXT#/g, 'Details');
	buttons += button;
	
	button = button_html;
	button = button.replace(/#LINK#/g, produkt.link_buy_now);
	if( str_order_now ) button = button.replace(/#TEXT#/g, str_order_now);
	else button = button.replace(/#TEXT#/g, 'Jetzt Bestellen');
	buttons += button;
	
	button = button_html;
	button = button.replace(/#LINK#/g, produkt.link_shopping_list);
	if( str_to_list ) button = button.replace(/#TEXT#/g, str_to_list);
	else button = button.replace(/#TEXT#/g, 'Merken');
	//buttons += button;
	
	
    this.prodButtons.innerHTML = buttons;
    
    this.height = Div.offsetHeight;
    this.setPosition();
	
   this.fadeIn(0.2);
   
}

function Produkt(link, link_buy_now, link_shopping_list, name, image, description_short, price ) {
	this.link = link;
	this.link_buy_now = link_buy_now;
	this.link_shopping_list = link_shopping_list;
	this.name = name;
	if( image == '' ){
		if( alternate_thumbnail ){
			this.image = '<img border="0" src="'+alternate_thumbnail+'" alt="'+this.name+'" title="'+this.name+'" />';
		} else {
			this.image = this.name;
		}
	} else {
		this.image = image;
	}
	this.description_short = description_short;
	this.price = price;
}

function TooltipInit(){
	ProductTooltip = new TooltipDiv('TooltipDiv', 'ProductTooltip', 360, 400);
	ProductTooltip.fetchDiv('prodName', 'TooltipProdName');
	ProductTooltip.fetchDiv('prodImage', 'TooltipProdImage');
	ProductTooltip.fetchDiv('prodPrice', 'TooltipProdPrice');
	ProductTooltip.fetchDiv('prodDescription', 'TooltipProdDescription');
	ProductTooltip.fetchDiv('prodButtons', 'TooltipButtons');
}

function buildProductPreviews( productlist, index, perpage ) {
	var perrow = 5;
	var rows = Math.ceil((productlist.length)/perrow);
	
	if( productlist.length > perpage ) {
		var html = '<table width="100%" border="0" cellspacing="0" cellpadding="10">';
		for( var r=0; r<rows; r++ ){
			if( r != __productListingPage ){
				var iStart = r * perrow;
				
				var iMax = (iStart+perrow);
				if( iMax > productlist.length ) iMax = productlist.length;
				
				// text: artikel anzeigen
				var str_nav = str_pagenav_show_products;
				str_nav = str_nav.replace(/#FROM#/g, (iStart+1));
				str_nav = str_nav.replace(/#TO#/g, (iMax));
				//
				
				html += '<tr>';
				html += '<td class="productpreviews-row" align="left" valign="top" nowrap>';

				
				html += '<a class="productpreviews" href="javascript:buildProductListing(ReptilicaProducts, '+r+', 5);">'+str_nav+'</a>';
				html += '</td>';
				html += '</tr>';
				
				html += '<tr>';
				
				var column = 0;
				html += '<td class="productpreviews-row" align="left" valign="top">';
				for( var i=iStart; i<iStart+perrow; i++ ){
					var padding = column == 0 ? '10px' : '0px';
					column++;
					//html += '<td class="productpreviews-row" align="left" valign="top" style="padding-left:'+padding+';" >';
					if( i<productlist.length ){
						var produkt = productlist[i];
						html += '<a class="productpreviews" href="'+(produkt.link)+'" onMouseOver="ProductTooltip.showToolTip(ReptilicaProducts,'+i+');">'+(produkt.image)+'</a>';
					} else {
						html += '&nbsp;';
					}
					//html += '</td>';
				}
				html += '</td>';
				html += '</tr>';
			}
			var produkt = productlist[i];
		}
		html += '</table>';
	}
	
	var el = document.getElementById('ProductPreviewsDiv');
	if( el ) el.innerHTML = html;
	
	var el = document.getElementById('ProductPreviewsContainer');
	if( el ) el.style.display = 'block';
}

function buildProductListing( productlist, index, perpage ) {
	ProductTooltip.fadeOut(-0.2);
	
	if( index * perpage > productlist.length-1 ){
		index = Math.floor((productlist.length-1)/perpage);
	}
	if( index < 0 ) index = 0;
	var iStart = index * perpage > productlist.length-1 ? productlist.length-1 : index * perpage;
	var iEnd = iStart + perpage > productlist.length ? productlist.length : iStart + perpage;
	__productListingPage = index;
	
	var button_html = '<div class="infobox_button" style="margin-top:0px; margin-bottom:4px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
	button_html += '<td class="infobox_button_left"><img src="/templates/default/images/spacer.gif" alt="" border="0"  height="6" width="6" /></td>';
	button_html += '<td class="infobox_button_right"><a class="infobox_button" href="#LINK#">#TEXT#</a></td>';
	button_html += '</tr></table></div>';
	
	var button = '';
	
	var html = '<table width="100%" border="0" cellspacing="0" cellpadding="10">';
	for( var i=iStart; i<iEnd; i++ ){
		var produkt = productlist[i];
		
		html += '<tr>';
		html += '<td class="productlisting-row" align="left" valign="top">';
		//html += '<a class="productlisting-name" href="'+(produkt.link)+'" onMouseOver="ProductTooltip.showToolTip(ReptilicaProducts,'+i+');">'+(produkt.image)+'</a>';
		html += '<a class="productlisting-name" href="'+(produkt.link)+'">'+(produkt.image)+'</a>';
		html += '</td>';
		html += '<td class="productlisting-row" align="left" valign="top"><a class="productlisting-name" href="'+produkt.link+'">'+(produkt.name)+'</a>';
		html += '<div style="margin-top:10px;">'+(produkt.description_short)+'</div>';
		html += '</td>';
		html += '<td class="productlisting-row" align="right" valign="top"><span class="productlisting-price" >'+(produkt.price)+'</span></td>';
		html += '<td class="productlisting-row" align="right" valign="top">';
		html += '<div style="width:180px;">';
		
		button = button_html;
		button = button.replace(/#LINK#/g, produkt.link);
		if( str_details ) button = button.replace(/#TEXT#/g, str_details);
		else button = button.replace(/#TEXT#/g, 'Details');
		html += button;

		button = button_html;
		button = button.replace(/#LINK#/g, produkt.link_buy_now);
		if( str_order_now ) button = button.replace(/#TEXT#/g, str_order_now);
		else button = button.replace(/#TEXT#/g, 'Jetzt Bestellen');
		html += button;

		button = button_html;
		button = button.replace(/#LINK#/g, produkt.link_shopping_list);
		if( str_to_list ) button = button.replace(/#TEXT#/g, str_to_list);
		else button = button.replace(/#TEXT#/g, 'Merken');
		//html += button;
	
		html += '</div>';
		html += '</td>';
		html += '</tr>';
	}
	
	html += '</table>';
	
	var el = document.getElementById('ProductListingDiv');
	el.innerHTML = html;
	
	var page = index + 1;
	var pages = Math.ceil((productlist.length-1)/perpage);
	el = document.getElementById('ProductListingPageinfo');

	// text: pagenav
	var str_nav = str_pagenav_products;
	str_nav = str_nav.replace(/#FROM#/g, (iStart+1));
	str_nav = str_nav.replace(/#TO#/g, (iEnd));
	str_nav = str_nav.replace(/#TOTAL#/g, (productlist.length));
	//
				
	el.innerHTML = str_nav;
	
	el = document.getElementById('ProductListingPagenav');
	var pagenav = '&nbsp;';
	if( iStart > 0 ) pagenav += '<a href="javascript:prevProductListing(ReptilicaProducts);">&lt;&lt;</a>';
	
	if( iEnd < productlist.length-1 ) {
		if( pagenav != '' ) pagenav += ' &nbsp; ';
		pagenav += '<a href="javascript:nextProductListing(ReptilicaProducts);">&gt;&gt;</a>';
	}
	
	el.innerHTML = pagenav;
	
	if( productlist.length > perpage ) {
		buildProductPreviews( productlist, index, perpage );
	}
}

function nextProductListing(productlist){
	__productListingPage ++;
	buildProductListing(productlist, __productListingPage, 5);
}

function prevProductListing(productlist){
	__productListingPage --;
	buildProductListing(productlist, __productListingPage, 5);
}



function ProductImageFadeIn(step) {
	if ( __isNetscape6_0 ) { return; }
	if ( faderThread != null ) { window.clearTimeout( faderThread ); faderThread = null; }
	
	var Div = document.getElementById('productImageDiv');
	var actOpacity = fadeOpacity;
	  
	if (actOpacity + step < 0.99) {
	  actOpacity += step;
	  Div.style.filter = "Alpha(Opacity="+(actOpacity * 100)+")";
	  Div.style.MozOpacity = actOpacity;
	  Div.style.KhtmlOpacity = actOpacity;
	  fadeOpacity = actOpacity;
	  faderThread = window.setTimeout('ProductImageFadeIn('+step+')', 40);
	} else {
	  Div.style.filter = "Alpha(Opacity="+0.99 * 100+")";
	  Div.style.MozOpacity = 0.99;
	  Div.style.KhtmlOpacity = 0.99;
	  fadeOpacity = 0.99;
	}

}

function ProductImageFadeOut(step) {
	if ( __isNetscape6_0 ) { return; }
	if ( faderThread != null ) { window.clearTimeout( faderThread ); faderThread = null; }
	
	var Div = document.getElementById('productImageDiv');
	var actOpacity = fadeOpacity;

	if (actOpacity + step > 0) {
	  actOpacity += step;
	  Div.style.filter = "Alpha(Opacity="+(actOpacity * 100)+")";
	  Div.style.MozOpacity = actOpacity;
	  Div.style.KhtmlOpacity = actOpacity;
	  Div.style.display = "block";
	  fadeOpacity = actOpacity;
	  faderThread = window.setTimeout('ProductImageFadeOut('+step+')', 40);
	} else {
	  fadeOpacity = 0;
	  Div.style.filter = "Alpha(Opacity="+0+")";
	  Div.style.MozOpacity = 0;
	  Div.style.KhtmlOpacity = 0;
	  Div.innerHTML = nextImage;
	  faderThread = window.setTimeout('ProductImageFadeIn(0.2)', 40);
	}

}

