/**
 *
 * Zielona Linia
 * skrypty ogólne
 * 
 * @lastmodified 00:53 2010-03-17
 *
 */


/**
 * tabz
 * jQuery plugin
 *
 * @author Mateusz Janik 
 * @revision 2 
 */
(function($){
$.fn.tabz = function(options) {
	var settings = $.extend({
			clActive: 'active'
		}, options);	
	
	return this.each( function() {
		var $root = $(this);
		var activeID = $root.find('.'+settings.clActive+' a').attr('href');
		
		$root.find('a').click(function () {
			( $(activeID).length ) ? $(activeID).hide() : ''; 
			
			$(this).parents('li').addClass(settings.clActive).siblings().removeClass(settings.clActive);
			activeID = $(this).attr('href');
			
			( $(activeID).length ) ? $(activeID).show() : '';
			
			return false
		}) // click
		
	});	// each
}
})(jQuery); 


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}};
 

/* ************************************************
   Document ready 
*/
$(function(){

	
	/**
	 * Tooltipy
	 * 
	 * @url http://www.learningjquery.com/2009/12/binding-multiple-events-to-reduce-redundancy-with-event-delegation-tooltips
	 * @todo przerobić na plugin
	 */
	var $liveTip = $('<div id="livetip"><i></i><div></div></div>').hide().appendTo('body');
	var tipTitle = '';

	$('.mod_quicklaunch.ql_compact')
	.add('.article a[title]')
	.bind('mouseover mouseout mousemove', function(event) {
		var $link = $(event.target).closest('a');

		if (!$link.length) { return; }
		var link = $link[0];
		
		
		if (event.type == 'mouseover' || event.type == 'mousemove') {
			$liveTip.css({
			  top: event.pageY + 12,
			  left: event.pageX + 12
			});
		}

		if (event.type == 'mouseover') {
			tipTitle = link.title;
			link.title = '';
			//$liveTip.html('<div>' + tipTitle + '</div><div>' + link.href + '</div>')
			$liveTip.find('div').html(tipTitle)
			.end()
			.show();
		}

		if (event.type == 'mouseout') {
			$liveTip.hide();
			if (tipTitle) {
					link.title = tipTitle;
				}
		}
	}); // Tooltipy
	
	
	/* Aktywacja zakładek na s. głównej */
	$('#main.home #home-mod_finder ul.tabs').tabz({clActive:'active'});	
	
	
	/**
	 * Pokazywanie / ukrywanie - np. sekcji w formularzach
	 */
	(function(){
		var $toggler = $('.showhide-toggler');
		
		$toggler
		.find('a.toggler-show').click( function () {
			var $wrapper = $(this).closest('.showhide');
			$wrapper.find('.showhide-content').slideDown('fast', function() {
				$wrapper.toggleClass('showhide_hidden').toggleClass('showhide_shown');
			} );
			return false
		} )
		.end()
		.find('a.toggler-hide').click( function () {
			var $wrapper = $(this).closest('.showhide');
			$wrapper.find('.showhide-content').slideUp( function() {
				$wrapper.toggleClass('showhide_hidden').toggleClass('showhide_shown');
			} );
			return false
		} );		
	
	})(); // showhide
	
	
	/**
	 * Zmiana rozmiaru tekstu i trybu tekstowego
	 */
	$('#readability .size > a').click( function () {
		var cl = 'font'+$(this).attr('class');
		$('body').removeClass('fontsize-1 fontsize-2').toggleClass(cl)
		$.cookie('readability_size', cl);
		return false;
	} );
	
	$('#readability .txt > a').click( function () {
		if ($(this).hasClass('txt-0')) {
		// tryb tekstowy:
			$('body').removeClass('contrast').toggleClass('light');
			$.cookie('readability_txt', $('body').hasClass('light') ? 'light' : '');
		} else if ($(this).hasClass('txt-1')) {
		// kontrast:
			$('body').removeClass('light').toggleClass('contrast');
			$.cookie('readability_txt', $('body').hasClass('contrast') ? 'contrast' : '');
		}
		return false;
	} );
	// Włączenie trybu na start strony wedle zapisanych ciastek:
	$('body').addClass($.cookie('readability_size'));
	$('body').addClass($.cookie('readability_txt'));
	
	
	/**
	 * Minimalna wysokość #main (by stopka była na dole zawsze)
	 */
	$('#main').css('min-height', 
		parseInt($(window).height()) - $('#header').height() - parseInt($('#footer').outerHeight())-20
	);
	
	
	/**
	 * table restyler
	 */
	(function(){
		var $oferty_pracy = $('.tres-oferty_pracy');
		$oferty_pracy
		.find('table:eq(1)')
		.find('> tbody > tr > td').addClass('td')
		.end()
		.find('> thead td').addClass('th')
		.end()
		.end()
		.find('p :empty').remove();
		
		var $kwalifikacje = $('.tres-kwalifikacje');
		$kwalifikacje		
		.find('table:eq(2)')
		.find('> tbody > tr > td:first-child').addClass('th align-right').css({'text-align':'right','vertical-align':'top'}).siblings().addClass('td');
		
		var $szkolenia = $('.tres-szkolenia');
		$szkolenia		
		.find('table:eq(1)')
		.find('> thead td').addClass('th')
		.end()
		.find('> tbody > tr > td').addClass('td')
		.end()
		.end()
		.find('p :empty').remove();
		
		var $historia_zatr = $('.tres-historia_zatr');
		$historia_zatr		
		.find('table:eq(2)')
		.find('> thead td').addClass('th')
		.end()
		.find('> tbody > tr > td').addClass('td')
		.end()
		.end()
		.find('p :empty').remove();
		
		var $dane_personalne = $('.tres-dane_personalne');
		$dane_personalne		
		.find('table:eq(1)')
		.find('td:nth(0)').addClass('th').css({'text-align':'right'})
		.end()
		.find('td:nth(1)').addClass('td').css({'text-align':'left'})
		
	})();
	
	
}) // Document ready
