/* SPARKART */
/* Javascript
----------------------------------------------------------------------------- */


	var headings = 'div#sidebar div.headlines h3';
	var links = 'ul#tags a, div#sidebar h4 a, ul.actions a';


	$(document).ready(function() {
		
		$(headings + ',' + links).attr('style','visibility: hidden');
		
	});


/* PAGE LOAD
----------------------------------------------------------------------------- */


	$(window).load(function() {


		Cufon.replace(headings, { fontFamily: 'VAG Rounded Bold' });
		Cufon.replace(links, { fontFamily: 'VAG Rounded Bold', hover: true });
		$(headings + ',' + links).attr('style','visibility: visible');


/* ANNOUNCEMENTS
----------------------------------------------------------------------------- */


	function archiveAnnouncement($announcement) {

		var headline = $announcement.children('h4').children('a').text();
		var date = $announcement.children('strong').text().split(',');
		var month = date[0].slice(0,3);
		var day = date[0].split(/\s/);
		var day = ' ' + day[1];

		$('<li style="display: none"><a href="#">' + headline + '&nbsp;&nbsp;' + month + day + '</a></li>').prependTo('#archive').fadeIn('fast');	

		if (page == "office" && alias.length > 0) {
			pageTracker._trackEvent('Announcements', 'Closed', 'by', alias);
		}

	}

	$('<ul id="archive"><li><a class="archive" href="/blog/announcements">&gt; See Past Announcements</a></ul>').insertAfter('div#content > h2');
	Cufon.replace('#archive a.archive', { fontFamily: 'VAG Rounded Bold' });	

	var read = $.cookie('sparkart-announcements');
	
	$('#announcements ul.stories > li').each(function(index) {
	
		var $this = $(this);
		var topic = $(this).children('h4').children('a').attr('href').split('/');
		var topic = topic[3];
		
		if ($(this).children('div.story').children('ul').children('li').children('strong:contains(Username)').length > 0) {
		
			$(this).children('div.story').find('ins').text(alias).next().text('(or ' + email + ')');
			
		}
		
		$('<a href="#" class="close" title="Close">Close</a>').appendTo(this).click(function() {
		
			$this.slideUp(function() {
	
				if (read != null && !read.match(topic)) {
					read += '-' + topic;
				} else {
					read = topic;	
				}
		
				$.cookie('sparkart-announcements', read, { expires: 3650 });		
				
				if ($('#archive li').length < 3) {
					archiveAnnouncement($this);
				}
	
			});
			
			return false;
		
		});

		if (read && read.match(topic)) {

			if ($('#archive li').length < 3) {
				archiveAnnouncement($this);
			}			

		} else {

			setTimeout(function() { $this.fadeIn(); }, 500 * index);	

		}

	});


/* CODE EXPANDER
----------------------------------------------------------------------------- */


	$('pre').each(function() {
	
		var code = $(this).children('code').text().split('\n');
		var code = code.length;

		if (code > 30) {
			$(this).wrap('<div class="expand"></div>');	
		}

	});

	$('<a class="expand" href="#">Expand</a>').appendTo('div.expand');

	$('div.expand a.expand').click(function() {
	
		$(this).parent().removeClass('expand');
		$(this).remove();
		return false;
	
	});


/* GOOGLE MAP
----------------------------------------------------------------------------- */


	if ($('#map').length > 0) {

		var mapOptions = {

			zoom: 16,
			center: new google.maps.LatLng(37.808429, -122.266545),
			mapTypeControl: false,
			navigationControl: true,
			navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN},
			mapTypeId: google.maps.MapTypeId.HYBRID      

		}

		var map = new google.maps.Map(document.getElementById("map"), mapOptions);                          
		var geocoder = new google.maps.Geocoder();

	}


/* SNAKES
----------------------------------------------------------------------------- */
	

	if (navigator.userAgent.match('Safari') || navigator.userAgent.match('Firefox/3')) {

		var snakes = new SWFObject(asset_host + "/flash/sidebar.swf", "sideSnakes", "100%", "100%", "9", "#ffffff" );
		var snakeColor;
		
		snakes.addVariable( "snakeColor", "0xEEEEEE" );
		snakes.addParam( "wmode", "opaque" );
		snakes.addParam( "menu", "false" );
		snakes.write( "snakes" );
	
	}

	function killSnakes() {

		$('#snakes').fadeOut('slow', function() {
			$('#snakes').remove();
		});
		
	}

	$(window).scroll(killSnakes);
	$(window).mousedown(killSnakes);


/* USAGE TRACKING
----------------------------------------------------------------------------- */


	if (page == "office" && alias.length > 0) {
		pageTracker._trackEvent('Office Page Usage', 'Visit', 'from', alias);
	}


/* END OF FILE */

	});
