var homepageChoice = ['http://www.facebook.com/profile.php?id=5609423057',
					  'http://blog.modernista.com/' , 
					  'http://www.youtube.com/profile?user=modernistaboston&view=playlists', 
				      'http://del.icio.us/modernistaboston/webwork','http://blogsearch.google.com/blogsearch?q=Modernista!+advertising+|+creative+|+interactive+|+agency+|+boston+|+amsterdam+-architecture&ie=UTF-8&scoring=d'];

com.modernista.defaultRefer = homepageChoice[Math.floor( Math.random()*(homepageChoice.length-1) )];

// M! home (if referrer is self or doesn't exist, go to default)
if (com.modernista.refer.substring(0,4)!='http' 
	|| com.modernista.refer.substring(0,25)=='http://www.modernista.com' 
	|| com.modernista.refer.substring(0,21)=='http://modernista.com'){
	//com.modernista.refer='http://en.wikipedia.org/wiki/Modernista!';
	com.modernista.refer = com.modernista.defaultRefer;
}

// used to popup new Flickr window, since Flickr now frame busts
var printUrl = "";

// Create a URL array for easy linking
com.modernista.m_urls = {
	"home" : com.modernista.refer
}

//	This function adds 'copy to clipboard' functionality via a flash hack
function copy_clip(text2copy)
{
	if (window.clipboardData && window.clipboardData.setData) {
    	window.clipboardData.setData("Text",text2copy);
    } else {
		if($('_copyclipDiv')){
			$('_copyclipDiv').destroy();
		}
		swfobject.removeSWF('_copyclip');
		var divcontainer = new Element('div',{ 'id':'_copyclipDiv' });
		Element.insert(document.body, divcontainer );
		swfobject.embedSWF('udm-resources/_clipboard.swf', 
						   '_copyclipDiv', 
						   '0', 
						   '0', 
						   '7', 
						   false, 
						   {'clipboard':escape(text2copy)}, 
						   {}, 
						   {'id':'_copyclip', 
						    'name':'_copyclip'});
	}
}

