/// <reference path="jquery.min-vsdoc.js" />


tab_nr_sel =1;
tab_nr =0;
				
function initTabs()
{

	jQuery(document).ready(function()
	{
		$('.tabs .t').mouseover(function() 
		{
			if( $(this).hasClass("t1"))
				tab_nr =1;
			else if( $(this).hasClass("t2"))
				tab_nr =2;
			else
				tab_nr =3;
				
			if( tab_nr_sel != tab_nr )
			{
				$('.tabs  .t' + tab_nr_sel).removeClass("t" +  tab_nr_sel + "a");				
				$('.tabs  .te' + tab_nr_sel).removeClass("te_a");	
				$('.tabs  .te_' + tab_nr_sel).removeClass("te_a");				
			}							
			
			tab_nr_sel = tab_nr;
			
			$('.tabs  .te' + tab_nr).addClass("te_a");	
			$('.tabs  .te_' + tab_nr).addClass("te_a");				
			$('.tabs  .t' + tab_nr ).addClass("t" + tab_nr + "a");				
			
		});
	});

}

function initAccordion() {
    jQuery(document).ready(function () {
        $("#accordion").accordion();
        $("#datepicker").datepicker();
    });
}

function initPublications()
{
	jQuery(document).ready(function(){
		$('#public a.ec').click(function() 
		{
			
			var act = $('#public a.act:first');
			if (act.attr("href") == $(this).attr("href"))
                            {
                                window.location = $(this).attr("href");
                                return false;
                            }


			if (typeof act == 'object'  )   // && act!=$(this)
			{
				act.removeClass("act");
				
				if( act.hasClass("index_last"))
					act.addClass("last");

				if( act.hasClass("index_first"))
				{
					act.addClass("first");
				}	
				
				var nexta = $( act.next() ); 
				var nextnexta = $( act.next().next() ); 
				
				var hh = nexta.height();	
				
				nexta.hide(300);
			 	//nexta.animate({height: '1px' }, 300, 'swing', function(){ $(this).css({display:'none', height: hh})  }  );

				if( nextnexta.hasClass("index_last"))
					nextnexta.removeClass("shadow_last");
				nextnexta.removeClass("shadow");
				
				if ( $(this)[0] == act[0] )
					return;
				
			}
		
			var next = $(this).next();						
			var nextnext = $(this).next().next();
			var height = next.height();
			
			//next.css({height: '1px', display: 'block' });
			//next.animate({height: height }, 300, 'swing' );
			
			next.slideDown("normal");
			
			if( $(this).hasClass("act"))
			{
				$(this).removeClass("act");
			}	
			else	
			{
				$(this).addClass("act");
				if( $(this).hasClass("index_last"))
				{
					$(this).removeClass("last");
					next.addClass("last");
				}

				if( $(this).hasClass("index_first"))
				{
					$(this).removeClass("first");
				}
				
				
				if( nextnext.hasClass("index_last") )	
					nextnext.addClass("shadow_last");
				else
					nextnext.addClass("shadow");
			}	
			
			return false;
		});
	});
}


var scrolling_gal = 0;

