var log = function(msg){
		   if (window.console && window.console.firebug){
		       console.log(msg);
		   }
	};


	var start_left = 0;    

	function looper(n) {

		var hmPMSwidth = $('#hmPMS').width()/2;	


		var hmPMSwidth2 = (hmPMSwidth/2);

		if (start_left == hmPMSwidth) {
			move_left = "+=64";
			start_left = hmPMSwidth + 1;
		} else {
			move_left = "-=128";
			start_left = hmPMSwidth;
		};

		// console.log("start_left: ");
		// console.log(start_left);
		// console.log(hmPMSwidth);

		var rand_top = Math.floor((160-139)*Math.random()) + 140;

		if (iconArray.length > 0){
			//Create ICONS from array
			$('#hmPMS').append("<img id='icon" + n + "' class='pmsfloat' src='images/pms/" + iconArray[iconArray.length - 1] + "' />");
			// console.log("iconArray: ");
			// console.log(iconArray);
			iconArray.pop();
		}

		//Animate icon
		$('#icon' + n)
		.animate({left: start_left,top: rand_top,opacity:"0"},0)
		.animate({opacity: ".9", width: "128", height:"128", top:"-=100", left: move_left}, 1000,"linear")
		.animate({opacity: "0", width: "256", height:"256", top:"-=100", left: move_left}, 1000, "linear", function(){
			$(this).animate({opacity: ".75", width: "0", height:"0"}, 0)		
		});
   		 
		//    		jQuery.each(jQuery.browser, function(i) {
		//    		  if($.browser.msie){
		//    		     // Don't animate PMS light. IE opacity on PNGs are terrible.
		//    		  }else{
		//    		     $('#pmslight')
		//    			    .animate({opacity: "1"}, 1500,"linear")
		//    			    .animate({opacity: ".6"}, 1500, "linear");
		//    		  }        
		// });        
                     
        // Don't animate PMS light. IE opacity on PNGs are terrible.     
		if ($.support.opacity) {
			$('#pmslight')
			.animate({opacity: "1"}, 1500,"linear")
			.animate({opacity: ".6"}, 1500, "linear");
		}

	   


	};//end looper

	var i=0;
	var iconArray = ["iTunes.png", "iPhoto.png", "Aperture.png", "4oD.jpg", "AppleMovieTrailers.png", "arte.tv.jpg", "BBCiPlayer.png", "CBSSports.png", "CNN.png", "ColbertReport.jpg", "DailyShow.jpg",  "FoodTV.png", "FoxNews.jpg", "GameTrailers.jpg", "Guardian.png", "HGTV.png", "Hulu.png", "ICANHASCHEEZBURGER.jpg", "CultureCatch.png", "Joost.jpg", "Miro.png", "MLB.png", "MTV.png", "NBC.png", "Netflix.jpg", "PBS.png", "Picasaweb.png", "pitchfork.jpg", "Revision3.png", "SesameStreet.png", "TED.png", "TIVO.png", "Vimeo.jpg", "YouTube.png"];
	//iconArray = $.shuffle(iconArray);
	var iconCount = iconArray.length;

	function startLoop() {
		looper(i);
		if (i == iconCount) { 
			i = 0 
		} else { 
			i=i+1;	
		}
		timeout=setTimeout("startLoop()",1500);
	}

	function createThumbs() {
		//console.log(iconCount);
		for (n=0;n<iconCount;n++) {
		$('#hmPMSicons').append("<img src='images/pms/" + iconArray[n] + "' />");
		}
		iconArray = $.shuffle(iconArray);
		startLoop();
	}

	$(document).ready(function() {
	createThumbs();

	}); 
