tileContent = [{
	name:'Icon Aircraft',
	msg :'Desktop Aeronautics helped in the conceptual design of ICON Aircraft light sport aircraft by assessing airfoil and wing design, performance, stability and control, and aerodynamic loads.',
	tags:'<a href="consulting.php" class="button">Consulting</a> <a href="icon.php" class="button">ICON</a>',
	img:'images/tile0.jpg',
	imgreplace:'',
	imgx:130,                  
	imgy:80
},{
	name:'Laminar Flow Optimization',
	msg :'Desktop Aeronautics provides state-of-the-art design services to optimize natural laminar flow using its internal analysis tools. Analysis outputs such as these represent pressure distributions and natural laminar flow transition locations on a given wing design.',
	tags:'<a href="consulting.php" class="button">Consulting</a> <a href="aerion.php" class="button">Aerion</a>',
	img:'images/tile1.jpg',
	imgreplace:'',
	imgx:130,
	imgy:60
},{
	name:'AeroVironment, Inc.',
	msg :'Desktop Aeronautics has worked with AeroVironment, Inc. for many years on projects ranging from Pterosaur replicas to flying wings and high-altitude long- endurance aircraft projects.',
	tags:'<a href="consulting.php" class="button">Consulting</a> <a href="aerovironment.php" class="button">Aerovironment</a>',
	img:'images/tile2.jpg',
	imgreplace:'',
	imgx:130,
	imgy:60
},{
	name:'Airbus',
	msg :'Desktop Aeronautics works with Airbus to develop advanced multidisciplinary design tools that will aid in the development of future transport aircraft.',
	tags:'<a href="consulting.php" class="button">Consulting</a><a href="airbus.php" class="button">Airbus</a>',
	img:'images/tile3.jpg',
	imgreplace:'',
	imgx:100,
	imgy:80
},{
	name:'Aerion Corporation',
	msg :'Desktop Aeronautics serves as an integral part of the Aerion design team developing a natural laminar flow supersonic business jet.',
	tags:'<a href="consulting.php" class="button">Consulting</a> <a href="aerion.php" class="button">Aerion</a>',
	img:'images/tile4.jpg',
	imgreplace:'',
	imgx:60,
	imgy:40
},{
	name:'SWIFT glider',
	msg :'Desktop Aeronautics founder, Ilan Kroo, and a team of graduate students at Stanford University designed the SWIFT which demonstrated dramatically improved performance over existing kite-type hang gliders.  The SWIFT is still available for sale.',
	tags:'<a href="consulting.php" class="button">Consulting</a><a href="swift.php" class="button">SWIFT</a>',
	img:'images/tile5.jpg',
	imgreplace:' <div id="ytapiplayer">You need Flash player 8+ and JavaScript enabled to view this video.</div>',
	imgx:15,
	imgy:100
},{
	name:'Rapid Aerospace Geometry Engine',
	msg :'RAGE allows for the generation of a variety of computational aerodynamic models from a central parameterized geometry definition rather than from a CAD model. Designers can quickly and easily develop aircraft geometries that range from very simple to quite detailed for analysis with an assortment of computational aerodynamics tools.',
	tags:'<a href="software.php" class="button">Software</a> </a> <a href="rage.php" class="button">RAGE</a>',
	img:'images/tile6.jpg',
	imgreplace:'',
	imgx:75,
	imgy:120
},{
	name:'Test Support',
	msg :'Desktop Aeronautics provides test support to clients who aspire to evaluate new concepts. We design aerodynamic test articles, conduct simulations, and validate designs with test data.',
	tags:'<a href="consulting.php" class="button">Consulting</a>',
	img:'images/tile7.jpg',
	imgreplace:'',
	imgx:0,
	imgy:60
},{
	name:'DARPA',
	msg :'Desktop Aeronautics provides ongoing advisory services to DARPA on numerous projects. Most recently we worked with DARPA and Northrop Grumman on the design of an unmanned oblique flying wing X-plane demonstrator.',
	img:'images/tile8.jpg',
	imgreplace:'',
	tags:'<a href="consulting.php" class="button">Consulting</a> <a href="darpa.php" class="button">DARPA</a>',
	imgx:0,
	imgy:50
},{
	name:'LinAir',
	msg :'LinAir is a vortex-lattice analysis tool ideal for computing the aerodynamic properties of multiple lifting surfaces. LinAir can rapidly compute stability derivatives and perform design optimization.',
	tags:'<a href="software.php" class="button">Software</a> <a href="linair.php" class="button">LinAir</a>',
	img:'images/tile9.jpg',
	imgreplace:'',
	imgx:120,
	imgy:80
},{
	name:'Blended Wing Body',
	msg :'Desktop Aeronautics personnel have worked on innovative new concept aircraft such as the Blended Wing Body. The above image depicts the results of computational analysis and optimization of boundary ingesting inlets.',
	tags:'<a href="consulting.php" class="button">Consulting</a>',
	img:'images/tile10.jpg',
	imgreplace:'',
	imgx:120,
	imgy:80
},{
	name:'CFD Algorithm Development',
	msg :'Desktop Aeronautics has developed a plug-in for NASA\'s Cart3D that provides a viscous model for the Euler equations to enable Cart3D to produce results that approach the accuracy of Navier-Stokes analysis while retaining the speed, automation, and efficiency of Cart3D.  More information about this plug-in will be available soon.',
	tags:'',
	img:'images/tile11.jpg',
	imgreplace:'',
	imgx:155,
	imgy:40
},{ 
	name:'NASA/Boeing Green Transport',
	msg :'Desktop Aeronautics works with NASA and Boeing in their efforts to create green transport concepts that extend range and fuel efficiency, while reducing carbon emissions.',
	tags:'<a href="consulting.php" class="button">Consulting</a>',
	img:'images/tile12.jpg',
	imgreplace:'',
	imgx:120,
	imgy:100
},{
	name:' Applied Aerodynamics Textbook',
	msg :'This electronic textbook on aerodynamics for university students is read using a web browser. Hundreds of full-color pictures, videos, and custom java applets illustrate the concepts discussed in the text.',
	tags:'<a href="aabook.php" class="button">Applied Aerodynamics Online Textbook</a>',
	img:'images/tile13.jpg',
	imgreplace:'',
	imgx:70,
	imgy:70
},{
	name:'Aircraft Design Workshop (ADW)',
	msg :'ADW is educational software that allows students and hobbyists to explore the tradeoffs in aircraft design and see the resulting impact on performance.',
	tags:'<a href="software.php" class="button">Software</a> <a href="adw.php" class="button">ADW</a>',
	img:'images/tile14.jpg',
	imgreplace:'',
	imgx:10,
	imgy:90
},{
	name:'Propulsion Integration',
	msg :'Desktop Aeronautics design optimization capabilities enable the airframe integration of advanced propulsion concepts such as the 3D bevel nozzle.',
	tags:'<a href="consulting.php" class="button">Consulting</a>',
	img:'images/tile15.jpg',
	imgreplace:'',
	imgx:220,
	imgy:120
}

];
function Tile(){
	this.id = '';
	this.x = 0;
	this.y = 0;
	this.w = 120;
	this.h = 120 ;
	this.padding = 8;
	this.expanded = false;
	this.moverex = 20;
	this.expand = function(){
		clearTimeout(mltime);
		$sm = $(".shadowmatte");
		$sm.remove();
		$this = $("#"+this.id);
		
		$this.unbind();
		if ($("#dark").length === 0){
			$this.parent().append("<div id='dark' style='display:none;position:absolute;width:504px;height:504px;top:4px;left:4px;background:#000;opacity:0.5;filter:alpha(opacity=50)'></div>");
		}
    	if ($("#largeShadow").length===0){
			$this.parent().append("<div id='largeShadow' style='display:none;' ><img src='styles/images/largeshadow.png' style='position:absolute;top:6px;left:6px;'></div>");
		}
   	 	if ($("#closeButton").length===0){
			$this.parent().append("<img id='closeButton' src='styles/images/closebutton.png' style='display:none;position:absolute;top:46px;left:435px;z-index:99'>");
		}
    
		if ($("#tilevid"+this.id.substr(4)).html() != ""){ 
			if ($("#playButton").length===0){  
			   $this.parent().append("<img id='playButton' src='styles/images/playbutton.png' style='display:none;position:absolute;top:146px;left:235px;z-index:99'>");
			}	
			$playButton = $("#playButton");
			$playButton.fadeIn();
			$playButton.click(function(){
				$(this).hide();				$("#tilevid"+$this.attr("id").substr(4)).show().css({"zIndex":1,"position":"relative"});
				$("#tileimg"+$this.attr("id").substr(4)).hide();
				var params = { allowScriptAccess: "always" };
   				var atts = { id: "myytplayer" };
   				//this hardcodes the video id, however this should be in imgreplace and the div to displaythe video should have unique id's based on their tilenumber 
   				swfobject.embedSWF("http://www.youtube.com/v/5x83jL94F7s&hl=en_US&fs=1&rel=0&color1=0x006699&color2=0x54abd6&enablejsapi=1&playerapiid=ytplayer",	"ytapiplayer", "400", "250", "8", null, null, params, atts);
  
			});                                                   
		}
		
		$closeButton = $("#closeButton");
		$closeButton.fadeIn();
		$closeButton.unbind();
		$closeButton.click(function(){
			closeEx($this.attr("id").substr(4));
		});
		$("#dark").fadeIn();
		this.expanded =true;
		t = this
		$("#tileimg"+this.id.substr(4)).animate({top:0,left:0})
		$this.animate({width:400,height:400,top:52,left:52},function(){
			if (t.expanded){
				$("#largeShadow").fadeIn('slow',function(){
					$(window).bind("keydown",im.onkeypress);
				});
			}
		});
		
	}
	this.unexpand = function(){
		$("#largeShadow").hide();
		$("#closeButton").hide();
		$("#playButton").hide();
		$(window).unbind('keydown');
		imgx = (tileContent[this.id.substr(4)].imgx * -1)+'px';
		imgy = (tileContent[this.id.substr(4)].imgy * -1)+'px';
		$("#tileimg"+this.id.substr(4)).animate({top:imgy,left:imgx},'fast');
		$this = $("#"+this.id);
		$("#tilevid"+this.id.substr(4)).hide();
		$("#tileimg"+this.id.substr(4)).show();
		im.unexpandID = $this;
		if (ytplayer){
			ytplayer.pauseVideo()
		}
		setTimeout(function(){
			im.unexpandID.bind("click",im.onclick);
			im.unexpandID.bind("mouseover",im.onmouseover);
			im.unexpandID.bind("mouseout",im.onmouseout);
			},100);
		this.close();
		this.expanded = false;
	}
	this.close = function(){
		clearTimeout(mltime);
		$("#"+this.id).animate({
			'width':this.w ,
			'height':this.h,
			'top':this.y ,
			'left':this.x 
		},100,'swing');
		id = this.id.substr(4);
		$("#shadowmatte"+id).fadeOut('fast',function(){
				$(this).remove();
			});	
		$("#dark").fadeOut(function(){
			$(this).remove();
		});	
	}
	this.open = function(){
		id = this.id.substr(4);
		$sm = $(".shadowmatte");
		$sm.remove();
		$this = $("#"+this.id)
		$this.parent().append("<img class='shadowmatte' id='shadowmatte"+id+"' src='styles/images/shadow.png' id='shadowmatte' style='display:none;position:absolute;height:170px;width:170px;top:0px;left:0px;'></div>");
		$sm = $("#shadowmatte"+id);
		$sm.fadeIn();
		$sm.css({top:this.y -25,left:this.x -25 });
		$(".tile").css({zIndex:0});
		$this.css({zIndex:2});
		$this.animate({
			'width':this.w + this.moverex,
			'height':this.h + this.moverex,
			'top':this.y - this.moverex/2,
			'left':this.x - this.moverex/2
		},100,'linear',function(){
			clearTimeout(mltime);
			mltime = setTimeout(function(){
				//tile[this.id].expand();
			},1000)
		});       
	}
}

