/**
 * Flyosity JS
 * (c) Mike Rundle 2010
 */

$(function(){
	
	/* Adding in our mostly-transparent header keywords, then adding their hover animation */
	window.setTimeout( function(){
		var keywords = [{ 'tag': "Apple", 'coord': [41,26] }, { 'tag': "Technology", 'coord': [145,74] },
						{ 'tag': "iPhone", 'coord': [190,18] }, { 'tag': "Interface Design", 'coord': [80,133] },
						{ 'tag': "Mac", 'coord': [330,165] }, { 'tag': "Twitter", 'coord': [448,25] },
						{ 'tag': "iPad", 'coord': [613,11] }, { 'tag': "Cocoa", 'coord': [740,9] },
						{ 'tag': "User Experience", 'coord': [685,60] }, { 'tag': "Objective-C", 'coord': [670,126] },
						{ 'tag': "Icons", 'coord': [816,153] }];
						
		for( var i = 0; i < keywords.length; i++ ) {
			var pos = "style='left: " + keywords[i]['coord'][0] + "px; top: " + keywords[i]['coord'][1] + "px;'";
			$('<span class="keyword" ' + pos + '>' + keywords[i]['tag'] + '</span>')
				.appendTo( $('.centered_header') )
				.animate({ opacity: '.1' }, 1500);
		}
	}, 800);
	
	/* Blog entry title hover animation */
	$('article h1 a').hover( function(){
		$(this).add( $(this).find('em') ).animate({ color: "#b60000" }, 250);
	}, function(){
		$(this).add( $(this).find('em') ).animate({ color: "#002d4c" }, 250);
	});
	
	/* HACK. Wait a little bit for the Twitter widget to load, and then find all
	   reply links and give them the correct class so that @anywhere hovercards
	   show up. Fade the whole block in. */
	window.setTimeout( function(){
		$('.twtr-atreply').addClass('twitter-anywhere-user');
		$('.recent_tweets').fadeIn(350);
	}, 2000);
		
	/* Replace ampersands in blog entry titles with nicer-styled ones */
	$('article h1 a').each( function(){
		var new_string = "";
		for( var i = 0, j = $(this).text().length; i < j; i++ ) {
			if( $(this).html().charAt(i) == "&" ) {
				new_string += "<em>&amp;</em>";
			} else {
				new_string += $(this).text().charAt(i);
			}
		}
		$(this).html( new_string );
	});
	
	/* Enable Twitter hovercards. Other @anywhere features coming soon... */
	twttr.anywhere( function(T){
		T.hovercards();
		
		/*
		T('aside .comments_tweetbox').tweetBox();
		
		var currentUser, screenName, profileImage, profileImageTag;
		
		if( T.isConnected() ) {
			currentUser = T.currentUser;
			screenName = currentUser.data('screen_name');
			profileImage = currentUser.data('profile_image_url');
			profileImageTag = "<img src='" + profileImage + "'/>";
			$("<p>Logged in as " + profileImageTag + " " + screenName + "</p>").appendTo( $('aside.comments') );
		}
		*/
	});

	/* Ajax posting of contact form info */
	eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$(\'p.7 a\').n(\'8\').3(\'4\',\'o://q.r/s/t.u\');$(\'p.7 a.8\').v(\'w\',9(){h($(5).3(\'4\')!==x){0 b=$(\'2.i\').1();0 c=$(\'2.y\').1();0 d=$(\'2.j\').1();0 e=$(\'2.z\').1();0 f=$(\'A.k\').1();h(b==""||d==""||f==""){6(\'l, I B C D E i, j F k.\')}m{0 g=$(5).3(\'4\');$.G(g,{H:b,J:c,K:d,L:e,M:f},9(a){6(a)})}}m{6(\'l, N O P Q R S T 5 U.\')}V W});',59,59,'var|val|input|attr|posting_url|this|alert|send_message|has_js|function||||||||if|name|email|message|Sorry|else|addClass|http||flyosity|com|contact|post123|php|bind|click|undefined|twitter|website|textarea|at|least|need|your|and|post|c_n||c_t|c_e|c_w|c_m|Javascript|must|be|turned|on|to|use|form|return|false'.split('|'),0,{}))
	
});

/*
CSS Browser Selector v0.3.3 (Sep 09, 2009)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);