// JavaScript Document
var $j = jQuery.noConflict();
var isRotating = 0; /* Controls "button mashing" (ie. repeated clicks of the buttons). */
var isStopped = 0;
var rotate;
$j("document").ready(function() {
	$j('#slides div:last').remove();
	// create the image rotator
	rotate = setInterval("rotateNext()", 5000); /* Controls the time between transitions (5000 = 5 seconds) */
	/*Calls the function rotateImagesRight(),
	enabling the user to manually rotate the carousel to the right by clicking the next button*/
	$j("button.next").click(rotateNext);
	/*Calls the function rotateImagesLeft(),
	enabling the user to manually rotate the carousel to the left by clicking the previous button*/			
	$j("button.prev").click(rotatePrev);
	$j("a#contactfixed").toggle(
		function() {
			$j("#contact").animate({ right: "0" }, 500)
		},
		function() {
			$j("#contact").animate({ right: "-220px" }, 500)
		}
	);
});

	function rotateNext() {
		if(isRotating == 1){ return; }
		isRotating = 1;
		var oCurPhoto = $j('#slides div.current');
		var oNxtPhoto = oCurPhoto.next('div');
		if (oNxtPhoto.length == 0){
			oNxtPhoto = $j('#slides div:first');
		}
		oCurPhoto.animate({ right: "-518px" },250, 'linear',
			function() {
				oCurPhoto.removeAttr('style');
				oCurPhoto.removeClass('current');
			});
		
		oNxtPhoto.animate({ right: "0px" }, 250, 'linear',
			function() {
				oNxtPhoto.addClass('current');
				isRotating = 0;
			});
	}
	function rotatePrev() {
		if( isRotating == 1 ){
			return;
		}
		isRotating = 1;	
		var oCurPhoto = $j('#slides div.current');
		var oNxtPhoto = oCurPhoto.prev();
		if (oNxtPhoto.length == 0){
			oNxtPhoto = $j('#slides div:last');
		}
		oCurPhoto.animate({ right: "518px" },250, 'linear',
			function() {
				oCurPhoto.removeAttr('style');
				oCurPhoto.removeClass('current');
			});
		oNxtPhoto.css("right","-518px");
		oNxtPhoto.animate({ right: "0px" }, 250, 'linear',
			function() {
				oNxtPhoto.addClass('current');
				isRotating = 0;
			});
	
	}

