var count = 0; 
var baseSpeed = 0.03; 
var radiusX = 200; 
var radiusY = 30; 
var centerX = 250; 
var centerY = 120;
var speed = 0.5;
var imageDivs = '';
var numberOfElements = 0;
var carousel = '';
var speedTest = '';
var bob = 1;
var extra = 0;
var chk1=0;
var chk2=0;
var IsStop="no";

window.addEvent('domready', function(){
	carousel = $('carousel');
	speedTest = $('speedTest');
	imageDivs = carousel.getElementsByTagName("div"); 
	numberOfElements = imageDivs.length; 
	setInterval('startCarousel()',38);
	carousel.addEvent('mousemove', onMouseMove.bindWithEvent( carousel ));
	carousel.addEvent('mouseover', onMouseMove.bindWithEvent( carousel ));
	carousel.addEvent('mouseout', onMouseOut.bindWithEvent( carousel ));

//	for (index=0;index<numberOfElements;index++)
//	{
//	    imageDivs[index].addEvent('mouseover', onMouseOver.bindWithEvent( imageDivs[index] ),RecOnMouseMove);
//	    imageDivs[index].addEvent('mouseout', onMouseOut.bindWithEvent( imageDivs[index] ));
//	}
});

function PauseCarsoule() 
{
    IsStop="yes";
}

function ResumeCarsoule() 
{
    IsStop="no";
}

function onMouseMove( evt ) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
  			winW = window.innerWidth;
  			winH = window.innerHeight;
 		}
 		
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
  			winW = document.body.offsetWidth;
  			winH = document.body.offsetHeight;
 		}
	}

	tempX = evt.client.x;

	if(tempX > ((winW / 2) + 40)){	
		bob = 1;
		extra=0;	
	}else{
	
		if(tempX < ((winW / 2) - 40)){	
			bob = 0;
			extra = 0;	
			//alert("stop1");
		}else{
			bob = 2;
			extra = 0;
			//alert("stop2");
		}
	}
	
	
	if(tempX > ((winW / 2) + 200)){	
		extra = 2; 	
	}else{
	
		if(tempX < ((winW / 2) - 200)){	
			extra=2;	
		}
	}
	
	if(tempX > ((winW / 2) + 300)){	
		extra = 4; 	
	}else{
	
		if(tempX < ((winW / 2) - 300)){	
			extra=4;	
		}
	}
}

function onMouseOut( evt ) {
	bob = 1;
	speed = 0.5;
	extra=0;	
    
    }

function startCarousel(){


if (IsStop == "no")
{
	for(i=0; i < numberOfElements; i++){

		angle = i * ( Math.PI * 2 ) / numberOfElements;
	
		imageDivsStyle = imageDivs[ i ].style; 
		imageDivsStyle.position='absolute';

		
		posX = ( Math.sin( count * ( baseSpeed * speed ) + angle )* radiusX + centerX );
		posY = ( Math.cos( count * ( baseSpeed * speed ) + angle )* radiusY + centerY );
		
		
		imageDivsStyle.left = posX+"px"; 
		imageDivsStyle.top = (posY-80)+"px";
        
		if (((posX>=178 && posX<=345) && posY>=94))
		{
		        var dvName = 'Div' + (i+1);
		        var imgName = 'Img_' + (i+1);
		        if (window.location.href.toLowerCase().indexOf('candidate') == -1)
		        {
		            if(document.getElementById(imgName))
		                document.getElementById(imgName).src="http://www.apply4u.co.uk/images/user-on_d64x64.png";
		        }
		        if(document.getElementById(dvName))
		            document.getElementById(dvName).style.display='inline';
		} 
		else
		{
		        var dvName = 'Div' + (i+1);
		        var imgName = 'Img_' + (i+1);
		        if (window.location.href.toLowerCase().indexOf('candidate') == -1)
		        {   
		            if(document.getElementById(imgName))   
		                document.getElementById(imgName).src="http://www.apply4u.co.uk/images/user-busy_64x64.png";
		        }
		        if(document.getElementById(dvName))
		            document.getElementById(dvName).style.display='none';   
		}
		
		
		imageDivWidth = posY*1.6;
		imageDivZIndex = Math.round(imageDivWidth)+100;
		
		imageDivsStyle.width = imageDivWidth+'px';
		imageDivsStyle.zIndex = imageDivZIndex;
		
		angle += speed;
	}
	
	if(bob==0){
		count++;
		if(extra>0){
			count = count + extra;
		}	
	}else{
		if(bob==1){
			count--;
			if(extra>0){
				count = count-extra;
			}	
		}	
	}

}
}