﻿function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


var currentPosition = 0;


function Slide(direction)
{
    var count=0;
     var objCollection = document.getElementsByTagName("div");
  
     for (ii=0;ii< objCollection.length;ii++)
     {
       if (objCollection[ii].getAttribute("id") != null )
       {
          if (objCollection[ii].getAttribute("id").indexOf("divType_") ==0)
          {
          count++;
          }
       }
     
     
     }


    if (count>3)
    {
    

    
     var tempmax = (currentPosition+3)-0;
     
        if (direction == 1)
        {
            if (document.getElementById("divType_"+tempmax) != null)
            {
            
            document.getElementById("divType_"+currentPosition).style.display = "none";
            document.getElementById("divType_"+tempmax).style.display = "block";
            
                currentPosition++;
                 if ((currentPosition+3) >= count)
                 {
                 document.getElementById("imgProductTypeRight").src = "images/right_gray.png";
                 document.getElementById("imgProductTypeLeft").src = "images/left_red.png";
                 }
                 else
                 {
                 document.getElementById("imgProductTypeRight").src = "images/right_red.png";
                 }
                 
            
            
            }
        }
        if (direction == -1)
        {
            if (currentPosition > 0)
            {
            currentPosition--;
            tempmax = (currentPosition+3)-0;
            document.getElementById("divType_"+currentPosition).style.display = "block";
            document.getElementById("divType_"+tempmax).style.display = "none";
            

                 if (currentPosition > 0)
                 {
                 //document.getElementById("imgProductTypeRight").src = "images/right_gray.png";
                 document.getElementById("imgProductTypeLeft").src = "images/left_red.png";
                 }
                 else
                 {
                 document.getElementById("imgProductTypeLeft").src = "images/left_gray.png";
                 //document.getElementById("imgProductTypeRight").src = "images/right_red.png";
                 }
                 if ((currentPosition+3) < count)
                 {
                 document.getElementById("imgProductTypeRight").src = "images/right_red.png";
                 }
                 else
                 {
                 document.getElementById("imgProductTypeRight").src = "images/right_gray.png";
                 }
                 
            
            
            }
        }
        
        
    }
}



function setBackground(imagename)
{
document.body.style.backgroundImage = 'url(data/images/'+imagename+')';

if (imagename != readCookie("backgroundimage").toString())
{
createCookie("backgroundimage",imagename,10);
}

}