com.modernista.throwSpeed = [];
com.modernista.mouseEventHandler = function(event)
{
	var element = Event.element(event);
	
	var mnav_container = $('mnav_container');
	var mnav_udm = $('udm');
	var mlogo = $('mlogo');
	var swfoverlay = $('_swfoverlay');
	
	if(!element.draggableMenu){
		mnav_container.originalPosition = [2,2];
		mnav_container.lastPosition = mnav_container.cumulativeOffset();
		element.draggableMenu = new Draggable(mnav_container,{'onDrag':com.modernista.onDrag, 'onEnd':com.modernista.onDragEnd, 'starteffect' : null, 'endeffect' : null, 'reverteffect' : null});
	}
		
	var rect = {};
	var viewportDimensions = document.viewport.getDimensions();
	rect.x = mnav_container.cumulativeOffset()[0]-viewportDimensions.width;
	rect.y = mnav_container.cumulativeOffset()[1]-viewportDimensions.height;
	rect.width = viewportDimensions.width*2;
	rect.height = viewportDimensions.height*2;
	
	Element.setStyle('swfoverlay',{'left':(rect.x + 'px'), 'top':(rect.y + 'px'), 'width':(rect.width + 'px'), 'height':(rect.height + 'px')});
	
	switch(event.type){
		case "mouseover" :
			if( com.modernista.currentURL == "home" 
			   || com.modernista.currentURL == "" ){
				element.setStyle({'cursor':'move'});
			}
			break;
		case "mouseout" :
			if(!element.mouseDown 
			   && !element.isDragging){
				element.setStyle({'cursor':'default'});
			}
			break;
		case "mousedown" :
			element.mouseDown = true;
			element.isDragging = false;
			element.setStyle({'cursor':'move'});
			break;
		case "mousemove" :
			if(element.mouseDown){
				element.isDragging = true;
			}
			//com.modernista.throwSpeed = [ mnav_container.cumulativeOffset()[0]-mnav_container.lastPosition[0], mnav_container.cumulativeOffset()[1]-mnav_container.lastPosition[1] ];
			//mnav_container.lastPosition = mnav_container.cumulativeOffset();
			element.setStyle({'cursor':'move'});
			break;
		case "mouseup" :
			if(element.isDragging){
				element.mouseDown = false;
				element.isDragging = false;
				
				var currentPosition = [ parseInt( mnav_container.getStyle('left') ), parseInt( mnav_container.getStyle('top') ) ];

				currentPosition[0] = Math.max( 0 , currentPosition[0] );
				currentPosition[1] = Math.max( 0 , currentPosition[1] );

				
				var viewportDimensions = document.viewport.getDimensions();	
			
				currentPosition[0] = Math.min( ( viewportDimensions.width - mnav_udm.getWidth() ) , currentPosition[0] );
				currentPosition[1] = Math.min( ( viewportDimensions.height - ( mnav_udm.getHeight() + mlogo.getHeight() ) ) , currentPosition[1] );
				

				if( currentPosition[0] <= 25
						&& currentPosition[1] <= 25 ) {
					currentPosition = [ 0, 0 ];
				}
				
				rect.x = currentPosition[ 0 ]-viewportDimensions.width;
				rect.y = currentPosition[ 1 ]-viewportDimensions.height;
				
				new Effect.Move( mnav_container, {duration:0.5, x: currentPosition[ 0 ], y: currentPosition[ 1 ], mode: 'absolute' });
				new Effect.Move( $('swfoverlay'), {duration:0.5, x: rect.x, y: rect.y, mode: 'absolute' });
				mnav_container.lastPosition = currentPosition;
				 
				element.setStyle({'cursor':'default'});
				// mnav_container.lastPosition = mnav_container.cumulativeOffset();
				
			} else {
				if(mnav_container.lastPosition[0] == mnav_container.cumulativeOffset()[0] 
					&& mnav_container.lastPosition[1] == mnav_container.cumulativeOffset()[1]){
					var ancestors = element.ancestors();
					var i=0;
					while(i<ancestors.length){
						var ancestor = ancestors[i];
						if(ancestor.getAttribute('href')){
							window.location.href = element.ancestors()[0].getAttribute('href');
							break;
						}
						i++;
					}
				}
			}
			break;
	}
}

com.modernista.onDragStart = function(element, event)
{
	var mnav_container = $('mnav_container');
	mnav_container.lastPosition =  mnav_container.cumulativeOffset();
	com.modernista.throwSpeed = [0,0]
}

com.modernista.onDrag = function(element, event)
{
	var mnav_container = $('mnav_container');
	com.modernista.throwSpeed = [ mnav_container.cumulativeOffset()[0]-mnav_container.lastPosition[0], mnav_container.cumulativeOffset()[1]-mnav_container.lastPosition[1] ];
	mnav_container.lastPosition = mnav_container.cumulativeOffset();
}
com.modernista.onDragEnd = function(element, event)
{
	// Event.stopObserving(document, 'mouseup', com.modernista.documentMouseEventHandler);
	// alert(com.modernista.throwSpeed);
}

