var ViewIndexes = new Array();
var ViewBinaryCodeIDs = new Array();
var VisibleHeight = 10;
var QuickViewBilderArray = new Array();
var QuickviewAllreadyMoved = false; // Unterdrückt den Quickview bis er korrekt positioniert wurde (also nach dem Laden der Seite)

function checkScrolling()
{
	// Alte Funktionalität des Quickviews für den IE5/IE6
	if (IEBUG == true)
	{
		currentVisibleHeight = getVisibleHeight();
		
		if(VisibleHeight != currentVisibleHeight)
		{
			VisibleHeight = currentVisibleHeight;
			moveQuickViewContent();
		} // if(VisibleHeight != currentVisibleHeight)
	} // if (IEBUG == true)
} // function checkScrolling()

function moveQuickViewContent() 
{
	// Alte Funktionalität des Quickviews für den IE5/IE6
	var Element = document.getElementById('QuickViewContent');
	Element.style.position='absolute';
	
	var height = getVisibleHeight()+50;
	Element.style.marginTop = height+"px";
	
	return true;
} // function moveQuickViewContent() 
    
function getVisibleHeight ()
{
	// Alte Funktionalität des Quickviews für den IE5/IE6
	return document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
} // function getVisibleHeight ()

function moveQuickView()
{
	var NaviTable = document.getElementById('NaviTable');
	var QuickViewContent = document.getElementById('QuickViewContent');
	
	if(NaviTable)
	{	
		if (QuickViewContent)
		{	
			TablePosition = getAbsoluteElementPosition(NaviTable);
			QuickViewContent.style.left = TablePosition.x - 84 + "px";
		}
	}
	
	// Quickview wurde soeben positioniert also darf er ab jetzt
	// angezeigt werden...
	QuickviewAllreadyMoved = true;
}

