
// Initialization commands

$(function($){


});



var Site = {

	init:function(page){
		
		//try{$.localScroll();}catch(e){}	
	
		switch(page){
			case 'home':
				var so = new SWFObject("/flash/TenthAndGApplication.swf", "flash-header", "643", "540", "9");
	   			so.addParam("wmode", "transparent");
				so.addParam('salign','bl');
				so.addParam('scale','noBorder');
	   			so.write("homeflash");
	   		break;
			case 'location':
				var so = new SWFObject("/flash/733_map.swf", "flash-map", "959", "423", "9", "#FFFFFF");
	   			so.addParam("wmode", "window");
				so.addParam('bgcolor','#FFFFFF');
	   			so.write("location-map");
			break;
			
			case 'gallery':
				this.galleryInit('exterior');
			break;
			
			case 'floorplans':
			
			break;
			
			case 'building-efficiency':
				var so = new SWFObject("/flash/TenthAndGApplication.swf", "flash-header", "643", "540", "9");
	   			so.addParam("wmode", "transparent");
				so.addParam('salign','bl');
				so.addParam('scale','noBorder');
	   			so.write("efficiency-flash");			
			break;
		}
		
		$('.floorplan_popup').click(function(){
			var fwin = window.open($(this).attr('href'),'FloorplanWin','width=940,height=540,scrollbars=auto');
			return false;
		});
		
		if($('#contacts-generator').length > 0) $('#contacts-generator').validate();
		
		$('#location-google').hover(function(){
			$(this).find('img').attr('src','/images/button-google-over.gif')
		},function(){
			$(this).find('img').attr('src','/images/button-google.gif')
		}).click(function(){
			window.open('http://maps.google.com/maps?f=q&hl=en&geocode=&q=+750+9th+Street,+NW,+Suite+900+Washington,+DC+20001-4516&sll=37.0625,-95.677068&sspn=38.775203,79.101563&ie=UTF8&ll=38.900335,-77.024117&spn=0.009318,0.019312&z=16&iwloc=addr','gwin');
		});

		$('#location-print-map').hover(function(){
			$(this).find('img').attr('src','/images/button-print-map-over.gif')
		},function(){
			$(this).find('img').attr('src','/images/button_printable_map_241x36.gif')
		}).click(function(){
			window.open('/pdf/733_map.pdf','mwin');
		});
		
		$('#green-download').hover(function(){
			$(this).find('img').attr('src','/images/button-green-features-pdf-o.gif')
		},function(){
			$(this).find('img').attr('src','/images/button-green-features-pdf.gif')
		}).click(function(){
			window.open('/pdf/733_green.pdf','mwin');
		});
		
		
		$('#factsheet-download').hover(function(){
			$(this).find('img').attr('src','/images/button-factsheet-over.gif')
		},function(){
			$(this).find('img').attr('src','/images/button-factsheet.gif')
		}).click(function(){
			window.open('/pdf/733_bldgfacts.pdf','mwin');
		});
		
		
		$('#stacking-download').hover(function(){
			$(this).find('img').attr('src','/images/button-building-stacking-over.gif')
		},function(){
			$(this).find('img').attr('src','/images/button-building-stacking.gif')
		}).click(function(){
			window.open('/pdf/stacking-plan.pdf','mwin');
		});

		
		$('#location-metro').hover(function(){
			$(this).find('img').attr('src','/images/button-metrosys-over.gif')
		},function(){
			$(this).find('img').attr('src','/images/button-metrosys.gif')
		}).click(function(){
			window.open('http://www.wmata.com/','mwin');
		});

		$('a').each(function(){
			var me = $(this);
			if(me.attr('href').match(/^http/)){
				me.bind('click',function(e){
					var pwin = window.open(me.attr('href'),'popwin');
					e.stopPropagation();
					e.preventDefault();
					return false;
				});
			}
		});

		$('#request-info').hover(function(){
			$(this).find('img').attr('src','/images/requestinfo-over.gif')
		},function(){
			$(this).find('img').attr('src','/images/requestinfo.gif')
		}).click(function(){
			window.location = '/contact';
			return false;
		});
		
		$('#download-brochure').hover(function(){
			$(this).find('img').attr('src','/images/button-brochure-over.gif')
		},function(){
			$(this).find('img').attr('src','/images/button-brochure.gif')
		}).click(function(){
			window.open('/pdf/10thandG.pdf','pdfWin');
			return false;
		});

		
		$('#topnav img').each(function(){
			var me = $(this);
			if(me.parent().attr('href').match(page)){
				me.attr('src',me.attr('src').replace(/\.gif/,'-over.gif'));
			}else{
				me.hover(
					function(){
						me.attr('src', me.attr('src').replace(/\.gif/ig,'-over.gif'));						
					},function(){
						me.attr('src', me.attr('src').replace(/-over/ig,''));			
					});
			}

			if(me.parent().next('ul').length > 0){
				var menu  = me.parent().next('ul');
				me.get(0).menuTimer = null;
				me.get(0).menuActive = false;
				
				menu.bind('mouseover',function(e){
					me.get(0).menuActive = true;
					clearTimeout(me.get(0).menuTimer);
				}).bind('mouseout',function(e){
					me.get(0).menuActive = false;
					me.get(0).menuTimer = setTimeout(function(){
						if(me.get(0).menuActive == false){
							menu.slideUp('fast');
						}
					},250);
				});
				
				me.bind('mouseover',function(e){
					var me = $(e.target);
					var offset = me.offset();
					me.get(0).menuActive = true;
					clearTimeout(me.get(0).menuTimer);
					menu.slideDown('fast');
				})
				.bind('mouseout',function(e){
					var me = $(e.target);
					me.get(0).menuActive = false;
					me.get(0).menuTimer = setTimeout(function(){
						if(me.get(0).menuActive == false){
							menu.slideUp('fast');
						}
					},100);
					
				});
				
			}
				
		});
	},
	
	galleries:{
		'interior':{
			base: '/images/gallery/interior',
			images:Array(
				{thumb:'/thumbs/int_ren_05_entrance_081308_people_sm.jpg',large:'/large/int_ren_05_entrance_081308_people.jpg',caption:'Main Lobby Entrance'},
				{thumb:'/thumbs/int_ren_07_lobby_081308_people_sm.jpg',large:'/large/int_ren_07_lobby_081308_people.jpg',caption:'Main Lobby'},
				{thumb:'/thumbs/int_ren_08_conferenceroom_sm.jpg',large:'/large/int_ren_08_conferenceroom.jpg',caption:'Conference Room'}
			)			
		},
		'exterior':{
			base:'/images/gallery/exterior',
			images:Array(
				{thumb:'/thumbs/ext_ren_01_aerial_080708_sm.jpg',large:'/large/ext_ren_01_aerial_080708.jpg',caption:'Rooftop View'},
				{thumb:'/thumbs/ext_ren_02_entrance_081308_people_sm.jpg',large:'/large/ext_ren_02_entrance_081308_people.jpg',caption:'Main Lobby Entrance'},
				{thumb:'/thumbs/ext_ren_02_midrise_080708_sm.jpg',large:'/large/ext_ren_02_midrise_080708.jpg',caption:'Corner of G Place and 10th Street'},
				{thumb:'/thumbs/ext_ren_03_aerial_080708_sm.jpg',large:'/large/ext_ren_03_aerial_080708.jpg',caption:'G Street Arial View'},
				{thumb:'/thumbs/ext_ren_05_080708_sm.jpg',large:'/large/ext_ren_05_080708.jpg',caption:'Corner of G Street and 10 Street Image'},
				{thumb:'/thumbs/ext_ren_04_080708_sm.jpg',large:'/large/ext_ren_04_080708.jpg',caption:'Office with Verizon Center View'}
			)
		},
		'neighborhood':{
			base:'/images/gallery/neighborhood',
			images:Array(
				{thumb:'/thumbs/neigh_d2x_3994_sm.jpg',large:'/large/neigh_d2x_3994.jpg',caption:'Clyde\'s Restaurant'},
				{thumb:'/thumbs/neigh_d2x_4000_sm.jpg',large:'/large/neigh_d2x_4000.jpg',caption:'Gallery Place'},
				{thumb:'/thumbs/neigh_nd3_2321_sm.jpg',large:'/large/neigh_nd3_2321.jpg',caption:'Chinatown'},
				{thumb:'/thumbs/neigh_nd3_2340_sm.jpg',large:'/large/neigh_nd3_2340.jpg',caption:'Verizon Center'},
				{thumb:'/thumbs/neigh_nd3_2370_sm.jpg',large:'/large/neigh_nd3_2370.jpg',caption:'Zaytinya Restaurant'},
				{thumb:'/thumbs/neigh_nd3_2394_sm.jpg',large:'/large/neigh_nd3_2394.jpg',caption:'McCormick'},
				{thumb:'/thumbs/neigh_nd3_2537_sm.jpg',large:'/large/neigh_nd3_2537.jpg',caption:'Pedestrian Walkway'},
				{thumb:'/thumbs/neigh_nd3_2552_sm.jpg',large:'/large/neigh_nd3_2552.jpg',caption:'Starbucks'} 
			)			
		},
		'office':{
			base:'/images/gallery/office',
			images:Array(
				{thumb:'/thumbs/poten_views_ifm0858_sm.jpg',large:'/large/poten_views_ifm0858.jpg',caption:'National Portrait Gallery'},
				{thumb:'/thumbs/poten_views_ifm0878_sm.jpg',large:'/large/poten_views_ifm0878.jpg',caption:'Washington Monument'},
				{thumb:'/thumbs/poten_views_ifm1566_sm.jpg',large:'/large/poten_views_ifm1566.jpg',caption:'United States Capitol'}		
			)
		}
		
	},
	currentItem:0,
	currentGallery: '',
	galleryInit:function(gallery){	

		var theGallery = Site.galleries[gallery];
		Site.currentGallery = gallery;
		Site.currentItem = 0;

		if($.browser.msie && typeof document.body.style.maxHeight == 'undefined'){
			$('#gallery-prev img').attr('src','/images/gallery-prev.gif');
			$('#gallery-next img').attr('src','/images/gallery-next.gif');
		}

		$('#gallery-images th a').each(function(){
			var atag = $(this);
			var re = new RegExp('#'+gallery);
			
			atag
			.unbind('mouseenter')
			.unbind('mouseover')
			.unbind('mouseout')
			.unbind('mouseleave')
			.unbind('click').click(function(){
				Site.galleryInit($(this).attr('href').substr(1));
			});					
			
			if(atag.attr('href').match(re)){
				atag.find('img').attr('src',atag.find('img').attr('src').replace(/\.gif|-over.gif/gi,'-over.gif'));
			}else{
				atag.find('img').attr('src',atag.find('img').attr('src').replace(/\.gif|-over.gif/gi,'.gif'));
				atag.hover(
					function(){atag.find('img').attr('src',atag.find('img').attr('src').replace(/\.gif/gi,'-over.gif'))},
					function(){atag.find('img').attr('src',atag.find('img').attr('src').replace(/-over/gi,''))}
				);					
			}
		});

		$('#gallery-prev img').hover(function(){$(this).css('cursor','pointer');Site.galleryPreview('prev')},function(){Site.galleryPreviewClose('prev')}).click(Site.galleryPrev);
		$('#gallery-next img').hover(function(){$(this).css('cursor','pointer');Site.galleryPreview('next')},function(){Site.galleryPreviewClose('next')}).click(Site.galleryNext);

		var tbody = $('#gallery-images table tbody');
		tbody.find('a').unbind('click');
		tbody.empty();
		
		var tr = $('<tr>');

		for(i=0;i<theGallery.images.length;i++){
			var im  = $('<img>').attr('src',theGallery.base + theGallery.images[i].thumb);
			var im2  = $('<img>').attr('src',theGallery.base + theGallery.images[i].large);
			if(i % 4 == 0 && i > 0){
				tbody.append(tr);
				var tr = $('<tr>');
			}
			var atag = $('<a rel="gallery" title="'+theGallery.images[i].caption+'" href="'+theGallery.base + theGallery.images[i].large+'"><img src="'+theGallery.base + theGallery.images[i].thumb+'" /></a>');
			var td = $('<td>').append(atag);
			tr.append(td);				
		}
		
		if(i%4 > 0){
			var rem = 4-i%4;
			for(j=0;j<rem;j++){
				tr.append( $('<td>') );
			}
		}
	
		tbody.append(tr);
		tbody.find('a').lightBox({fixedNavigation:true});

	}
}