function initGalleries()
{
	max_pics = 6;
	scroll_width = 115;

	
	jQuery(document).ready(function()
	{
		$('.bl_con .galleries a.next').each( 
		
			function( intIndex )
			{	
				var link_prev = $(this).prev();
				var container = $(this).next();	
				var lis = $(container).find('li');
				var ul = $(container).find('ul');
				var lis_length = lis.length;
                                var width = 0;
                                var visible_pix = 0;
                                lis.each(function(index){
                                    width = width + $(this).width()+11;
                                    if (width <= 600)
                                    visible_pix++;
                                });
				// permazai paveikslu kad scrollinti
				if( width <= 600)
					$(this).addClass('next_not');
				else
				{
				
					//------------- prasukam pirmyn ----------
					$( this ).bind ( "click", function(){
					
						if( scrolling_gal )
							return;
							
						if( $(this).hasClass('next_not') )
						{
							scrolling_gal =0;	
							return;
						}	
							
						scrolling_gal =1;	
					
						var scrolled = container.attr('scrolled');
						if( scrolled == undefined)
							scrolled = 1;
						else
							scrolled = parseInt(scrolled) + 1;
						container.attr('scrolled', scrolled);
						
						$(link_prev).addClass('prev_act');
						
						if( scrolled == lis_length - visible_pix)
							$(this).addClass('next_not');	
						
						var ML = parseInt($(ul).css('marginLeft'));
                                                var scrollwidth = width/lis_length;
                                                 var scrolpix = width - 600;
                                                 if(scrolpix > scrollwidth)
                                                     scrolpix = scrollwidth;
                                                scrollwidth = scrolpix;
                                                if(width - 600 + ML < scrollwidth)
                                                    {
                                                         scrolpix = width - 600 + ML;
                                                    }


						$(ul).animate({marginLeft: ML - scrolpix + 'px'}, 200, function()
							{ 
								scrolling_gal = 0 ;
							} );
						
						
					});
				}	
			}
		);
		
		$('.bl_con .galleries a.prev').each( 
		
			function( intIndex )
			{	
				var link_next = $(this).next();
				var container = $(this).next().next();	
				var lis = $(container).find('li');
				var ul = $(container).find('ul');
				var lis_length = lis.length;
				var width = 0;
                                lis.each(function(index){
                                    width = width + $(this).width() +11;
                                });
				//------------- prasukam atgal ----------
				$( this ).bind ( "click", function()
				{
					if( scrolling_gal )
							return;
							
					var scrolled = container.attr('scrolled');

					if( scrolled == undefined)
					{
						scrolling_gal =0;
						return;
					}	
					else
					{
						scrolling_gal =1;	
						scrolled = parseInt(scrolled) ;
					}	
						
					//if( scrolled != lis_length - visible_pix + 1)
						$(link_next).removeClass('next_not');
						
					if( scrolled > 0)
					{	
						container.attr('scrolled', scrolled-1);
						var ML = parseInt($(ul).css('marginLeft')); 
						
						if(scrolled ==1 )
							$(this).removeClass('prev_act');
                                                var scrollwidth = width/lis_length;
                                                var scrollpix = scrollwidth;
                                                if (ML + scrollwidth > 0)
                                                    scrollpix = -ML;
						$(ul).animate({marginLeft: ML + scrollpix + 'px'}, 200, function()
								{ 
									scrolling_gal = 0 ;
								});
					}
					
					else
					{
						scrolling_gal = 0;
					}
				});
				
			}
		);		
		
	});	

}

function initTree()
{
(function($){

$.fn.simpleTooltip = function(options){
	var opts = $.extend({}, $.fn.simpleTooltip.defaults, options);
	return this.each(function(){
		var me = $(this);
		var originalTitle = "";
		me.hover(function(e){
			originalTitle = me.attr('title');
			titleDisplayed = (originalTitle && !opts.overrideElementTitle ? originalTitle : opts.title).replace(/ :: /g, "<br />");
			me.attr("title","");
			if(titleDisplayed.length>0){
				$("body").append("<div id='v-tooltip'>"+titleDisplayed+"</div>");
				$("#v-tooltip")
					.animate({opacity: 0.9}, opts.delay)
					.css("top",(e.pageY - opts.xOffset) + "px")
					.css("left",(e.pageX + opts.yOffset) + "px")
					.fadeIn("fast");
			}
      	},function(){
			me.attr("title", originalTitle);
			$("#v-tooltip").remove();
		});
		me.mousemove(function(e){
			$("#v-tooltip")
				.css("top",(e.pageY - opts.xOffset) + "px")
				.css("left",(e.pageX + opts.yOffset) + "px");
		});
	});
}
 
$.fn.simpleTooltip.defaults = {
	title: null,
	xOffset: 10,
	yOffset: 12,
	delay: 200,
	overrideElementTitle: false
}
})(jQuery);

jQuery(document).ready(function () {

    $('.tree .act ').mouseover(function () {
        $(this).addClass('act_show');
    });


    $('.tree .act ').mouseout(function () {
        $(this).removeClass('act_show');
    });


    $('.tree .expand, .tree .collapse').click(function () {
        var ul = $(this).parent().parent().next();

        if ($(this).hasClass('expand')) {
            $(this).removeClass("expand");
            $(this).addClass("collapse");
            ul.slideDown(0);
        }
        else {
            $(this).removeClass("collapse");
            $(this).addClass("expand");
            ul.slideUp(0);
        }

    });
    $('a.an').simpleTooltip();
    $('a.per').simpleTooltip();
});
}