function showQuickView(tnid, description, bcid, sizes, color)
{
	// Quickview-Div Position ist noch links am Rand, also noch nicht
	// anzeigen...
	if (QuickviewAllreadyMoved == false)
		return true;

	// Wenn ein Quickview geöffnet werden alle MainNavi SubMenus schließen, falls vorhanden und geöffnet
	var SubMenus = new Array('ShopImageSub','BrandneuImageSub','BrandsImageSub','SaleImageSub','BlogImageSub');
	for (var i = 0; i < SubMenus.length; i++) 
	{
		var SubMenu = document.getElementById(SubMenus[i]);
		if(SubMenu)
			if(SubMenu.style.display=='')
				SubMenu.style.display='none';
	} // for (var i = 0; i < SubMenus.length; i++)

	// SearchSuggestLayer schließen wenn Quickview geöffnet werden soll
	var sLayer = document.getElementById('suggestLayer');
	if (sLayer)
	{
		if (sLayer.style.display=='block')
			sLayer.style.display='none';
	} // if (sLayer)

	//Pfeil-Divs positionieren
	var Table = document.getElementById('view'+tnid); // Table mit Produktbild
	if (Table)
	{
		var MyPos = getAbsoluteElementPosition(Table); // Posi der Table ermitteln
		
		var TableWidth=parseInt(Table.style.width); // Breite der Table ermitteln
		var TableHeight=parseInt(Table.style.height); // Höhe der Table ermitteln
		
		TableHeight=(TableHeight/2); // Die Hälfte der Höhe ermitteln
		TableHeight= (TableHeight-13); // Den 25 Pixel hohen Pfeil zur Hälfte über dem Mittelpunkt der Tabelle plazieren
		
		var LeftDiv = document.getElementById('left'+tnid);
		if (LeftDiv)
		{
			LeftDiv.style.top=(MyPos.y+(TableHeight))+'px';
			LeftDiv.style.left=(MyPos.x+1)+'px';
		} // if (LeftDiv)
		
		var RightDiv = document.getElementById('right'+tnid);
		if (RightDiv)
		{
			RightDiv.style.top=(MyPos.y+(TableHeight))+'px';
			RightDiv.style.left=(MyPos.x+(TableWidth-26))+'px';
		} // if (RightDiv)
	} // if (Table)
	
	var Bild = new Image();
	Bild.src = 'http://www.frontlineshop.com/gateTools/scripts/binary.php?BinaryCodeID=' + bcid + '&convert[-resize]=210x302';
	
	// onMouseOver - Fix
	var elem = document.getElementById('QuickViewContent');
	var HTMLCode = elem.innerHTML;
	
	if (HTMLCode.indexOf('BinaryCodeID='+bcid) > 0)
		return;
	// onMouseOver - Fix Ende
	
	var ProductForm  = '<table cellpadding="0" cellspacing="0" class="top right" style="background-color:#ffffff;width:220px;border:2px solid #747474;">';
	ProductForm += '<tr><td class="top right">';
	ProductForm += '	<table cellpadding="0" cellspacing="0" style="margin:5px;"';
	ProductForm += '		<tr><td class="top" style="text-align:left;">';
	ProductForm += '	<table cellpadding="0" cellspacing="0" style="background-image:url(\'http://www.frontlineshop.com/customGates/resources/binaries/universal/backgrounds/please-wait.gif\');';
	ProductForm += 'background-repeat:no-repeat;width:210px;height:302px;">';;
	ProductForm += '		<tr><td class="top">';
	
	if(bcid)
		bgImage = 'http://www.frontlineshop.com/gateTools/scripts/binary.php?BinaryCodeID=' + bcid + '&amp;convert[-resize]=210x302';
	else	
		bgImage = 'http://www.frontlineshop.com/customGates/resources/binaries/de_DE/special/nopic/quick_view.gif';
	
	
	ProductForm += '		<div id="QuickViewImage" style="background-image:url(\''+ bgImage +'\');background-repeat:no-repeat;width:210px;height:301px;">&nbsp;</div>';
	ProductForm +='		</td>';
	ProductForm +='	</tr>';
	ProductForm +='</table>';

		
		
		// ProductForm += '<div id="QuickViewImage" class="border_grey_3" style="background-image:url(\''+ bgImage +'\');background-repeat:no-repeat;width:210px;height:301px;">&nbsp;</div>';
		//ProductForm += '<img id="QuickViewImage" src="http://www.frontlineshop.com/gateTools/scripts/binary.php?BinaryCodeID=' + bcid + '&amp;convert[-resize]=210x302"  class="border_grey_3" >';
		ProductForm += '<div class="gross bold" style="margin-top:5px;">' + description + '</div>';
		ProductForm += '<div>';
		
		if(color.length > 0)
			if(color != 'no color' && color != 'no colour')
				ProductForm += '<div style="margin-top:3px;"><span class="bold klein">Farbe:</span> <span class="klein">' + color + '</span></div>';
			
		if(sizes.length > 0)
			ProductForm += '<div class="bold klein" style="margin-top:3px;margin-bottom:4px;">Verfügbare Größen:</div>';
		
		var sizesPerLine = 0;
		var charsPerLine = 0;
		
		for(var i = 0; i < sizes.length; i++)
		{
			sizesPerLine++;
			
			if( ( (charsPerLine + sizes[i].length) * 6 + sizesPerLine * 12) > 160)
			{
				charsPerLine = 0;
				sizesPerLine = 0;
				ProductForm += '</div>';
			}
			
			if(charsPerLine == 0)
				ProductForm += '<div style="margin-bottom:2px;background-color:#f4f4f4;">';
				
			charsPerLine += sizes[i].length;
			ProductForm += ' <span style="padding:0px 3px 0px 3px;">' + sizes[i];
			
			// Wenn noch mindestens ein Element kommt
			if ((sizes.length-1) > i)
			{
				// Wenn als nächstes kein Zeilenumbruch eingefügt werden soll dann Trennslash anfügen
				if( ( (charsPerLine + sizes[(i+1)].length) * 6 + sizesPerLine * 12) < 160)
					ProductForm += ' / ';
			} // if ((sizes.length-1) > i)
			
			ProductForm += ' </span>';
		} // foreach ($_REQUEST['Sizes'] as $Size)
			
		ProductForm +=' 							</div></div>';

		ProductForm +='</div>';

		ProductForm +='					</td>';
		ProductForm +='				</tr>';
		ProductForm +='			</table>';	
		ProductForm +='		</td>';
		ProductForm +='	</tr>';
		ProductForm +='</table>';
		
		var elem = document.getElementById('QuickViewContent');
		elem.innerHTML = ProductForm;
		
		var elem = document.getElementById('PrevQuickView' + tnid);
		if(elem)
		{
			elem.src = 'http://www.frontlineshop.com/customGates/resources/binaries/universal/buttons/last_view.png';
		
			var elem = document.getElementById('NextQuickView' + tnid);
			elem.src = 'http://www.frontlineshop.com/customGates/resources/binaries/universal/buttons/next_view.png';
		}
} // function showQuickView(tnid, description, bcid, sizes)


