/* 
 *
 * THIS IS FREE SCRIPT BUT LEAVE THIS COMMENT IF
 * YOU WANT USE THIS CODE ON YOUR SITE 
 *
 * Made by Wilq32, wilq32@gmail.com, Wroclaw, Poland, 04.2008 
 * 
 */ 



/*
 * This is image roller class, mail me if you have 
 * any questions. Example of use of this class:
 *
 * new Wilq32.RollImages(containerDIV,smoothSpeed,centerVertical,imagesWidth,ImagesHeight,imagesList);	
 *
 * - containerDIV - an defined div in document that
 *	 	will be used to put all images into, DIV need
 *		to be initalized before You can use this class.
 * - smoothSpeed - this parameter defines how fast
 * 		everything will move corresponding to length from centerVertical,
 * - centerVertical - this parameter tells a 
 *		where is vertical center of all images (see example)
 * - imagesWidth - all images will be scaled to this value
 * - imagesHeight - all images will be scaled to this value
 * - imagesList - a List of images in format of object:
 *
 * 		example imagesList:
 *
 *		imagesList=[{src:'image.gif', href:'#'},{src:'image2.gif', href:'http://google.com'}]
 *
 * Parameters that are in imageList:
 *
 *   src: - an image source - THIS IS NESSESARY ITEM
 *   href: - link to other page via <a href>
 *   onmouseover: - onmouseover event - can be a call to other function
 *   onmouseout: - onmouseout event - can be a call to other function
 *   onclick: - onclick event - can be a call to other function
 */

if (typeof Wilq32=="undefined")
	Wilq32 = {} 


Wilq32.RollImages = function(DIV,speed,centerX,imagesWidth,imagesHeight,imagesList,boxWidth)
{
	this.centerX=centerX;
	this.smooth=speed;
	this.imagesDIV = DIV;
	this.imagesWidth = imagesWidth;
	this.imagesHeight = imagesHeight;
	this.imagesList=imagesList;
	this.boxWidth=boxWidth;
	this.heightLength=this.imagesWidth*this.imagesList.length;	
	// Optimalize common used variables
	this.actualRoll = 0;
	this.divide = 2*Math.PI/this.imagesList.length;
	this.half=Math.round(this.imagesList.length/2);
	this.init();
	Wilq32.RollCallback=this;	
	setInterval('Wilq32.RollCallback.drawImages()',30);
}   

Wilq32.RollImages.prototype.init= function()
{
 
		
        Wilq32.IE = document.all ? true : false;
        if (!Wilq32.IE) 
            document.captureEvents(Event.MOUSEMOVE);      
        document.onmousemove = Wilq32.getMouseXY;        
        var images = document.getElementById(this.imagesDIV);
		
		for (var temp in this.imagesList)
		{
			var el=document.createElement("div");
			el.style.position="absolute";
			images.appendChild(el);
			//el.innerHTML="<a href='"+this.imagesList[temp].href+"' onclick='"+this.imagesList[temp].onclick+"' onmouseover='"+this.imagesList[temp].onmouseover+"' onmouseout='"+this.imagesList[temp].onmouseout+"'><img border='0' src='images/prod_bg.jpg' width='115' height='69' style='position:absolute;'><img border='0' src='"+this.imagesList[temp].src+"' width='59' height='59' style='position:absolute;'></a>";
			el.innerHTML="<span style='position:relative; z-index:96; top:-5px; width:105px; overflow:hidden; display:inline-block; left:50%; text-align:center; background-image:url(images/productimages/none_cat.jpg); background-repeat:no-repeat; background-position:center'><a href='"+this.imagesList[temp].href+"' onclick='"+this.imagesList[temp].onclick+"' onmouseover='"+this.imagesList[temp].onmouseover+"' onmouseout='"+this.imagesList[temp].onmouseout+"'><img src='/images/trans.gif' width='105' height='105' border='0' style='background-image:url("+this.imagesList[temp].src+"); background-repeat:no-repeat; background-position:center'></a></span><img border='0' src='images/prod_bg.jpg' width='115' height='115' style='position:relative; z-index:95;'>";	
		}
		
        
}
	
Wilq32.RollImages.prototype.drawImages=function()
{

		if (Wilq32.mousePositionY) 
		{
			this.actualRoll -= Math.round((Wilq32.mousePositionX - this.centerX )/this.smooth);
			if (this.actualRoll<0) this.actualRoll+=this.heightLength;
		}
		var list = document.getElementById(this.imagesDIV).getElementsByTagName("div");
		var which =Math.round(this.actualRoll/this.imagesWidth)%this.imagesList.length;	
		
		for (var temp=0;temp<list.length;temp++) 
		{

			var el=list[temp];
			var inside=(-Math.PI/2+(this.actualRoll/this.imagesWidth-temp)*this.divide);
			var sin=Math.sin(inside);
			var cos=Math.cos(inside);
			el.style.marginLeft = (this.centerX+((this.boxWidth-this.imagesWidth)/2)*cos)-(this.imagesWidth/3)-115
			el.style.marginTop = 5+Math.round((this.imagesWidth/8)*sin);
			el.style.opacity= 1-sin;
			el.style.filter="alpha(opacity="+(1-sin)*100+")";
			var temp1=Math.abs(which-temp);
			if (temp1>this.half) temp1=Math.abs(temp1-this.imagesList.length);
			
			el.style.zIndex = this.imagesList.length-temp1;
		}
		
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }


Wilq32.getMouseXY=function(e)
{
    if (Wilq32.IE) 
	{
        Wilq32.mousePositionX = (event.clientX + document.getElementById("images").scrollLeft)-findPosX(document.getElementById("images"));
        Wilq32.mousePositionY = event.clientY + document.getElementById("images").scrollTop;
    }
    else 
	{
        Wilq32.mousePositionX = e.pageX-findPosX(document.getElementById("images"));
        Wilq32.mousePositionY = e.pageY;
    }
    
    return true;
}