var intr;
var intrRestore = 0;	
//var whichImage = 0;

$.fn.theRotator = function() {  
    //Set the opacity of all images to 0
	if(intrRestore == 0){	
	//Call the rotator function to run the slideshow, 5000 = change to next image after 6 seconds
	//	intr = setInterval('rotate()', 1000);
	}
};

var arr = new Array(11);
var cnt;
var j;
j=0;
cnt=0;


function GenrateRanArr()
{	
	var i;
	i=0;
	//var whichImage;
	while(i<=11)
	{
		var whichImage = Math.round(Math.random()*(11));
	 	if (!contains(arr, whichImage))
		{
			//alert(i);
			arr[i]=whichImage;
			//alert(arr[cnt]);
			i++;
		}	 	
	}

}



function testNum(testNum, theArray){
// testResult = whether testNum is found in theArray, init to 0;
testResult = 0;
for (i=0; i <= theArray.length; i++){
if (testNum == theArray[i]){
testResult = 1;
}
}
return testResult;
}

function rotate() {	
	//$('div#gallery ul li a').animate({opacity: 0.3}, 500);
	var UL = $('#galleryUL').children();
	var current  = $('div#gallery ul li a.show');
	var p = UL.length;
	
	if(j==0)
	{
	GenrateRanArr();	
	}
		if(arr[j]<p)
		{
			var next = $(UL[arr[j]]).find('a');
			//Set the fade in effect for the next image, the show class has higher z-index			
			 next.css({opacity: 0})
			.addClass('show')
			.animate({opacity: 1}, 2000, function(){rotate()});

			var next = $(UL[arr[j+1]]).find('a');
			//Set the fade in effect for the next image, the show class has higher z-index			
			 next.css({opacity: 0})
			.addClass('show')
			.animate({opacity: 1}, 1500, function(){rotate()});


		
			//Hide the current image
			current.removeClass('show');
			//j++;		
			j = j+2;
		}

};

function contains(a, obj) {
  var i = a.length;
  while (i--) {
    if (a[i] === obj) {
      return true;
    }
  }
  return false;
}

