﻿/**
 * Navigation drop down fix
 */
/* //perkelta i Menu bloka
$('document').ready(function(){
  var lastChild = $('#meniu ul');
  
  $('#meniu > li').each(function(i, item){    
    $(item).mouseout(function(){
      if (window.opera) {  
        $('#flash').append(document.createElement('div'));
      }
    });
  });  
  
  beforeBeforeLastChild   = lastChild[lastChild.length - 5];
  beforeLastChild = lastChild[lastChild.length - 2];
  lastChild       = lastChild[lastChild.length - 1];
    
  $(beforeBeforeLastChild).css('left', '-73px');
  $(beforeLastChild).css('left', '-135px');
  $(lastChild).css('left', '-133px');
});
*/ //perkelta i Menu bloka
/**
 * Main page tab handler
 */
function tabHandler(parent)
{
  var active  = $(parent + ' > ul li.active');
  var content = $('#' + active.attr('alt')); 
    
  $(parent + ' > ul li').each(function(){
    if (!$(this).hasClass('mask'))
    {
     $(this).click(function(){
        /* Removing selected tab selection */
        if (active != 'none')
        {
          active.removeClass('active');
          $(parent + ' > ul li.mask').remove();
        }
        
        $(this).addClass('active');
        $(this).after('<li class="mask">' + $(this).text() + '</li>');

        
        /* Changing content section */
        content.css('display', 'none');
        content = $('#' + $(this).attr('alt'));
        content.css('display', '');
        
        active = $(this);
      });  
    }
  });
}

/**
 *  Left menu sliders
 */
$('document').ready(function(){
  $('.expandable').each(function(){
    $(this).find('.expand-side').click(function(){
      
      var exp = $('.expandable').find('.expandable-area');
      var trn = $(this).attr('title').split('|');
             
      if (exp.attr('alt') == 'expanded')
      {
        exp.slideDown();
        exp.attr('alt', 'collapsed');
        
        var a = $(this).find('a');
        
        a.attr('title', trn[0]);
        a.text(trn[0]);
      }
      else
      {   
        exp.slideUp();
        exp.attr('alt', 'expanded'); 
        
        var a = $(this).find('a');
        
        a.attr('title', trn[1]);
        a.text(trn[1]);
      }
    });
  });  
});

/**
 * Naujienų switcheris
 */
var ns = {
    activeClass : 'active',
    activeItem  : false,
    items       : new Array(),
    delay       : 4000,
    timer       : false,
    switcher : function(item)
    {
        if(ns.items[item] === undefined)
            return false;

        if(ns.activeItem !== item)
        {
            $('#newsImg').attr('src', ns.items[item].image);
            $('#newsText').html(ns.items[item].text);

            if(ns.activeItem !== false)
                $('#nsItem'+ ns.activeItem).attr('class','');

            $('#nsItem'+ item).attr('class', ns.activeClass);
            ns.activeItem = item;
        }
    },
    addItem : function(image, text)
    {
        if(image !== undefined && text !== undefined)
        {
            var pos = ns.items.length;
            ns.items[pos] = {
                image : image,
                text  : text
            };
        }
    },
    getItem : function(item)
    {
        ns.switcher(item);
        ns.resetTimer();
    },
    getNext : function(timer)
    {
        var pos = ns.activeItem + 1;
        if(ns.items[pos] === undefined)
            pos = 0;

        ns.switcher(pos);
        ns.resetTimer();
    },
    getPrev : function()
    {
        var pos = ns.activeItem - 1;
        if(pos < 0)
            pos = ns.items.length - 1;

        ns.switcher(pos);
        ns.resetTimer();
    },
    resetTimer : function()
    {
        if(ns.timer)
        {
            clearTimeout(ns.timer);
            ns.activateTimer();
        }
    },
    activateTimer : function()
    {
        ns.timer = setTimeout("ns.getNext(true);", ns.delay);
    }
};


function getTooltip(display, source, target)
{
    var w = $('#'+ source).width();
    var h = $('#'+ source).height();
    var height = $('#'+ target).height();
    $('#'+ target).css({
        left : w-5,
        top  : -(height / 2) + (h / 2),
        display : display ? 'block' : 'none'
    });
}

jQuery.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* @example value = $.getURLParam("paramName");
*/ 
 getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;

	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});

$(document).ready(function () {
  // Call printer
  if ($.getURLParam('print'))
  {
    // Insert logo imagei
    $('.logo').html('<img src="/images/lrv-logo-for-print.jpg" alt="" border="0" />');

    window.print();
  }
});