com.modernista.timeoutID = []
com.modernista.mnavMouseEventHandler = function(event)
{
	var element = Event.element(event);
	while(com.modernista.timeoutID.length>0){
		clearTimeout(com.modernista.timeoutID[com.modernista.timeoutID.length-1]);
		com.modernista.timeoutID.pop();
	}
	var mnav_container = $('mnav_container');
	var swfoverlay = $('_swfoverlay');
	
	var rect = {};
	var viewportDimensions = document.viewport.getDimensions();
	rect.x = mnav_container.cumulativeOffset()[0]-viewportDimensions.width;
	rect.y = mnav_container.cumulativeOffset()[1]-viewportDimensions.height;
	rect.width = viewportDimensions.width*2;
	rect.height = viewportDimensions.height*2;
	
	switch(event.type){
		case "mouseover" :
			if(swfoverlay.showAt){
				swfoverlay.showAt(mnav_container.cumulativeOffset());
			}
			com.modernista.timeoutID[com.modernista.timeoutID.length] = setTimeout("Element.setStyle('swfoverlay',{'left':'" + rect.x + "px', 'top':'" + rect.y + "px', 'width':'" + rect.width + "px', 'height':'" + rect.height + "px'});", 50);
			break;
		case "mouseout" :
			if(swfoverlay.hideAt){
				com.modernista.timeoutID[com.modernista.timeoutID.length] = setTimeout("$('_swfoverlay').hideAt($('mnav_container').cumulativeOffset());", 1250);
			}
			com.modernista.timeoutID[com.modernista.timeoutID.length] = setTimeout("Element.setStyle('swfoverlay',{'left':'" + rect.x + "px', 'top':'" + rect.y + "px', 'width':'1px', 'height':'1px'});", 50);
			break;
	}
}

com.modernista.wikipediaWindow = null;
com.modernista.flickrWindow = null;
com.modernista.twitterWindow = null;
com.modernista.googleNewsWindow = null;
com.modernista.netvibesWindow = null;

com.modernista.navItemClickHandler = function(event)
{
	var element = Event.element(event);
	var id = element.getAttribute('id');
	var rel = '/' + id + '/';
	
	if(rel){
		if(com.modernista.wikipediaWindow){
			com.modernista.wikipediaWindow.close();
			com.modernista.wikipediaWindow = null;
		}
		
		if(com.modernista.flickrWindow){
			com.modernista.flickrWindow.close();
			com.modernista.flickrWindow = null;
		}
		
		if(com.modernista.twitterWindow){
			com.modernista.twitterWindow.close();
			com.modernista.twitterWindow = null;
		}
		
		if(com.modernista.googleNewsWindow){
			com.modernista.googleNewsWindow.close();
			com.modernista.googleNewsWindow = null;
		}
		
		if(com.modernista.netvibesWindow){
			com.modernista.netvibesWindow.close();
			com.modernista.netvibesWindow = null;
		}
		
		if( SWFAddress.getValue()==rel ){
			com.modernista.goHREF(rel);
		} else {
			SWFAddress.setValue(rel);
			if(id == 'wikipedia'){
				setTimeout(com.modernista.openWikipediaWindow, 100);
			}
		}
		
		if(id.indexOf('print') != -1){
			printUrl = id;
			setTimeout(com.modernista.openFlickrWindow, 100);				
		}
		
		if(id == 'twitter'){
			setTimeout(com.modernista.openTwitterWindow, 100);				
		}
		
		if(id == 'googlenews'){
			setTimeout(com.modernista.openGoogleNewsWindow, 100);				
		}
		
		if(id == 'netvibes'){
			setTimeout(com.modernista.openNetvibesWindow, 100);				
		}
	}
	
	Event.stop(event);
}

com.modernista.openWikipediaWindow = function(){
	com.modernista.wikipediaWindow = window.open(com.modernista.m_urls['wikipedia'],'wikipediaWindow','toolbar=yes, location=yes, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes') 
	com.modernista.wikipediaWindow.focus();
}

com.modernista.openFlickrWindow = function(){
	var anchorLink = document.getElementById(printUrl);
	var ahref = anchorLink.getAttribute('href');
	com.modernista.flickrWindow = window.open(ahref,'flickrWindow','toolbar=yes, location=yes, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes') 
	com.modernista.flickrWindow.focus();
}

com.modernista.openTwitterWindow = function(){
	com.modernista.twitterWindow = window.open(com.modernista.m_urls['twitter'],'twitterWindow','toolbar=yes, location=yes, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes') 
	com.modernista.twitterWindow.focus();
}

