
var rem_URL = "http://www.phrings.com/scroller/xph/";


Carousel_tplxph = {
	// 7 variables to control behavior
	'Car_Vertical' : true,
	'Car_Image_Width':130,
	'Car_Image_Height':130,
	'Car_Border':false,		// true or false
	'Car_Border_Color':"silver",
	'Car_Speed':1.5,
	'Car_Direction':true,		// true or false
	'Car_NoOfSides':12,		// must be 4, 6, 8 or 12

/* array to specify images and optional links. 
	For 4 sided carousel specify at least 2 images
	For 6 sided carousel specify at least 3
	For 8 sided carousel specify at least 4
	For 12 sided carousel specify at least 6
 If Link is not needed keep it ""
	*/
	//http://domain658367.sites.fasthosts.com/images/scroller/scr-(2).jpg
	'Car_Image_Sources':[
		rem_URL+"001.jpg","http://www.phrings.com/x_at_ph/linksrings.asp",
		rem_URL+"002.jpg","http://www.phrings.com/x_at_ph/sleeves.asp",
		rem_URL+"003.jpg","http://www.phrings.com/x_at_ph/diamonds.asp",
		rem_URL+"004.jpg","http://www.phrings.com/x_at_ph/2colour.asp",
		rem_URL+"005.jpg","http://www.phrings.com/x_at_ph/plainvariations.asp",
		rem_URL+"006.jpg","http://www.phrings.com/x_at_ph/RJCollection.asp",
		rem_URL+"007.jpg","http://www.phrings.com/x_at_ph/linksrings.asp",
		rem_URL+"008.jpg","http://www.phrings.com/x_at_ph/sleeves.asp",
		rem_URL+"009.jpg","http://www.phrings.com/x_at_ph/diamonds.asp",
		rem_URL+"010.jpg","http://www.phrings.com/x_at_ph/2colour.asp",
		rem_URL+"011.jpg","http://www.phrings.com/x_at_ph/plainvariatons.asp",
		rem_URL+"012.jpg","http://www.phrings.com/x_at_ph/RJCollection.asp",
		rem_URL+"013.jpg","http://www.phrings.com/x_at_ph/linksRings.asp",
		rem_URL+"014.jpg","http://www.phrings.com/x_at_ph/sleeves.asp",
		rem_URL+"015.jpg","http://www.phrings.com/x_at_ph/diamonds.asp",
		rem_URL+"016.jpg","http://www.phrings.com/x_at_ph/2colour.asp",
		rem_URL+"017.jpg","http://www.phrings.com/x_at_ph/plainvariations.asp",
		rem_URL+"019.jpg","http://www.phrings.com/x_at_ph/linksrings.asp",
		rem_URL+"021.jpg","http://www.phrings.com/x_at_ph/diamonds.asp",
		rem_URL+"023.jpg","http://www.phrings.com/x_at_ph/2colour.asp" // NOTE No comma after last line
		]
}
/*******************************************************************************/
	
	C_Coef=new Array(
		3*Math.PI/2,0,3*Math.PI/2,11*Math.PI/6,Math.PI/6,3*Math.PI/2,7*Math.PI/4,	0,
		Math.PI/4,3*Math.PI/2,5*Math.PI/3,11*Math.PI/6,0,Math.PI/6,Math.PI/3);

	Car_Div = [];
	gCH_I = [];
	gC_Angle = [];
	gC_CrImg = [];
	gC_Stppd = [];
	gC_MaxH = [];
	gCarousel_tpl = [];

	function build_Carousel(){
		this.C_Stppd = false;
		this.C_Angle =this.Car_Direction?Math.PI/(this.Car_NoOfSides/2):0
		this.C_CrImg = this.Car_NoOfSides;
		var i;
		if(document.getElementById){
			this.C_Pre_Img= [];
			for(i=0;i<this.Car_Image_Sources.length;i+=2){
				var p_i = this.C_Pre_Img.length;
				this.C_Pre_Img[p_i]=new Image();
				this.C_Pre_Img[p_i].src=this.Car_Image_Sources[i]
			}
			this.C_MaxH = this.Car_Image_Height/Math.sin(Math.PI/this.Car_NoOfSides)+this.C_HalfNo+1;
			this.Car_Div = document.getElementById(this.id);
			this.CH_I = [];
			for(i=0;i<this.C_HalfNo;i++){
				this.CH_I[i]=document.createElement("img");
				this.Car_Div.appendChild(this.CH_I[i]);	
				this.CH_I[i].style.position="absolute";
				this.CH_I[i].style[(this.Car_Vertical?'left':'top')]=0+"px";
				this.CH_I[i].style.height=this.Car_Image_Height+"px";
				this.CH_I[i].style.width= this.Car_Image_Width+"px";
				if(this.Car_Border){
					this.CH_I[i].style.borderStyle="solid";
					this.CH_I[i].style.borderWidth=1+"px";
					this.CH_I[i].style.borderColor=this.Car_Border_Color}
				var s_name = this.id;
				this.CH_I[i].src=this.Car_Image_Sources[2*i];
				this.CH_I[i].lnk=this.Car_Image_Sources[2*i+1];
				this.CH_I[i].onclick= function(){if(this.lnk)window.location.href=this.lnk};
				this.CH_I[i].onmouseover= function () {
					this.style.cursor=this.lnk?"pointer":"default";
					CAROUSELS[s_name].C_Stppd=true;
				};
				this.CH_I[i].onmouseout=function () {CAROUSELS[s_name].C_Stppd=false;}
			}
			//gCH_I[s_name] = CH_I;
			this.roll()
		}
	}

	function roll_Carousel(s_name){

		var i;
		if(!this.C_Stppd){
			this.C_TotalH=0; this.C_ClcH= [];
			for(i=0;i<this.C_HalfNo;i++){
				this.C_ClcH[i]=Math.round(Math.cos(Math.abs(C_Coef[this.C_CoefOf+i]+this.C_Angle))*this.Car_Image_Height);
				this.C_TotalH+=this.C_ClcH[i]}
			this.C_TopOffset=(this.C_MaxH-this.C_TotalH)/2;
			for(i=0;i<this.C_HalfNo;i++){
				this.CH_I[i].style[(this.Car_Vertical?'top':'left')]=this.C_TopOffset+"px";
				this.CH_I[i].style[(this.Car_Vertical?'height':'width')]=this.C_ClcH[i]+"px";
				this.C_TopOffset+=this.C_ClcH[i]
			}
			this.C_Angle+=this.Car_Speed/720*Math.PI*(this.Car_Direction?-1:1);
			if((this.Car_Direction&&this.C_Angle<=0)||(!this.Car_Direction&&this.C_Angle>=Math.PI/this.C_HalfNo)){
				if(this.C_CrImg==this.Car_Image_Sources.length)this.C_CrImg=0;
				if(this.Car_Direction){
					this.CH_I[this.C_HalfNo]=this.CH_I[0];
					for(i=0;i<this.C_HalfNo;i++)this.CH_I[i]=this.CH_I[i+1];
					this.CH_I[this.C_HalfNo-1].src=this.Car_Image_Sources[this.C_CrImg];
					this.CH_I[this.C_HalfNo-1].lnk=this.Car_Image_Sources[this.C_CrImg+1]}
				else{	for(i=this.C_HalfNo;i>0;i--)this.CH_I[i]=this.CH_I[i-1];
					this.CH_I[0]=this.CH_I[this.C_HalfNo];
					this.CH_I[0].src=this.Car_Image_Sources[this.C_CrImg];
					this.CH_I[0].lnk=this.Car_Image_Sources[this.C_CrImg+1]}
				this.C_Angle=this.Car_Direction?Math.PI/this.C_HalfNo:0;
				this.C_CrImg+=2}}
		setTimeout("CAROUSELS['"+this.id+"'].roll()",50)}

	var CAROUSELS = [];
	function Carousel(a_tpl,s_name) {

		this.id = s_name?s_name:'Caruosel'+CAROUSELS.length;
		CAROUSELS[this.id] = this;

		this.a_tpl = a_tpl;
		this.Car_Vertical = a_tpl.Car_Vertical;
		this.Car_Image_Width=a_tpl.Car_Image_Width;
		this.Car_Image_Height=a_tpl.Car_Image_Height;
		this.Car_Border=a_tpl.Car_Border;		// true or false
		this.Car_Border_Color=a_tpl.Car_Border_Color;
		this.Car_Speed=a_tpl.Car_Speed;
		this.Car_Direction=a_tpl.Car_Direction;		// true or false
		this.Car_NoOfSides=a_tpl.Car_NoOfSides;		// must be 4, 6, 8 or 12
		this.Car_Image_Sources = a_tpl.Car_Image_Sources;
		this.C_HalfNo=this.Car_NoOfSides/2;
		this.C_CoefOf=this.Car_NoOfSides==4?0:this.Car_NoOfSides==6?2:this.Car_NoOfSides==8?5:9;

		var ph_width = 0;
		var ph_height = 0;
		var ciwidth = (this.Car_Vertical?this.Car_Image_Height:this.Car_Image_Width)
		var ph_items = this.Car_Image_Sources.length/2;
		switch(this.Car_NoOfSides){
			case 4:
				ph_width = 1.42 * ciwidth + 3;
				break;
			case 6:
				ph_width = 2 * ciwidth + 4;
				break;
			case 8:
				ph_width = 2.62 * ciwidth + 5;
				break;
			case 12:
				ph_width = 3.87 * ciwidth+ 7;
				break;
		}
		ph_height = (this.Car_Vertical?this.Car_Image_Width:this.Car_Image_Height)+2;
		
		document.write('<div id="'+s_name+'" style="position:relative "><img src="placeholder.gif" height="'+(this.Car_Vertical?ph_width:ph_height)+'" width="'+(this.Car_Vertical?ph_height:ph_width)+'"></div>')
		this.build = build_Carousel;
		this.roll = roll_Carousel;
		this.build();
	}
