﻿function viewPhoto(strPath)	{
	window.open('assets/viewphoto.aspx?strPath=' + strPath, 'Viewver', 'width=780, height=500, scrollbars=yes, status=yes, resizable=yes')
}

function ResizePhotoViewer(window) {
	var img = document.getElementById('imgPhoto')
	var x = img.width + 50;
	var y = img.height + 155;
	
	if (screen.availWidth<x) { 
		x = screen.availWidth - 28; 
	}
	
	window.resizeTo(x,y);
}

function showEmail(strName, strDomain, strLinkText) {
	var strEmail = strName + '@' + strDomain;
	if (!strLinkText) {strLinkText = strEmail;}
	
	document.write('<a class="email" href="mailto:' + strEmail + '">' + strLinkText + '</a>');
}

function PlayFlash(src, cssclass)	{
	document.write("<object class=\"" + cssclass + "\" type=\"application/x-shockwave-flash\" data=\"" + src + "\">")
	document.write("<param name=\"movie\" value=\"" + src + "\" />")
	document.write("</object>") 
}

function HidePhoto()	{
	document.getElementById('largeimage').style.display='none';
}

function Enlarge(photoId)	{
	if (document.getElementById('largeimage').style.display=='block')	{
		document.getElementById('largeimage').style.display='none';
	}
	else	{
		document.getElementById('imglarge').src='assets/dbphoto.aspx?tablename=CE_News&ColNameData=FileData&ColNameSize=FileSize&ColNameId=cntNewsId&id=' + photoId + '&width=500';
		document.getElementById('largeimage').style.display='block';
	}
}

function Toggle(obj)	{
	if (document.getElementById(obj).style.display=='block')	{
		document.getElementById(obj).style.display='none';
	}
	else	{
		document.getElementById(obj).style.display='none';
		document.getElementById(obj).style.display='block';
	}
}

activateMenu = function(nav) {
	if (document.all && document.getElementById(nav).currentStyle) {
		var navroot = document.getElementById(nav);
	    
		/* Get all the list items within the menu */
		var lis=navroot.getElementsByTagName("LI");  
		for (i=0; i<lis.length; i++) {
	                
			/* If the LI has another menu level */
			if(lis[i].lastChild.tagName=="UL") {
	        
				/* assign the function to the LI */
				lis[i].onmouseover=function() {	
	            
					/* display the inner menu */
					this.lastChild.style.display="block";
				}
				lis[i].onmouseout=function() {                       
					this.lastChild.style.display="none";
				}
			}
		}
    }
}

function PrintProduct(ProductId, Culture) {
	window.open('clientfiles/assets/print.aspx?productId=' + ProductId + '&culture=' + Culture, 'Print', 'width=700, height=600, top=50, left=350, scrollbars=yes, status=yes resizable=yes');
}


var intPageSize = 4;
var arrImages = new Array;

function ChangeImage(ID) {
	img = document.getElementById('product-image');
	img.src = 'clientfiles/assets/productimage.aspx?id=' + ID;
}

SetupImages = function(ID) {
	arrImages = document.getElementById(ID).getElementsByTagName("a");
	
	if (arrImages.length <= intPageSize) { document.getElementById('navigation').style.display = 'none'; } else { ShowThumbs(1); } 
}

function ShowThumbs(intPage) {
	intPage = (intPage - 1);
	
	var intStart, intEnd;
	var oPrev = document.getElementById('prev');
	var oNext = document.getElementById('next');
	var oInfo = document.getElementById('page');
	
	//Dölj bilderna
	for (i=0; i<arrImages.length; i++) {arrImages[i].style.display = 'none';}
	
	intStart = (intPage * intPageSize);
	intEnd = (intStart + intPageSize);
	
	//Kolla indexen
	if (intPage == 0) {
		oPrev.href = '#';
		oPrev.className	= 'disabled';
	} else {
		oPrev.href = 'javascript:ShowThumbs(' + (intPage) + ');';
		oPrev.className	= '';
	}
		
	if (intEnd >= arrImages.length) {
		intEnd = arrImages.length
		oNext.href = '#';
		oNext.className	= 'disabled';
	} else {
		oNext.href = 'javascript:ShowThumbs(' + (intPage+2) + ');';
		oNext.className	= '';
	}
		
	oInfo.innerHTML = (intPage+1) + '/' + Math.ceil(arrImages.length/intPageSize);

	//Visa bilderna
	for (i=intStart; i<intEnd; i++) { arrImages[i].style.display = 'block';	}
	
	oPrev.style.display = 'block';
	oNext.style.display = 'block';
}

window.onload = function() {
	if (document.getElementById('product-thumbs')) {
		SetupImages('product-thumbs');
	}
	
    activateMenu('menu'); 
}