com.modernista.openGoogleNewsWindow = function(){
	com.modernista.googleNewsWindow = window.open(com.modernista.m_urls['googlenews'],'googleNewsWindow','toolbar=yes, location=yes, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes') 
	com.modernista.googleNewsWindow.focus();
}

com.modernista.openNetvibesWindow = function(){
	com.modernista.netvibesWindow = window.open(com.modernista.m_urls['netvibes'],'netvibesWindow','toolbar=yes, location=yes, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes') 
	com.modernista.netvibesWindow.focus();
}

com.modernista.configureNav = function()
{
	Element.setStyle('mnav_container',{
							'width': 'auto',
							'overflow': 'visible',
							'zIndex':'3'
						});
	
	var navtoggle = new Element('div',{ 'id':'navtoggle' }).update('<a href="javascript://" onclick="com.modernista.toggleNav(); return false;" title="Minimize Nav"><img src="udm-resources/white_minus.gif" alt="Minimize Nav" name="navTog" width="5" height="5" id="navTog" /></a>');
										
	Element.insert($('mnav_container'), navtoggle );

	Event.observe('mnav_container', 'mouseover', com.modernista.mnavMouseEventHandler );
	Event.observe('mnav_container', 'mouseout', com.modernista.mnavMouseEventHandler );

	Event.observe('mlogo', 'mouseover', com.modernista.mouseEventHandler );
	Event.observe('mlogo', 'mouseout', com.modernista.mouseEventHandler );
	Event.observe('mlogo', 'mousedown', com.modernista.mouseEventHandler );
	Event.observe('mlogo', 'mousemove', com.modernista.mouseEventHandler );
	Event.observe('mlogo', 'mouseup', com.modernista.mouseEventHandler );
	
	var anchorLinks = document.getElementsByTagName("a");
	for(var i=0; i<anchorLinks.length; i++){
		var anchorLink = anchorLinks[i];
		if(anchorLink.getAttribute('href') && anchorLink.getAttribute('id')){
			/*
				// old way using static m_urls object
				for(var j in com.modernista.m_urls) {
					var m_url = com.modernista.m_urls[j];
					if(href == m_url){
						var rel = '/'+j+'/';
						Element.writeAttribute(anchorLink,{'rel':rel});
						Event.observe( anchorLink, 'click', com.modernista.navItemClickHandler );
						break;
					}
				}
			*/
			
			// new way uses anchor tag's id as m_urls object key and swfaddress hash, 
			// and href as m_urls object value
			var id = anchorLink.getAttribute('id');
			var href = anchorLink.getAttribute('href');
			com.modernista.m_urls[id] = href;
			Event.observe( anchorLink, 'click', com.modernista.navItemClickHandler );
		}
	}
}

com.modernista.configureWelcomeCloseButton = function()
{
	Element.setStyle('hello', {
						   'left': '153px',
						   'top': '22px',
						   'height': 'auto',
						   'zIndex':'2'
						});
	
	var closehello = new Element('div',{ 'class':'closehello', 'id':'closehello' }).update('<a href="javascript://" onclick="com.modernista.toggleLayer(\'hello\');" title="Close Welcome Message"><img src="images/closebttn.gif" alt="Close Welcome Message" width="40" height="9" border="0" /></a>');
										
	Element.insert($('hello'), closehello );
}

com.modernista.configureEscapeButton = function()
{
	var escapeDiv = new Element('div',{ 'id':'escape' }).update('<a href="'+ com.modernista.refer +'" onclick="com.modernista.runAway(); return false;"><img src="images/escapebttn.gif" title="Leave Modernista.com" width="45" height="9" /></a>');
	Element.insert(document.body,escapeDiv);
}

