var $jq = jQuery.noConflict();

jQuery(document).ready(function(){

	//PROJECTS
	$jq('li.project a').bind('mouseenter', function(){
		var relation = $jq(this).attr('rel');
		var href = $jq(this).attr('href');
		if(href == '#none') {
			$jq('a[rel=' + relation + ']').parent().parent('li.project').css({
				background: '#73BF45'
			});			
		} else {
			$jq('a[rel=' + relation + ']').parent().parent('li.project').css({
				background: '#c40064'
			});
		}

		$jq('span#worked_for').html(relation);
	});
	$jq('li.project a').bind('mouseleave', function(){
		var relation = $jq(this).attr('rel');
		$jq('a[rel=' + relation + ']').parent().parent('li.project').css({
			background: '#333333'
		});
		$jq('span#worked_for').html('');
	});
	
	$jq('a[href=#none]').css({cursor: 'default'});
	
	$jq(window).bind('resize', function() {
		var bird = $jq('body').width();
		var wind = '1100';
		if(bird < wind) {
			$jq('body').addClass('flip');
			$jq('#tweetBottom').addClass('flip');
		} else {
			$jq('body').removeClass('flip');
			$jq('#tweetBottom').removeClass('flip');
		}
	});
	
	//SLIDING TO ANCHORS
  	$jq('a[href*=#]').click(function() {
			var $jqtarget = $jq(this.hash);
   			$jqtarget = $jqtarget.length && $jqtarget
   			|| $jq('[name=' + this.hash.slice(1) +']');
   			if ($jqtarget.length) {
  				var targetOffset = $jqtarget.offset().top;
				var targeted = targetOffset - 95; 
  				$jq('html,body')
  				.animate({scrollTop: targeted}, 1000);
    			return false;
   			}
  	});
	/*
	//WORK OVERLAY
	$jq('a.viewMore').bind('click',function(){
		var position = $jq('div#content').position();
		var overlay = $jq('#work_overlay');
		var postID = $jq(this).parent().parent('li').attr('id');
		$jq(overlay).css({
			left: position.left
		});

		if(overlay.is(':visible')) {
			$jq(overlay).hide().html('');
		} else {			
			var project = $jq('div.' + postID).html();
			$jq('#work_overlay #project_content').append(project);			
			$jq(overlay).fadeIn(400);
		};
	});
	
	//click the clsoseoverlay button
	$jq('#closeOverlay').click(function(){
		$jq('#work_overlay #project_content').html('')
		$jq('#work_overlay').fadeOut(200);
	})
	*/
	
	//if window is resized keep position of overlay in the right place
	$jq(window).bind('resize', function() {
		var position = $jq('div#content').position();
		var overlay = $jq('#work_overlay');
		$jq(overlay).css({
			left: position.left
		})
	});
	
	
	$jq('div#links a').bind('click',function(){
		$jq('.active').removeClass('active');
		$jq(this).addClass('active');
	});
	
	//FEED ME
   jQuery.getFeed({
        url: 'wp-content/themes/Robeam/proxy.php?url=http://robeam.posterous.com/rss.xml',
        success: function(feed) {

            jQuery('#feedMe').append(
				'<h2>' + feed.title + '</h2>' +
			 	'<h3><a href="' + feed.link + '">' + feed.description + '</a></h3>' +
				'<h3 id="rss_pos"><a href="http://robeam.posterous.com/rss.xml">Robeam Posterous via RSS</a></h3>'
			);

            var html = '';

            for(var i = 0; i < feed.items.length && i < 5; i++) {

                var item = feed.items[i];

                html += '<h3>'
                + '<a href="'
                + item.link
                + '">'
                + item.title
                + '</a>'
                + '</h3>';

                html += '<div class="updated">'
                + item.updated
                + '</div>';

            }

            jQuery('#feedMe_posts').append(html);
        }    
    });

});
