$(document).ready(function() {
	// ######################################        main image rotator        ###########################
	if($('#home')){
	
		if($(window).width() > 960){
			$("<div id=\"loadingDiv\">Images are loading...</div>")
			.prependTo('#imageLoop')
			.hide()  // hide it initially
			.ajaxStart(function() {
				$(this).fadeIn(1500, function() {
					// Animation complete
				  });
			})
			.ajaxStop(function() {
				$(this).fadeOut(400, function() {
					// Animation complete
				  });
			});
			

			
			$.get('imageLoop.php?l=9s87yd9auhg', function(data) {
				$('#imageLoop').html(data);
				// alert('Load was performed.');
			  
					// hide the desired elements
				$("#imageLoop div").hide();
				
				// set an iterator counter
				var j = 0;
				// set the total num of items in our list
				var jmax = $("#imageLoop div").length-1;
				// apply the effect
				$('<div id="storeMSG" style="font-size:1.2em;color:white;position:absolute;left:0;right:0;z-index:200; padding: .35em 1em;background-color:rgb(255,76,0);background-color:rgba(255,76,0,.8);">Got the craving for a tasty healthy snack? Visit our new Raw Foods Web Store! <br />Go to <a href="http://pachamamaraw.com/" style="color:white;font-weight:bold;">pachamamaraw.com</a></div>').hide().appendTo('#imageLoop').fadeIn(1200);
				function loopThruItems(){
				 // alert('looping...');
					// select the current element and apply effect, call self recursively	
					var k = (j < jmax) ? j+1 : 0;
					//alert($("#imageLoop div:eq(" + j + ")").html());
					if(j == 0){
						$("#imageLoop div:eq(" + j + ")")
						.show()
						.css("z-index","2")
						.delay(6500);
					} else {
						$("#imageLoop div:eq(" + j + ")")
						.css("z-index","2")
						.delay(6500);
					}
					if(j < jmax){
						$("#imageLoop div:eq(" + k + ")")
						.css("z-index","100")
						.fadeIn(600);
					} else {
						$("#imageLoop div:eq(0)")
						.css("z-index","100")
						.fadeIn(600);
						$('#storeMSG').fadeOut(900);
					}
					$("#imageLoop div:eq(" + j + ")")	
						.fadeOut(10, function(){
							(j == jmax) ? j=0 : j++;
							loopThruItems();
						});

				};
			  
				loopThruItems();
			
			});
		} //else if($(window).width() < 321){
		//	$("#imageLoop img").attr("width","320");
		//} else {
		//	$("#imageLoop img").attr("width","480");
		//}
		else {
			$('<div id="storeMSG" style="font-size:1.2em;color:white;position:absolute;left:0;right:0;z-index:200; padding: .35em 1em;background-color:rgb(255,76,0);background-color:rgba(255,76,0,.8);">Got the craving for a tasty healthy snack? Visit our new Raw Foods Web Store! <br />Go to <a href="http://pachamamaraw.com/" style="color:white;font-weight:bold;">pachamamaraw.com</a></div>').hide().prependTo('#imageLoop').fadeIn(1200).delay(6500).fadeOut(900);
			
		}
	}
});	