com.modernista.createIFrame = function()
{
	// check the referrer and write the iframe accordingly
	var currentHash = window.location.hash.substring(1).split('/').join('');
	var srcURL;
	if(currentHash==""){
		currentHash = "home";
		srcURL = com.modernista.refer;
	} else if(currentHash != "twitter" && currentHash != "googlenews" && currentHash != "netvibes" && currentHash.indexOf('print') == -1){
		srcURL = com.modernista.m_urls[currentHash];
	} 
	
	
	com.modernista.currentURL = currentHash;

	this._myiframe = new Element('iframe',{
										'id':'_myiframe', 
										'name':'_myiframe',
										'width':'100%', 
										'height':'100%',
										'frameborder':'0',
										'src':srcURL
										});
	this._myiframe.setStyle({
							'top':'0',
							'left':'0', 
							'width':'100%', 		
							'height':'100%',
							'border':'0'
							});
	
	Element.insert(document.body,this._myiframe);
	
	if(com.modernista.wikipediaWindow){
		com.modernista.wikipediaWindow.close();
		com.modernista.wikipediaWindow = null;
	}
	
	if(com.modernista.flickrWindow){
		com.modernista.flickrWindow.close();
		com.modernista.flickrWindow = null;
	}
	
	if(com.modernista.twitterWindow){
		com.modernista.twitterWindow.close();
		com.modernista.twitterWindow = null;
	}
	
	if(com.modernista.googleNewsWindow){
		com.modernista.googleNewsWindow.close();
		com.modernista.googleNewsWindow = null;
	}
	
	if(com.modernista.netvibesWindow){
		com.modernista.netvibesWindow.close();
		com.modernista.netvibesWindow = null;
	}
	
	if(com.modernista.currentURL == 'wikipedia'){
		com.modernista.moveMenuToLowerLeft();
	}
	
	if(com.modernista.currentURL.indexOf('print') != -1){
		printUrl = com.modernista.currentURL;
		setTimeout(com.modernista.openFlickrWindow, 100);
	}
	
	if(com.modernista.currentURL == 'twitter'){
		setTimeout(com.modernista.openTwitterWindow, 100);
	}
	
	if(com.modernista.currentURL == 'googlenews'){
		setTimeout(com.modernista.openGoogleNewsWindow, 100);
	}
	
	if(com.modernista.currentURL == 'netvibes'){
		setTimeout(com.modernista.openNetvibesWindow, 100);
	}
}
com.modernista.swfoverlay = null;
com.modernista.createSWFOverlay = function()
{
	var swfoverlayDiv = new Element('div',{ 'id':'swfoverlay' }).update('<div id="_swfoverlay"></div>');
	Element.insert(document.body,swfoverlayDiv);
	/*
	if (swfobject.hasFlashPlayerVersion("9.0.0")) {
		var vars = {
					'name1':'hello',
					'name2':'world',
					'name3':'foobar'
				  };
		var att = { 
					'data':'', 
					'width':'100%', 
					'height':'100%',
					'id':'_swfoverlay',
					'name':'_swfoverlay'
				  };
		var par = { 
					'wmode':'transparent', 
					'menu':'false',
					'seamlesstabbing':'false',
					'salign':'LT',
					'scale':'noscale',
					'allowfullscreen':'false'
				  };
		var id = "_swfoverlay";
		SWFObject.embedSWF('', 
						   '_swfoverlay', 
						   '100%', 
						   '100%', 
						   '9', 
						   false, 
						   vars, 
						   par, 
						   att);
		if($('_swfoverlay')){
			com.modernista.swfoverlay = $('_swfoverlay');
		}
	}
	*/
}

com.modernista.createCopyToClipboardLinks = function()
{
	var locpath = location.protocol+"//"+location.host+location.pathname;

	var usalist = "<li class=\"itemHeading\"><a href=\"javascript:copy_clip('Modernista! 109 Kingston Street Second Floor Boston, MA 02119 Phone: (617) 451-1110 Fax: (617) 451-8680');\">copy to clipboard</a></li>";
	var europelist = "<li class=\"itemHeading\"><a href=\"javascript:copy_clip('Modernista! UK Garrick House, 26-27 Southampton Street, London WC2E 7RS, United Kingdom Phone: +44 0207 717 8553 Fax: +44 0207 717 8401');\">copy to clipboard</a></li>";
	
	Element.insert('usaCopyToClipBoardMenu',usalist);
	Element.insert('europeCopyToClipBoardMenu',europelist);
}