function closeQuickView(tnid, event)
{
	// OnMouseOut Fix
	try
	{
		var toElement = null;
		if (event.relatedTarget)
			toElement = event.relatedTarget;
		else if (event.toElement)
			toElement = event.toElement;
			
		var cnt = 0;	
		var ShouldBe = 'view'+tnid;
			
		while (toElement)
		{
			toElement = toElement.parentNode;
			if(toElement && toElement.id == ShouldBe)
			{
				cnt++;
			}	
		}
		
		if (cnt >= 1)
			return;
	}
	catch(e)
	{
		//Nix
	}

	// OnMouseOut Fix Ende
	
	var elem = document.getElementById('QuickViewContent');
	elem.innerHTML = "";
	
	var elem = document.getElementById('PrevQuickView' + tnid);
	if(elem)
	{
		elem.src = 'http://www.frontlineshop.com/customGates/resources/binaries/universal/empty.gif';
		elem.blur();
	
		var elem = document.getElementById('NextQuickView' + tnid);
		elem.src = 'http://www.frontlineshop.com/customGates/resources/binaries/universal/empty.gif';
		elem.blur();
	}
} // function closeQuickView()

function changeView(tnid, showNext, width, height, description, sizeArray, color)
{
	var identifier = 'view' + tnid;
	
	if (showNext)
		if (ViewIndexes[identifier] == (ViewBinaryCodeIDs[identifier].length - 1))
			ViewIndexes[identifier] = 0;
		else
			ViewIndexes[identifier] = ViewIndexes[identifier] + 1;
	else
		if (ViewIndexes[identifier] == 0)
			ViewIndexes[identifier] = (ViewBinaryCodeIDs[identifier].length - 1);
		else
			ViewIndexes[identifier] = ViewIndexes[identifier] - 1;
		
	var ViewsBCID = ViewBinaryCodeIDs[identifier][ViewIndexes[identifier]];		
				
	// Bild wechseln
	var el = document.all ? document.all[identifier] : document.getElementById(identifier);
	//el.style.backgroundImage = 'url(http://www.frontlineshop.com/gateTools/scripts/binary.php?BinaryCodeID=' + ViewsBCID + '&convert[-resize]=' + width + 'x' + height + ')';
	el.onmouseover = function()
		{
			showQuickView(tnid, description, ViewsBCID, sizeArray, color);
		};
		
	var el = document.all ? document.all['QuickViewImage'] : document.getElementById('QuickViewImage');
	el.style.backgroundImage = 'url(http://www.frontlineshop.com/gateTools/scripts/binary.php?BinaryCodeID=' + ViewsBCID + '&convert[-resize]=210x302)';
	//el.src= 'http://www.frontlineshop.com/gateTools/scripts/binary.php?BinaryCodeID=' + ViewsBCID + '&convert[-resize]=210x302';
	
} // changeView(tnid, showNext, width, height, description, sizeArray)
