var Poly = new Class({

    Implements: new Options, 
	   
	options : {
		id : "",
		zIndex : 0,
		spacing : 2,
		scale : 1.5,
		rotateSpeed : 39,
		width : 40,
		height : 40,
		opacity :.8,
		left : 0,
		top : 0,		
		hideCenter : true,
		contents : 'img',
		data : [],
		root : "",
		notFound : "noImage.gif",
		counterSpin : false
	},
	
	initialize : function(options){	
		this.setOptions(options);
		this.id = this.options.id;
		this.scale = this.options.scale;
		this.spacing = this.options.spacing;
		this.rotateSpeed = this.options.rotateSpeed;
		this.counterSpin = this.options.counterSpin;
		this.left = this.options.left;
		this.top = this.options.top;		
		this.width = this.options.width;
		this.height = this.options.height;		
		this.root = this.options.root;
		this.hideCenter = this.options.hideCenter;
		this.notFound = this.options.notFound;
		this.zIndex = this.options.zIndex;
		this.contents = this.options.contents;	
		this.data = this.options.data;
		this.opacity = this.options.opacity;
		this.coll = null;
		//this.facets = 0;
		this.x = 0;
		this.y = 0;
		this.z = 0;	
		this.v = 0;	
		this.u = 0;
		this.w = 0;
		this.u2 = 0;
		this.w2 = 0;
		this.v2 = 0;		
	},

	rotatePoly : function(a,b,l,t){
		this.facets = 0;			
		$each(this.coords, function(coord, index){
			this.x = coord.x;
			this.y = coord.y;
			this.z = coord.z;			
			this.u = this.x * Math.cos(a) - this.y * Math.sin(a);
			this.v2 = this.x * Math.sin(a) + this.y * Math.cos(a);
			this.w2 = this.z;
			this.v = this.v2 * Math.cos(b) - this.w2 * Math.sin(b);
			this.w = this.v2 * Math.sin(b) + this.w2 * Math.cos(b);
			this.c = Math.round((this.w ) * 90); // changes color gradient
			if(this.c < 0) this.c = 0;
			if(this.c > 255) this.c = 255;
			this.coll = document.getElementById('l' + this.facets + this.id);	
			if($(this.coll)){
				with(this.coll){	
					//innerHTML = this.w + this.spacing//(l + this.u * (this.w + this.spacing) * this.width).round(1)
				}
				with(this.coll.style){										
					if(this.counterSpin){
						left = l + this.u * (this.w + this.spacing) * this.width;
						top  = t + this.v * (this.w + this.spacing) * this.width;							
					}else{
						left = l - this.u * (this.w + this.spacing) * this.width;
						top  = t - this.v * (this.w + this.spacing) * this.width;							
					}
					zIndex = this.w.round(1) * 10;
					color = 'rgb(' + this.c + ', ' + this.c + ', 0)';	
					if(this.contents === "img"){
						width = Math.abs(parseInt((this.w + this.scale) * this.width)) + "px";
						height = Math.abs(parseInt((this.w  + this.scale) * this.height)) + "px";	
					}else{
						fontSize = ((this.w + this.scale) > 0) ? (this.w + this.scale) * 13 + "px" : 0.1;
					}
					if(Browser.Engine.trident){														
						if(this.contents === "img") filter = "alpha(opacity=" + (((this.w + this.scale) * this.opacity) * 100) +")";							
					}else{
						opacity = (this.w + this.scale) * this.opacity;
					}						
					if(this.hideCenter && this.w === 0) display = "none";
				}							
				this.coll.setProperty("lastOpacity",this.coll.getStyle("opacity"));
				this.coll.setProperty("lastWidth",this.coll.getStyle("width"));
				this.coll.setProperty("lastHeight",this.coll.getStyle("height"));	
				this.coll.setProperty("lastFontSize",this.coll.getStyle("fontSize"));								
				this.coll.setProperty("lastX",this.coll.getStyle("left"));	
				this.coll.setProperty("lastY",this.coll.getStyle("top"));						
				this.facets++;
			}
		}.bind(this));	
	}	
});