com.modernista.toggleNav = function()
{
	if($('udm_nav').visible()){
		Element.hide('udm_nav');
		Element.writeAttribute($('navTog').ancestors()[0], {'title':'Expand Nav'});
		Element.writeAttribute('navTog',{'src':'udm-resources/white_plus.gif', 'alt':'Expand Nav'});
	} else {
		Element.show('udm_nav');
		Element.writeAttribute($('navTog').ancestors()[0], {'title':'Minimize Nav'});
		Element.writeAttribute('navTog',{'src':'udm-resources/white_minus.gif', 'alt':'Minimize Nav'});
	}
}

com.modernista.toggleLayer = function(layerID)
{
	if(Element.visible(layerID)){
		Element.hide(layerID);
	} else {
		Element.show(layerID);
	}
}

com.modernista.goHREF = function(hrefKey){
	com.modernista.currentURL = hrefKey.split('/').join('');
	
	
	if(Element.visible('hello') && com.modernista.currentURL != "")
	{
		Element.hide('hello');
	}
	
	// find the iframe
	var myIFrame = window.frames[0];
	
	// add it to the history and the address bar
	if(com.modernista.currentURL 
	    && com.modernista.currentURL != "") {
		// change the iframe's location
		window.location.hash = '/'+com.modernista.currentURL+'/';

		if (com.modernista.currentURL != "twitter" && com.modernista.currentURL != "googlenews" && com.modernista.currentURL != "netvibes" && com.modernista.currentURL.indexOf("print") == -1) { 
			myIFrame.location.replace( com.modernista.m_urls[ com.modernista.currentURL ] );
			Element.writeAttribute($('escape').descendants()[0], {'href':com.modernista.m_urls[ com.modernista.currentURL ] });
		}
		
		if(com.modernista.currentURL == 'wikipedia'){
			com.modernista.moveMenuToLowerLeft();
		}
	}
	
	if(com.modernista.currentURL.substring(0,2) == 'tv'){
		com.modernista.youTubeMessage();
	}
	
}

com.modernista.moveMenuToLowerLeft = function(){
	var mnav_container = $('mnav_container');
	var mnav_udm = $('udm');
	var mlogo = $('mlogo');
	
	var currentPosition = [ parseInt( mnav_container.getStyle('left') ), parseInt( mnav_container.getStyle('top') ) ];
	

	currentPosition[0] = Math.max( 0 , currentPosition[0] );
	currentPosition[1] = Math.max( 0 , currentPosition[1] );

	
	var viewportDimensions = document.viewport.getDimensions();	

	currentPosition[0] = Math.min( ( viewportDimensions.width - mnav_udm.getWidth() ) , currentPosition[0] );
	currentPosition[1] = Math.min( ( viewportDimensions.height - ( mnav_udm.getHeight() + mlogo.getHeight() ) ) , currentPosition[1] );
	

	if( currentPosition[0] < 155
			&& currentPosition[1] < 155 ) {
		currentPosition = [ Math.max( ( viewportDimensions.width - mnav_udm.getWidth() - 18 ) , 155 ), 37 ];
	}
	
	var secs = (com.modernista.youCanDragIt) ? 5 : 7;
	
	new Effect.Move( $('mnav_container'), {delay: secs, duration:1, x: currentPosition[ 0 ], y: currentPosition[ 1 ], mode: 'absolute' });
}

com.modernista.runAway = function (){
	if(com.modernista.m_urls[com.modernista.currentURL] != "" && com.modernista.currentURL){
		window.location = com.modernista.m_urls[com.modernista.currentURL];
	} else {
		window.location = 'http://www.facebook.com/pages/Modernista/5609423057';
	}
}

