// JavaScript Document
$flipSpeed = 200;

$a = 1;
var temp = -1;	
var index = 0;

Array.prototype.shuffle = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]);
while (s.length) this.push(s.pop());
return this;
} 
var myary = ['renovation','highRise','luxuryExperts','localMarket','newConstruction','midRise','mixedUse'];
myary.shuffle();



function flipTile() {
	
	if($a < 17 ){
		  $mask = '#tile_mask' + $a + ' img';
		  $tile = '#tile' + $a;
		  $newPhoto = 'images/home_tiles/' + $filePrefix + $a + '.jpg';
		  
		  $($mask).animate( { width: "1px"}, { queue: false, duration: $flipSpeed } )
		  .animate( { 'margin-left': "94px" } , $flipSpeed, function() {
		  // Animation complete.
		  flipTileOdd();
		  $($tile).attr("src", $newPhoto);
		  $($mask).animate( { width: "189px"}, { queue: false, duration: $flipSpeed } )
		  .animate( { 'margin-left': "0px" } , $flipSpeed, function() {
		  // Animation complete.
		  $a = $a+2;
		  flipTile();
		  }); 
		  }); 
		  
	}else{
		$a = 1;
		randomProperty();	
		autoPlayTimer = setTimeout('flipTile()', 3000);
	}
}

function randomProperty() {
	if (index < myary.length -1){
		index ++;
	}else{
		index = 0;
	}
	$filePrefix = myary[index];
}

function flipTileOdd() {
	$b = $a+1
	
		  $mask2 = '#tile_mask' + $b  + ' img';;
		  $tile2 = '#tile' + $b;
		  $newPhoto2 = "images/home_tiles/" + $filePrefix + $b + '.jpg';
		  
		  $($mask2).animate( { width: "1px"}, { queue: false, duration: $flipSpeed } )
		  .animate( { 'margin-left': "94px" } , $flipSpeed, function() {
		  // Animation complete.
		  $($tile2).attr("src", $newPhoto2);
		  $($mask2).animate( { width: "189px"}, { queue: false, duration: $flipSpeed } )
		  .animate( { 'margin-left': "0px" } , $flipSpeed, function() {
		  // Animation complete.
		  
		  }); 
		  }); 
}

$(document).ready(function() {	

	randomProperty();
	flipTile();

});


