/*
 * JS
 */

var Liegruppen = new Object();
var images;
var originalImage = '';
var originalIamgeonClick = '';
originalImageHTML = '';
var index = 0;

Liegruppen.Images =
{
	init : function(pageImages)
	{
		var div, photocontainer;
		var moreImages = document.getElementById('moreImages');
		if (moreImages) {
			document.getElementById('moreImages').onclick = Liegruppen.Images.showMoreImages;
		}
		if (document.getElementById('specLink')) {
			document.getElementById('specLink').onclick = Liegruppen.Images.toggleSpec;
		}
		images = pageImages; // images.length 
		images.length = images.length-1; // adder ALLTID et tomt bilde på slutten pga "kommaproblem"" i mal
		//photocontainer = document.getElementById('photocontainer');
		//originalImage = photocontainer.src;
		//originalImageonClick = photocontainer.onclick;
		originalImageHTML = document.getElementById('mainphoto').innerHTML;
		
 	},
	toggleSpec : function(e)
	{
		
		
		if( document.getElementById('specsContainer').style.display == 'block' )
		{
			document.getElementById('specsContainer').style.display = 'none';
			
			t = document.getElementsByTagName('div');
			for(tri = 0;tri < t.length;tri++)
			{
				switch( t[tri].className )
				{
					case 'infobox1':
						t[tri].style.display = 'block';
						break;
				}
			}
		}
			
		else
		{
			document.getElementById('specsContainer').style.display = 'block';
			t = document.getElementsByTagName('div');
			for(tri = 0;tri < t.length;tri++)
			{
				switch( t[tri].className )
				{
					case 'infobox1':
						t[tri].style.display = 'none';
						break;
				}
			}
		}
	},
	showMoreImages : function(e)
	{
		index = 0;
		var photocontainer = document.getElementById('photocontainer');
		document.getElementById('navContainer').innerHTML = '';

		var img = document.createElement('img');
		img.src= '/sitefiles/2/design/arrow_previous.png';
		img.id = 'prevImage';
		img.onclick = Liegruppen.Images.prevImage
		document.getElementById('navContainer').appendChild(img);
		img = document.createElement('img');
		img.src= '/sitefiles/2/design/arrow_next.png';
		img.id = 'nextImage';
		img.onclick = Liegruppen.Images.nextImage
		document.getElementById('navContainer').appendChild(img);
		if(images.length > 1 )
		{	
			document.getElementById('mainphoto').innerHTML = '';
			if(images[index][2] == 1)
			{
				document.getElementById('mainphoto').innerHTML = '<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="206" HEIGHT="122" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"><PARAM name="SRC" VALUE="'+images[index][0]+'"><PARAM name="AUTOPLAY" VALUE="true"><PARAM name="CONTROLLER" VALUE="false"><embed width="206px" height="122px" scale="ToFit" controller="false" name="plugin"  PLUGINSPAGE="http://www.apple.com/quicktime/download/" src="'+images[index][0]+'" type="video/quicktime" ></embed></OBJECT>';
				//document.getElementById('mainphoto').innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="206px" height="122px" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="'+images[index][0]+'"><param name="autoplay" value="true"><param name="controller" value="false">';				
				//document.getElementById('mainphoto').innerHTML = '<embed width="206px" height="122px" scale="ToFit" controller="false" name="plugin" pluginspage="http://www.apple.com/quicktime/download/" src="'+images[index][0]+'" type="video/quicktime" />';
			}
			else
			{
				var img = document.createElement('img');
				img.src = images[index][0];	
				img.id = "photocontainer";		
				img.onclick = function() { productPopup(1,images[index][1],455,760,0,0); };
				document.getElementById('mainphoto').appendChild(img);
			}
			if( index == images.length )
				document.getElementById('nextImage').src = '/sitefiles/2/design/arrow_nonext.png';
		}
	},
	nextImage : function(e)
	{
		var photocontainer = document.getElementById('photocontainer');
		if( index < (images.length-1) )
		{
			
			document.getElementById('prevImage').src = '/sitefiles/2/design/arrow_previous.png';
			document.getElementById('mainphoto').innerHTML = '';
			//Dersom det er video
			if(images[++index][2] == 1)
			{
				document.getElementById('mainphoto').innerHTML = '<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="206" HEIGHT="122" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"><PARAM name="SRC" VALUE="'+images[index][0]+'"><PARAM name="AUTOPLAY" VALUE="true"><PARAM name="CONTROLLER" VALUE="false"><embed width="206px" height="122px" scale="ToFit" controller="false" name="plugin"  PLUGINSPAGE="http://www.apple.com/quicktime/download/" src="'+images[index][0]+'" type="video/quicktime" ></embed></OBJECT>';

				//document.getElementById('mainphoto').innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="206px" height="122px" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="'+images[index][0]+'"><param name="autoplay" value="true"><param name="controller" value="false">';				
				//document.getElementById('mainphoto').innerHTML += '<embed width="206px" height="122px" scale="ToFit" controller="false" name="plugin"  PLUGINSPAGE="http://www.apple.com/quicktime/download/" src="'+images[index][0]+'" type="video/quicktime" ></embed></OBJECT>';
			}
			else
			{
				var img = document.createElement('img');
				img.src = images[index][0];
				img.id = 'photocontainer';
				img.onclick = function() { productPopup(1,images[index][1],455,760,0,0); };
				document.getElementById('mainphoto').appendChild(img);
			}
			if( index == (images.length-1) )
				document.getElementById('nextImage').src = '/sitefiles/2/design/arrow_nonext.png';
		}
	},
	prevImage : function(e)
	{
		var photocontainer = document.getElementById('photocontainer');
		if( index > 0 )
		{
			document.getElementById('nextImage').src = '/sitefiles/2/design/arrow_next.png';
			document.getElementById('mainphoto').innerHTML = '';
			//Dersom det er video
			if(images[--index][2] == 1)
			{
				document.getElementById('mainphoto').innerHTML = '<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="206" HEIGHT="122" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"><PARAM name="SRC" VALUE="'+images[index][0]+'"><PARAM name="AUTOPLAY" VALUE="true"><PARAM name="CONTROLLER" VALUE="false"><embed width="206px" height="122px" scale="ToFit" controller="false" name="plugin"  PLUGINSPAGE="http://www.apple.com/quicktime/download/" src="'+images[index][0]+'" type="video/quicktime" ></embed></OBJECT>';
				//document.getElementById('mainphoto').innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="206px" height="122px" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="'+images[index][0]+'"><param name="autoplay" value="true"><param name="controller" value="false">';				
				//document.getElementById('mainphoto').innerHTML = '<embed width="206px" height="122px" scale="ToFit" controller="false" name="plugin" pluginspage="http://www.apple.com/quicktime/download/" src="'+images[index][0]+'" type="video/quicktime" />';
			}
			else
			{
				var img = document.createElement('img');
				img.src = images[index][0];
				img.id = 'photocontainer';
				img.onclick = function() { productPopup(1,images[index][1],455,760,0,0); }
				document.getElementById('mainphoto').appendChild(img);
			}
		}
		else
		{
			index = -1; // så vi er HELT sikre;-)
			document.getElementById('mainphoto').innerHTML = '';
			document.getElementById('mainphoto').innerHTML = originalImageHTML;
			/*var img = document.createElement('img');
			img.src = originalImage;
			img.onclick = originalImageonClick;
			document.getElementById('mainphoto').appendChild(img);*/
			document.getElementById('prevImage').src = '/sitefiles/2/design/arrow_noprev.png';
		}
	},
	showImage : function(e)
	{
		var target = window.event ? window.event.srcElement : e ? e.target : null;
		var i = target.id.replace('tempId_','');
		for(var y = 0;y<images.length;y++)
		{
			if( document.getElementById('tempId_'+y) )
			{
				if( y == i )
					document.getElementById('tempId_'+y).className = 'ImageActive';
				else
					document.getElementById('tempId_'+y).className = 'ImageNotActive';
 			}
		}
		document.getElementById('prospektImage').src = images[i][0];
		document.getElementById('prospektImage').onclick = function () { productPopup(1,images[i][1],455,760,0,0); }
	}
}