//animated text alert
com.modernista.type = function()
{
  if ($(this.destination))
  {
    var dest = $(this.destination);
    if (dest)// && dest.innerHTML)
    {
	  if(dest.innerHTML.length>com.modernista.text.length){
	  	dest.innerHTML = dest.innerHTML.substr(0,dest.innerHTML.length-1);
		currentChar--;
		if(currentChar<=1 || dest.innerHTML.length<=1) {
			Element.setStyle(dest,{'display':'none'});
			return;
	    }
		setTimeout("com.modernista.type()", 5);
	  } else {
      	dest.innerHTML=com.modernista.text.substr(0, currentChar);
      	//dest.innerHTML+=text[currentChar-1];
      	currentChar++
		if (currentChar>com.modernista.text.length)
     	{
       	currentChar=1;
      	}
	  	else
        {
        setTimeout("com.modernista.type()", 25);
      	}
	  }
    }
  }
}

com.modernista.startTyping = function(textParam, destinationParam)
{
 this.text = textParam;
 this.destination = destinationParam;
 var dest=$(destinationParam);
  if(textParam.length>1){
  	currentChar=1;
  	Element.setStyle(dest,{'display':'block'});
  }
  else
  {
  	currentChar = dest.innerHTML.length;
  }
  com.modernista.type();
}

com.modernista.noYouTube = false;
com.modernista.youTubeMessage = function ()
{
	return;
	if(com.modernista.noYouTube){
		return;
	};
	if(!$('youtube')){
		var youtubeDiv = new Element('div',{ 'id':'youtube' });
		Element.insert(document.body, youtubeDiv);
	}
	var t=setTimeout("com.modernista.startTyping('To access the menu again, pause the video player.', 'youtube');",1500);
	t=setTimeout("com.modernista.startTyping('', 'youtube')",12000);
	com.modernista.noYouTube=true;
}

com.modernista.youCanDragIt = false;
com.modernista.youCanDragItMessage = function ()
{

	if(com.modernista.youCanDragIt){
		return;
	};
	if(!$('youtube')){
		var youtubeDiv = new Element('div',{ 'id':'youtube' });
		Element.insert(document.body, youtubeDiv);
	}
	var t=setTimeout("com.modernista.startTyping('&lt;- Psst! You can drag and drop the menu.', 'youtube');",2000);
	t=setTimeout("com.modernista.startTyping('', 'youtube')",9000);
	com.modernista.youCanDragIt=true;
}

com.modernista.handleSWFAddressChange = function(event) {
	com.modernista.goHREF(SWFAddress.getValue());
};

com.modernista.handleResize = function()
{
	var mnav_container = $('mnav_container');
	var mnav_udm = $('udm');
	var mlogo = $('mlogo');
	
	var currentPosition = [ parseInt( mnav_container.getStyle('left') ), parseInt( mnav_container.getStyle('top') ) ];
	

	currentPosition[0] = Math.max( 0 , currentPosition[0] );
	currentPosition[1] = Math.max( 0 , currentPosition[1] );
	
	var viewportDimensions = document.viewport.getDimensions();	

	currentPosition[0] = Math.min( ( viewportDimensions.width - mnav_udm.getWidth() ) , currentPosition[0] );
	currentPosition[1] = Math.min( ( viewportDimensions.height - ( mnav_udm.getHeight() + mlogo.getHeight() ) ) , currentPosition[1] );
	

	new Effect.Move( $('mnav_container'), {delay: 0, duration:0.5, x: currentPosition[ 0 ], y: currentPosition[ 1 ], mode: 'absolute' });
};

com.modernista.init = function ()
{
	this.configureNav();
	this.configureWelcomeCloseButton();
	this.configureEscapeButton();
	this.createCopyToClipboardLinks();
	this.createIFrame();
	this.createSWFOverlay();
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, com.modernista.handleSWFAddressChange);
	
	this.youCanDragItMessage();
};



document.observe("dom:loaded", function() { com.modernista.init(); });

Event.observe(window, "resize", com.modernista.handleResize.bindAsEventListener(this));