var width = 0;
  if (window.innerWidth) {
	width = window.innerWidth
    } else if (document.documentElement &&
                document.documentElement.clientWidth) {
	width = document.documentElement.clientWidth
    } else if (document.body) {
	width = document.body.clientWidth
    }
  if (width < 25) {
	width=screen.availWidth
  }

iconW=width/9.5
iconH=iconW*1.385
logoW=width/5
logoH=logoW/5.565
linuxW=width/8.19
linuxH=linuxW/.822
menufont=width/120
menuwidth=width/15
pxsize = width/84
emsize = 1
if (width < 900) {
	  emsize = .8
  }
if (width > 1200) {
	  emsize = 1.2
  }

userAgent=navigator.userAgent
  if (userAgent.indexOf("iPhone") > 0) {
	  pxsize = pxsize*2.5;
    }

document.write('<style type="text/css">#menu {margin: 0; padding: 0}');
document.write('#menu li {float: left; list-style: none; font: ' + menufont + 'pt Verdana, Arial, sans-serif;}');
document.write('#menu li a {display: block; background: #e4e4e4; padding: 3px 4spx; text-decoration: none; border-right: 1px solid white; width: ' + menuwidth + 'px; color: purple; white-space: nowrap}');
document.write('#menu li a:hover {background: #e0e0e0}');
document.write('#menu li ul {margin: 0; padding: 0; position: absolute; visibility: hidden; border-top: 1px solid white; z-index: 42}');
document.write('#menu li ul li {float: none; display: inline}');
document.write('#menu li ul li a {width: auto; background: #e4e4e4}');
document.write('#menu li ul li a:hover {background: #ffffff}');
document.write('h1 {font-family: Verdana, Arial, sans-serif; font-size: ' + (pxsize * 1.2) + 'px; font-weight: bold; text-align: center}');
document.write('h2 {font-family: Verdana, Arial, sans-serif; font-size: ' + pxsize + 'px; font-weight: bold; text-align: center}');
document.write('h3 {font-family: Verdana, Arial, sans-serif; font-size: ' + (pxsize * .8) + 'px; font-weight: bold; text-align: center}');
document.write('h4 {font-family: Verdana, Arial, sans-serif; font-size: ' + (pxsize * .9) + 'px; font-weight: normal; text-align: center}');
document.write('li {font-family: Verdana, Arial, sans-serif; font-size: ' + pxsize + 'px}');
document.write('p.text {font-family: Verdana, Arial, sans-serif; font-size: ' + pxsize + 'px; font-weight: normal}');
document.write('p.notes {font-family: Verdana, Arial, sans-serif; font-size: ' + (pxsize * .8) + 'px; font-weight: normal}');
document.write('td.itunes {font-family: Verdana, Arial, sans-serif; font-size: ' + (pxsize * .8) + 'px; font-weight: normal}');
document.write('a[href $=\'.pdf\'] {padding-right: 18px; background: transparent url(http://www.andersensilva.com/images/icon_pdf.gif) no-repeat center right}');
document.write('a[href ^=\'mailto:\'] {padding-right: 18px; background: transparent url(http://www.andersensilva.com/images/icon_mailto.gif) no-repeat center right}');
document.write('li.quotes {list-style:none; list-postion:inside; font-family: Verdana, Arial, sans-serif; font-size: ' + (pxsize * .8) + 'px; font-weight: bold; text-align: center}');
document.write('</style>');

var timeout    = 250;
var closetimer = 0;
var ddmenuitem = 0;

function menu_open()
{  menu_canceltimer();
   menu_close();
   ddmenuitem = jQuery(this).find('ul').css('visibility', 'visible');}

function menu_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function menu_timer()
{  closetimer = window.setTimeout(menu_close, timeout);}

function menu_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

jQuery(document).ready(function()
{  jQuery('#menu > li').bind('mouseover', menu_open)
   jQuery('#menu > li').bind('mouseout',  menu_timer)});
   
document.onclick = menu_close;

var numquotes; 
var curritem=0; 
jQuery(document).ready(function(){ 
    numquotes = jQuery("#quotes li").hide().size(); 
    jQuery("#quotes li:eq("+curritem+")").show(); 
    setInterval(ticknews,5000);
}); 

function ticknews() {
    jQuery("#quotes li:eq("+curritem+")").hide(); 
    curritem = ++curritem%numquotes; 
    jQuery("#quotes li:eq("+curritem+")").show(); 
}

jQuery(document).ready(function() {
    jQuery.ajaxSetup({ cache: true });

    // Send JSON request
    // The returned JSON object will have a property called "results" where we find
    // a list of the tweets matching our request query
    jQuery.getJSON(
        'http://search.twitter.com/search.json?callback=?&rpp=1&q=from:joyinthenew',
        function(data) {
            jQuery.each(data.results, function(i, tweet) {
                // Uncomment line below to show tweet data in Fire Bug console
                // Very helpful to find out what is available in the tweet objects
                //console.log(tweet);

                // Before we continue we check that we got data
                if(tweet.text !== undefined) {
                    var date_tweet = new Date(tweet.created_at);
                    var date_now   = new Date();
                    var date_diff  = date_now - date_tweet;
                    var hours      = Math.round(date_diff/(1000*60*60));
		    var minutes    = Math.round(date_diff/(1000*60));
		    var tweet_time = '';
		    
		    if(minutes < 60) {
			tweet_time += minutes + ' minutes ago';
		        }
			else {
			tweet_time += hours + ' hours ago';
			}

                    // Build the html string for the current tweet
                    var tweet_html = '<div class="tweet_text" style="font-family: Verdana, Arial, sans-serif; font-size: ' + pxsize + 'px">';
                    tweet_html    += '<b>From <a href="http://twitter.com/joyinthenew" target="_blank">Twitter</a>, ' + tweet_time + ': Andy </b>';
                    tweet_html    += tweet.text + '<\/div>';

                    // Append html string to tweet_container div
                    jQuery('#tweet_container').append(tweet_html);
                }
            });
        }
    );
});

