$(document).ready(function(){

//custom scroll
$('#maincontent').jScrollPane({showArrows:true, scrollbarWidth:10, scrollbarMargin:0});

//custom scroll podpięty w biogramach
$('div.biogram-prawa').jScrollPane({showArrows:true, scrollbarWidth:10, scrollbarMargin:0});

//custom scroll podpięty w opisie projektu
$('div.projekt-opis').jScrollPane({showArrows:true, scrollbarWidth:10, scrollbarMargin:0});


//tabela z projektami - ładowanie podglądów projektów
$('table.tabela-projekty tr').hover( 
  function() {
    var is_eng = false;
    if (document.location.href.indexOf('/en/') > -1)
      is_eng = true;
    if (is_eng==true)
      $('#photos-110').load("en/projekt_preview.php?prid=" + $(this).attr('id'));
    else
      $('#photos-110').load("projekt_preview.php?prid=" + $(this).attr('id'));
  },
  function() {
    //$('#photos-110').empty();
  }
);

//tabela z projektami - sortowanie
// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
  id: 'sort_ingarden_dates', 
  is: function(s) { 
    return false; 
  }, 
  format: function(s) { 
  // format your data for normalization 
    var test_arr = new Array();
    var n = '';
    
    if (s.indexOf('-') > 0 ) {
        test_arr = s.split('-');
        if (test_arr[1] != '') {
          n = test_arr[1]+'-'+test_arr[0];
        }
        else {
          n = '9999'+'-'+test_arr[0];
        }
    }
    else {
        n = s+'-'+s;
    }
    return n;
  }, 
    //text albo numeric
    type: 'text' 
}); 

$(function() { 
  $("table#sortingtable").tablesorter({ 
      headers: { 
        4: { 
          sorter:'sort_ingarden_dates' 
        } 
      } 
    });
});                  

$('table.tabela-projekty tr td.c2,table.tabela-projekty tr td.c3,table.tabela-projekty tr td.c4,table.tabela-projekty tr td.c5').hover(
  function() {
    //alert('a');
    var is_eng = false;
    if (document.location.href.indexOf('/en/') > -1)
      is_eng = true;
    if (is_eng==true)
      $(this).attr('title','sort');
    else
      $(this).attr('title','sortowanie');
  },
  function() {}
);

$('table.tabela-projekty tr td.c2').click(
  function() {
    $('table.tabela-projekty tr th.c2').trigger('click');
  } 
);
$('table.tabela-projekty tr td.c3').click(
  function() {
    $('table.tabela-projekty tr th.c3').trigger('click');
  } 
);
$('table.tabela-projekty tr td.c4').click(
  function() {
    $('table.tabela-projekty tr th.c4').trigger('click');
  } 
);
$('table.tabela-projekty tr td.c5').click(
  function() {
    $('table.tabela-projekty tr th.c5').trigger('click');
  } 
);

// podświetlanie obrazka na liście po najechaniu myszką
$('div.items > a > img').hover( 
  function() {
    $(this).addClass('currimg');
    $('#photos-100-opis-text').append($(this).attr('rel'));
  },
  function() {
    $(this).removeClass('currimg');
    $('#photos-100-opis-text').empty();
  }
);

//wymienianie obrazka dużego
$('div.items > img').click(
  function() {
    $('div.items > img').removeClass('currimg');
    $('.projekt-grafika img').replaceWith('<img src="' + ($(this).attr('rel')) + '" />');
    $(this).addClass('currimg');
    //alert ('<img src="' + ($(this).attr('rel')) + ' />');
  }
);

//galeria (na stronie biuro)
$(".lightbox").lightbox({
	fileLoadingImage : "css/lightbox/loading.gif",
	fileBottomNavCloseImage : "css/lightbox/close.gif",
	displayHelp: false,
	displayTitle: false,
	displayImageData: false,
	strings : {
		help: ' \u2190 / P - previous image\u00a0\u00a0\u00a0\u00a0\u2192 / N - next image\u00a0\u00a0\u00a0\u00a0ESC / X - close image gallery',
		prevLinkTitle: 'previous',
		nextLinkTitle: 'next',
		prevLinkText:  '&laquo; Wstecz',
		nextLinkText:  'Dalej &raquo;',
		closeTitle: 'zamknij galerię',
		image: 'Grafika ',
		of: ' z '
	}
});

//haki w IE6, nie do przeskoczenia w inny sposób
if ( document.all && !window.opera && !window.XMLHttpRequest && $.browser.msie )
  {
	 	 var isIE6 = true;
	   $("#nav li").css("width", "80px");
	   $(".nav li").css("width", "20px");
	}

//scrolowanie obrazów na dole strony
$(".scrollable").scrollable({ 
  size: 6,
  naviItem : 'img',
  activeClass: 'currimg',
  clickable: false
});

var s = $('.scrollable').scrollable({api: true});
$(".next,.prev").hover(function() {
  var is_eng = false;
  if (document.location.href.indexOf('/en/') > -1)
    is_eng = true;
  if (is_eng==true)
    $(this).attr('title','click to scroll');
  else
    $(this).attr('title','kliknij, aby przewijać');
}, function() {
});

if(typeof(s) !== 'undefined') {
  if (s.getPageAmount()<2) {
      //alert(s.getPageAmount());
      $(".next,.prev").addClass('disabled');
    }
}
/*
$(".next,.prev").hover(function() {
  var self = this;
  var is_eng = false;
  if (document.location.href.indexOf('/en/') > -1)
    is_eng = true;
  if (is_eng==true)
    $(this).attr('title','hover mouse cursor to scroll graphics');
  else
    $(this).attr('title','najedź kursorem myszy, by przewijać grafiki');
  $(this).data('interval', setInterval(function() {
    $(self).click();
  }, 300));
  
}, function() {
  if ($(this).data('interval')) {
    clearInterval($(this).data('interval'));
    $(this).data('interval', null);
  }
});
*/ 
/*
-- po staremu, hover triggeruje clicka
$('div.items > img').hover( 
  function() {
    $(this).trigger('click');
  },
  function() {
    //nic
  }
);
*/

});

