$(document).ready(function(){
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();
		
		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;
		
		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];
		
		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
		
		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 1000);
	});
        $(".cite").html('<b>&ldquo; </b>'+$(".cite").html()+'<b> &bdquo;</b>');
        $('a.expand_but').click(function(){
            if($('div.expand').hasClass('expanded')){
                $('div.expand').animate({height: "100px"}, 500, function(){$('div.expand').removeClass('expanded');$("a.expand_but").html('Покажи целият текст');});
            }
            else{
                var height = $('div.expand').textHeight()-10;
                $('div.expand').animate({height: height+"px"}, 500, function(){$('div.expand').addClass('expanded');$("a.expand_but").html('Скрий текста');});
            }
        });
        $("#ttip1").tooltip('.ttip');
        $("#ttip2").tooltip('.ttip');
        $('.person').click(function(){
            $('#company').removeClass('block');
            $('#person').addClass('block');
        });
        $('.company').click(function(){
            $('#company').addClass('block');
            $('#person').removeClass('block');
        });
        $("#add_project").click(function(){
            if($('.form2').css('display')=='none'){
                $('.form2').css('display','block');
                $.post('js/project.php', {p: 2});
            }
            else{
                $('.form3').css('display','block');
                $.post('js/project.php', {p: 3});
            }
            if($('.form3').css('display')=='block'){
                $(this).css('display','none');
            }
            else{
                $(this).css('display','block');
            }
        });
        if(window.location.hash=='#участници' || window.location.hash=='#конференция'){
            switchForms(2);
        }
        $('#years').mouseenter(function(){
            $(this).addClass('expanded');
            $('#dd_year_arr').css('display','none');
            $('#dd_year').css('display','none');
            $(this).children('div').each(function(){
               $(this).css('display','block');
               var divId=$(this).attr('id');
               /*if(divId=='prevyear') {var bpos='bottom';}
               elseif(divId=='nextyear'){var bpos='top';}
               else{var bpos='-8px';}*/
               $(this).hover(
                function(){$(this).css('background-image','url(vision/years_hover.png)');},
                function(){$(this).css('background-image','url(vision/years_active.png)');}
               );
               $(this).children('a').each(function(){
                    var yearId=$(this).attr('id');
                    $(this).css('background','url(vision/'+yearId+'_active.png) 11px center no-repeat');
                    $(this).hover(
                        function(){$(this).css('background','url(vision/'+yearId+'_hover.png) 11px center no-repeat');},
                        function(){$(this).css('background','url(vision/'+yearId+'_active.png) 11px center no-repeat');}
                    );
               });
            });
        });
        $('#years').mouseleave(function(){
            $(this).removeClass('expanded');
            $('#dd_year_arr').css('display','block');
            $('#dd_year').css('display','inline');
            $(this).children('div').each(function(){
               $(this).css('display','none');
            });
        });
        /* var id=$(this).attr('id');
            $(this).children('a').css('background','url(vision/'+id+'_active.png) 10px center no-repeat');
            $(this).hover(
            function(){$(this).css('background','url(vision/'+id+'_hover.png) 10px center no-repeat');},
            function(){$(this).css('background','url(vision/'+id+'_active.png) 10px center no-repeat');})*/
});
$.fn.textHeight = function(){
  var html_org = $(this).html();
  var html_calc = '<div>' + html_org + '</div>'
  $(this).html(html_calc);
  var height = $(this).find('div:first').height();
  $(this).html(html_org);
  return height;
};
$.fn.tooltip = function(type){
  $(type).each(function(){
     $(this).focus(function(){
         if($(this).attr('title')!=''){
             var pos=$(this).position();
             $('<div class="tooltip" style="left:'+(pos.left+$(this).width()+15)+'px;top:'+(pos.top)+'px;"><span></span>'+$(this).attr('title')+'</div>').insertAfter($(this));
         }
     });
     $(this).blur(function(){
         $('.tooltip').remove();
     });
  });
}
function switchForms(form){
   if(form==1){
       $("#ttip2").css('display','none');
       $("#ttip3").css('display','none');
       $("#ttip1").css('display','block');
       $(".tab2").removeClass('cur_tab');
       $(".tab3").removeClass('cur_tab');
       $(".tab1").addClass('cur_tab');
   }
   else if(form==2){
       $("#ttip1").css('display','none');
       $("#ttip3").css('display','none');
       $("#ttip2").css('display','block');
       $(".tab1").removeClass('cur_tab');
       $(".tab3").removeClass('cur_tab')
       $(".tab2").addClass('cur_tab');
   }
   else{
       $("#ttip1").css('display','none');
       $("#ttip2").css('display','none');
       $("#ttip3").css('display','block');
       $(".tab1").removeClass('cur_tab');
       $(".tab2").removeClass('cur_tab');
       $(".tab3").addClass('cur_tab');
   }
}
function delProject(project){
   $.post('js/project.php', {del: project});
   $(".form"+project).css('display','none');
   $("#add_project").css('display','block');
}
function getUsers(value){
   $.post('js/project.php', {fetch: value},function(data){
       $("#ttip2").html(data);
   });
}


