$(function(){

  // project image swapper
  $('#images ul li a').click(function() {
    $('#images ul li a').removeClass("current");
    $(this).addClass("current");
    $src = $(this).attr('href');
    $width = parseFloat($(this).attr('width'));
    //$('div.images img').hide().attr('src',$src).fadeIn();
    
    // adjust widths
    //$('#content div.images img').hide().attr('width',$width).delay(900).attr('src',$src).fadeIn();
    $('#content div.images img').hide().attr('width',$width).attr('src',$src).load(function() {
      $(this).fadeIn();
      $('#content div.images').css('width',$width);
      $('#content div.columns').css('width',900-20-$width);
    });
    
    return false;
  });
  
  
  // navigation functionality
  $('#navigation > ul > li > a').click(function() {
    
    // remove 'current' class(es) on all 1st levels
    $('#navigation > ul > li').removeClass("current_page_parent current_page_ancestor");
    
    // add 'current' class on clicked 1st level
    $(this).parent().addClass("current_page_parent");
    
    // hide all 2nd levels
    $('#navigation > ul > li > ul').hide();
    
    // show 2nd level that was clicked
    $(this).parent().find("ul").fadeIn();
    
    // disable link
    return false;
  });


});


jQuery.fn.fadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

var Toggled = true;

$(document).ready(function() {
  // enable tooltips
  tooltip();
  
  // add class to first paragraph in column 1
  p1 = $("#content div.columns div.c1 p:first");
  p1.addClass("first");
  
  // project load
  //$('body.page-template-page_project-php div.c1').hide();
  //$('body.page-template-page_project-php div.c1').fadeIn(1500);
  $width = parseFloat($("body.page-template-page_project-php #images ul li a:first").attr('width'));
  $('body.page-template-page_project-php #content div.images').css('width',$width);
  $('body.page-template-page_project-php #content div.columns').css('width',900-20-$width);
  
});



this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */
	$("a.tooltip, #images ul li a").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip, #images ul li a").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



