﻿

// JavaScript Document
	/************************************************************************************************************
	************************************************************************************************************/	

	var slideshow2_noFading = false;
	var slideshow2_timeBetweenSlides = 2500;	// Amount of time between each image(1000 = 1 second)
	var slideshow2_fadingSpeed = 10;	        // Speed of fading
	
	var slideshow2_galleryContainer;	        // Reference to the gallery div
	var slideshow2_galleryWidth;	            // Width of gallery
	var slideshow2_galleryHeight;	            // Height of galery
	var currentslide = -1;	                    // Index of current image shown
	var nextslide = false;	                    // Index of next image shown
	var slideshow2_imageDivs = new Array();	    // Array of image divs(Created dynamically)
	var slideshow2_currentOpacity = 100;	    // Initial opacity
	var slideshow2_imagesInGallery = false;	    // Number of images in gallery
	var activedescriptiondiv = '';
	
	var currentindex;
	var showstate = 'running';	
	var popupshowing = false;
	var currentaction = '';
    var browsertype = ''	
    var imagelen = 0;
    
    function getbrowser()
    {
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
        { //test for MSIE x.x;
            var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
            if (ieversion>=8)
                browsertype = 'IE8';
            else if (ieversion>=7)
                browsertype = 'IE7';
            else if (ieversion>=6)
                browsertype = 'IE6';
            else if (ieversion>=5)
                browsertype = 'IE5';
        }
        else
            browsertype = 'n/a';
    }
    var imagecount = 0;
    
    function countimages()
    {
        imagecount++;
        if(imagecount==imagelen)
        {
            initImageGallery();
        }
    }
        
    function skipimage(next)
    {
        for(i = 0; i < imagelen; i++)
        {
            var hs = slideshow2_imageDivs[i];
    		hs.style.zIndex = 0;
		    if(document.all)
			    hs.style.filter = 'alpha(opacity=1)';
		    else
			    hs.style.opacity = 0.01; 
        }
        
        currentslide += next;

        if (currentslide < 0)
            currentslide = imagelen - 1;
            
        if (currentslide == imagelen)
            currentslide = 0;


        var ns = slideshow2_imageDivs[currentslide];
        
		ns.style.zIndex = 1;
		ns.style.visibility= 'visible';

		if(document.all)
			ns.style.filter = 'alpha(opacity=100)';
		else
			ns.style.opacity = 0.99;


        showproductid(currentslide);
			
    }

    function showproductid(id)
    {
        var pr = document.getElementById('navproductid');
	    pr.innerHTML = images[id][1];

    }
    
	function previousimage()
	{
	    skipimage(-1);
	}
	
	function nextimage()
	{
        skipimage(1);
	}
	
	function pauseshow()
	{
        showstate = 'stopped';	
	}
	
	function startshow()
	{
	    if(!popupshowing)
            showstate = 'running';
	}
	
	function getGalleryImageSize(imageIndex)
	{
	    getbrowser();
		if(imageIndex==slideshow2_imagesInGallery)
		{			
			showGallery(0);
		}
		else
		{
			var imgObj = document.getElementById('galleryImage' + imageIndex);
			var imgWidth = imgObj.width;
			var imgHeight = imgObj.height;
			if(imgWidth>50){						
				var tmpDiv = document.createElement('DIV');
				tmpDiv.id = 'galleryDiv' + imageIndex;
				tmpDiv.style.visibility = 'hidden';
				tmpDiv.style.width = '170';
				tmpDiv.className='imageInGallery';
				slideshow2_galleryContainer.appendChild(tmpDiv);
				tmpDiv.appendChild(imgObj);

                var imgheight = imgObj.height;
                var imgwidth = imgObj.width;
                
                if((browsertype != 'IE6')&&(browsertype != 'IE7'))
                {
				    imgObj.style.marginLeft = (slideshow2_galleryWidth - imgwidth)   / 2 + "px";
				    imgObj.style.marginTop  = (slideshow2_galleryHeight - imgheight) / 2 + "px";
                }
                else
                {
				    imgObj.style.left = parseInt((slideshow2_galleryWidth - imgwidth)   / 2);
				    imgObj.style.top = 0;//parseInt((slideshow2_galleryHeight - imgheight) / 2);
                }
                
				slideshow2_imageDivs.push(tmpDiv);
				tmpDiv.style.visibility = 'hidden';
				imageIndex++;
				getGalleryImageSize(imageIndex);
			}else{
				setTimeout('getGalleryImageSize(' + imageIndex + ')',10);
			}
		}		
	}
	
	
	function showGallery(next)
	{
        if(imagelen==1)
        {
        		slideshow2_imageDivs[0].style.visibility = 'visible';
                showproductid(0);
        		return;
        }          

        currentaction = 'switching';
    	
		if ((showstate=='running')&&(next==0))
		    currentslide++;
        else
            currentslide += next;
		    
		if(currentslide==slideshow2_imageDivs.length)
		    currentslide=0;

		if(currentslide<0)	// Index of next image to show
		    currentslide=slideshow2_imageDivs.length-1; 

        if(next!=0)
            nextslide = currentslide + next;	                    // Index of the next next image
        else
            nextslide = currentslide+1;	                        // Index of the next next image
		    
		if(nextslide>=slideshow2_imageDivs.length)
		    nextslide = 0;
		    
		if(nextslide<0)
		    nextslide = slideshow2_imageDivs.length-1;

		slideshow2_currentOpacity=100;	// Reset current opacity

		// Displaying image divs
		slideshow2_imageDivs[currentslide].style.visibility = 'visible';
		if(navigator.userAgent.indexOf('Opera')<0)
		{
			slideshow2_imageDivs[nextslide].style.visibility = 'visible';
		}
		
		if(document.all)
		{
			slideshow2_imageDivs[currentslide].style.filter = 'alpha(opacity=100)';
			slideshow2_imageDivs[nextslide].style.filter = 'alpha(opacity=1)';
		}
		else
		{
			slideshow2_imageDivs[currentslide].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[nextslide].style.opacity = 0.01;
		}	
			
        showproductid(currentslide);
        
        setTimeout('revealImage(true)',slideshow2_timeBetweenSlides);		    
	}
	
	function revealImage(ignorestate)
	{
        currentaction = 'revealing';

        if((showstate=='stopped')||(popupshowing))
        {
			setTimeout('revealImage(false)',slideshow2_fadingSpeed);
			return;
        }

		if(slideshow2_noFading)
		{
			slideshow2_imageDivs[currentslide].style.visibility = 'hidden';
			showshowGallery(0);
			return;
		}
		
		slideshow2_currentOpacity--;
		
		if(document.all){
			slideshow2_imageDivs[currentslide].style.filter = 'alpha(opacity='+slideshow2_currentOpacity+')';
			slideshow2_imageDivs[nextslide].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity)+')';
		}else{
			slideshow2_imageDivs[currentslide].style.opacity = Math.max(0.01,slideshow2_currentOpacity/100);	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[nextslide].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity/100)));
		}
		
		if(slideshow2_currentOpacity>0)
		{
			setTimeout('revealImage(false)',slideshow2_fadingSpeed);
		}
		else
		{
			slideshow2_imageDivs[currentslide].style.visibility = 'hidden';
			slideshow2_imageDivs[currentslide].style.zIndex = 0;
			slideshow2_imageDivs[nextslide].style.zIndex = 1;
			showGallery(0);
		}
	}

    function showdescription(id)
    {
        activedescriptiondiv = id;
        popupshowing = true;
        var tg = document.getElementById('modalpanel');
        tg.style.visibility = 'visible';
        showstate = 'stopped';

        var myWidth = 0, myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' )
        {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } 
        else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
        {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } 
        else if (document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
        {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        }
        
        var uo = document.getElementById('modalpanel');
        uo.style.height = myHeight;
        uo.style.width= myWidth;

        d = document.getElementById(id);
        d.style.visibility = 'visible';
    }	

    function hidedescription()
    {
        var gh = document.getElementById(activedescriptiondiv);
        gh.style.visibility = 'hidden';
        var hj = document.getElementById('modalpanel');
        hj.style.visibility = 'hidden';
        
        showstate = 'running';
        popupshowing = false;
    }
	
    function MultiDimensionalArray(iRows,iCols)
    {
        var i;
        var j;
        var a = new Array(iRows);
        for (i=0; i < iRows; i++)
        {
            a[i] = new Array(iCols);
            for (j=0; j < iCols; j++)
            {
                a[i][j] = '';
            };
        };
        return(a);
    };

	function initImageGallery()
	{
        if(imagelen==0)
            return;
        if(imagelen > 1)
        {
	        var tw1 = document.getElementById('btnprevious');
	        var tw2 = document.getElementById('btnnext');
	        tw1.style.visibility = 'visible';
	        tw2.style.visibility = 'visible';
        }
        slideshow2_galleryContainer = document.getElementById('imageSlideshowHolder');

		slideshow2_galleryWidth = slideshow2_galleryContainer.clientWidth;
		slideshow2_galleryHeight = slideshow2_galleryContainer.clientHeight;

		galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
        		
		for(var no=0;no<galleryImgArray.length;no++)
		{
			galleryImgArray[no].id = 'galleryImage' + no;
		}

		slideshow2_imagesInGallery = galleryImgArray.length;

		getGalleryImageSize(0);	
	}
		