var mltime;
var im = {
	unexpandID:0,
	mainlinkon:function(id){
		for (i=0;i<tileContent.length;i++){
      		if (tile[i].expanded){
      			tile[i].unexpand();
      		}
      	}
        tile[id].open();
		mltime = setTimeout(function(){ 	
			tile[id].expand()
		},500);
	},
	mainlinkout:function(id){
		clearTimeout(mltime);
		tile[id].unexpand()
	},
	onmouseover:function(e){
		id = e.currentTarget.id.substr(4)
		tile[id].open();
	},
	onmouseout:function(e){
		id = e.currentTarget.id.substr(4)
		tile[id].close();
				
	},
	onclick:function(e){
		id = e.currentTarget.id.substr(4)
		tile[id].expand();
	},
	onkeypress:function(e){
		var kC  = (window.event) ? event.keyCode : e.keyCode;
      	if(kC==27){
      		for (i=0;i<tileContent.length;i++){
      			if (tile[i].expanded)
      				tile[i].unexpand();
      		}
      	}
	}
}

function closeEx(id){
	tile[id].unexpand();
}

var ytplayer;
function onYouTubePlayerReady(playerId) {
      ytplayer = document.getElementById("myytplayer");
      ytplayer.playVideo()
}

$(document).ready(function(){
	tile = new Array();
	i = 0;
	j = 0;
	
	outputString ="";
	for (h=0;h<tileContent.length;h++){
		outputString +="<div id='tile"+h+"' class='tile'>"
							+ "<div  id='tilevid"+h+"' style='display:none;'>"
							+ tileContent[h].imgreplace
							+ "</div><img id='tileimg"+h+"'" 
							+ " style='position:relative;top:"+ ( tileContent[h].imgy  * -1) + "px;"
							+ "left:"+ (tileContent[h].imgx * -1)+ "px;"
							+"' src=\""+tileContent[h].img+"\">"
							+ "<div class='tilei'><h2>"+tileContent[h].name+"</h2>"
							+ "<div class='tileii'>"
							+ tileContent[h].msg
							+ "</div>"
							+ tileContent[h].tags
							+ "</div></div>";
	}	
	$("#righti").html(outputString);
	$(".tile").each(function(){
		k = tile.length;
		tile[k] = new Tile();
		tile[k].x =  (i * (tile[k].w+tile[k].padding));
		tile[k].y = (j * (tile[k].h+tile[k].padding));
		tile[k].id = "tile"+k;
		$(this).css({'left': tile[k].x,'top':tile[k].y});
		$(this).bind("click",im.onclick);
		$(this).bind("mouseover",im.onmouseover);
		$(this).bind("mouseout",im.onmouseout);
		
		if (i == 3){
			i = 0;
			j++;
		}else{
			i++
		}
	});

});
