$(document).ready(function() {
   
            
      $("#profile_tabs ol").localScroll({ 
            target:"#profile_tabs",
            duration:0,
            hash:true
      });
      
      
      // Initialize history plugin.
      // The callback is called at once by present location.hash. 
      $.historyInit(pageload);
		
      // set onlick event for buttons
      $("a[rel='history']").click(function(){
	// 
	var hash = this.href;
        $(this).blur();
	hash = hash.replace(/^.*#/, '');
	// moves to a new page. 
	// pageload is called at once.        
                
	$.historyLoad(hash);
	return false;
      });

      
      
      //Tooltip
       var mykeyword;
    function removetooltip(){$('.tooltip').children().remove();$('.tooltip').remove();}

	
    $('.keyword').hover(
        function(e){
            mykeyword = $(this).text();
            this.tip = this.title;
            
            if (this.tip){
		this.title = "";
                
		var mywidth = $(this).width();
                var myheight = $(this).height();
                var position = $(this).position();		
                
                $(this).addClass('bhover').append('<div id="mytip" class="tooltip"><div class="t"><span>'+this.tip+'</span></div><div class="arrow" style="display:none"></div></div>');
                
		     //alert(this.tip);               
                
                $(".tooltip").css({top: position.top,left: position.left}).show().css({opacity:0}).animate({opacity:.9,top: position.top-$(".tooltip").height()},250,function(){
		
                        $(".arrow").slideDown();
                
                        if ($("#mytip").length > 0) {
                            if ( (document.documentElement.scrollTop || document.body.scrollTop) >= $(".tooltip").offset().top){
                                $(".tooltip").animate({top: document.documentElement.scrollTop},250);
                  }}

			});}

		}, 

		function() {

			$(this).removeClass('bhover');

			removetooltip();

			this.title = this.tip;


		}

	);
    
      
      
   $("#profile_menu a").click(function(){
      
      var node = this;
      var targetNode =$(this).attr('href');
      targetNode += "-pop";
            
      $(".projectinfo").css({ display:"none" });
      $(targetNode).css({ display:"block" });
      
      $("#profile_menu a").removeClass("selected");      
      $(node).addClass("selected");
		

   });
   
   $('#s_profile_menu a:first').addClass('selected');
   $("#s_profile_menu a").click(function(){
      
      var node = this;
      var targetNode =$(this).attr('href');
      targetNode += "-pop";
            
      $(".projectimg").css({ display:"none" });
      $(targetNode).css({ display:"block" });
      
      $("#s_profile_menu a").removeClass("selected");      
      $(node).addClass("selected");		

   });
   
   
   $('#p_profile_menu a:first').addClass('selected');
   $("#p_profile_menu a").click(function(){
      
      var node = this;
      var targetNode =$(this).attr('href');
      targetNode += "-pop";
            
      $(".projectimgp").css({ display:"none" });
      $(targetNode).css({ display:"block" });
      
      $("#p_profile_menu a").removeClass("selected");      
      $(node).addClass("selected");		

   });  
  
  
   $(".projs").mouseover(function(){
		var imgdad = this.id;
                //alert(imgdad);
		$("#" + imgdad + "-image").css({backgroundPosition:"0 -74px"});
	})
	$(".projs").mouseout(function(){
		var imgdad = this.id;
		$("#" + imgdad + "-image").css({backgroundPosition:"0 0"});
	});
        
      $(".closer").click(function(){         
            var dad = this.parentNode.id;         
            $(".projectinfo").css({ display:"none" });	
	    $("#who-copy").removeClass("faded");	
      
   });     

});

// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser
      function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		if($("#profile_tabs") && document.location.hash){                
                  $.scrollTo("#profile_tabs");
            
                  var anchorTags = document.getElementsByTagName("a");
                  $("#profile_menu a").removeClass("selected");
                  
                  for (var i = 0; i < anchorTags.length ; i++){
                  
                       if (anchorTags[i].href.indexOf(document.location.hash) !== -1){
                             addClass(anchorTags[i], 'selected');                                               
                              
                              var idx = anchorTags[i].href.indexOf(document.location.hash);
                              var targetNode = anchorTags[i].href.substring(idx);
                              targetNode += "-pop";
                        
                              $(".projectinfo").css({ display:"none" });                              
                              $(targetNode).css({ display:"block" });
                        }
                  }                                 
            } else {
                   $("#profile_menu a").removeClass("selected");  
                   $('#profile_menu a:first').addClass('selected');
            }
	} else {
                  $("#profile_menu a").removeClass("selected");  
		  $('#profile_menu a:first').addClass('selected');
	}
      }


function addClass(element, value) {         
        if (!element.className) {   
               element.className = value;  
        } else {  
           var newClassName = element.className;  
              newClassName += " ";  
              newClassName += value;  
              element.className = newClassName;  
         }
}