$(document).ready(function() {
	// /projects block	 
	$('.project-block').mouseover(function(){
		$(this).css('cursor','pointer');
		$(this).fadeTo('fast', 0.5);	
	}).click(function(){
		var location = $(this).attr('data-location');
		window.location = location;
	}).mouseout(function(){
		$(this).fadeTo('fast', 1);
	});
	
	// add dev link to current project
	developmentUrl = window.location.pathname.replace('projects','development');
	if($('#project-view').attr('data-email'))
	{
		$('#project-view').html('<a href="/email'+developmentUrl+'">View Project</a>');
	}
	else if($('#project-view').children('.website').attr('data-website') == 'true')
	{
	
	}
	else
	{
		$('#project-view').html('<a href="'+developmentUrl+'">View Project</a>');
	}
	
	//current active menu item
	var path = location.pathname.substring(1);
	pathArr = path.split('/');
   	if(path)
   	{
   		$('#main-menu a[href$="'+pathArr[0]+'"]').attr('class', 'active');
	}
	/*// project cycle
	var currentProject = $('#project-title').attr('previous-project');
	// get previous and next project
	$.ajax({
	    type: 'GET',
	    dataType: 'json',
	    url: window.location.pathname,
	    data: 'project-previous='+currentProject,
	    timeout: 5000,
	    success: function(data, textStatus ){
	       alert('request successful');
	    },
	    error: function(xhr, textStatus, errorThrown){
	       alert(errorThrown);
	    }
	});*/
	// project cycle events
	$('#content').prepend('<div id="project-info-next" class="tk-report">'+$('#project-next').attr('name')+'</div>');
	$('#content').prepend('<div id="project-info-previous" class="tk-report">'+$('#project-previous').attr('name')+'</div>');
	$('#project-next').mouseover(function(){
		$(this).css('cursor', 'pointer');
		$('#project-info-next').fadeIn(500);
		//$(this).basicToolTip($('#content'), $(this).attr('name'));
	}).click(function(){
		window.location = $(this).attr('data-location');
	}).mouseout(function(){
		$('#project-info-next').fadeOut('fast');
	});	
	$('#project-previous').mouseover(function(){
		$(this).css('cursor', 'pointer');
		$('#project-info-previous').fadeIn(500);
		//$(this).basicToolTip($('#content'), $(this).attr('name'));
	}).click(function(){
		window.location = $(this).attr('data-location');
	}).mouseout(function(){
		$('#project-info-previous').fadeOut('fast');
	});
	
	// project load flash file
	$('.project-flash-item').mouseover(function(){
		$(this).css('cursor','pointer');
	}).click(function(){
		$('html, body').animate({
			scrollTop: $("#project-menu").offset().top
			}, 500);
		var loadSWF = $(this).attr('data-location');
		var width = $(this).attr('w');
		var height = $(this).attr('h');
		$('#flash-object-embed').flash({swf:loadSWF+'.swf',width:width,height:height}); 
	});
	
	//main menu actions
	$('#main-menu a').mouseover(function(){
		$(this).css('cursor','pointer');
		$(this).fadeTo('fast', 0.5);
	}).mouseout(function(){
		$(this).fadeTo('fast', 1);
	})
	
	//contact form
	$('#select-contact-form').mouseover(function(){
		$(this).css('cursor','pointer');
		$(this).fadeTo('fast', 0.5);
	}).mouseout(function(){
		$(this).fadeTo('fast', 1);
	}).click(function(){
		$('html, body').animate({
			scrollTop: $("#copy-contact-area").offset().top
			}, 500);
	});
	$('#contact-form-submit').mouseover(function(){
		$(this).css('cursor','pointer');
		$(this).fadeTo('fast', 0.5);
	}).click(function(){
		$('#contact-form').fadeTo('slow',0.1);
		$('#contact-form-submit').removeAttr('id');
		$('#form-section').append('<div id="message"></div>');
		// validate form	
		var name = $('#contact-form-name').val();
		var email = $('#contact-form-email').val();	
		var message = $('#contact-form-message').val(); 
		var properties = 'name='+name+'&email='+email+'&message='+message+'&process_form=1';
		$.ajax({  
		  type: "POST",  
		  url: window.location.pathname,  
		  data: properties,  
		  success: function() {
		      
		    $('#message').html("<h2>Contact Form Submitted!</h2>")  
		    .append("<p>We will be in touch soon.</p>")  
		    .hide()  
		    .fadeIn(1500);  
		  }  
		}); 
		return false;
	}).mouseout(function(){
		$(this).fadeTo('fast', 1);
	});
	
	//footer twitter
	/*$("#twitter").getTwitter({
		userName: "actiumind",
		numTweets: 3,
		loaderText: "Loading tweets...",
		slideIn: true,
		showHeading: true,
		headingText: "Tweet Tweet",
		showProfileLink: true
	});*/
	
	$('a[rel="external"]').click( function() 
	{
        window.open( $(this).attr('href') );
        return false;
    });
	
});

(function($){
	$.fn.basicToolTip = function(content, projectName) {
		content.prepend('');
	};
})(jQuery);

$.fn.textWidth = function(){
  var sensor = $('<div />').css({margin: 0, padding: 0});
  $(this).append(sensor);
  var width = sensor.width();
  sensor.remove();
  return width;
};

