/*!
 * jQuery custom scripts file
 * 
 * Dariusz Pobożniak
 * http://pobozniak.pl
 */

$(function () {
    $('.intro article').setEqualHeight();  
    $('.shortoffer dl').setEqualHeight();
    $('input', '#logintab').placeholder();
    $('.lightbox').fancybox();
    $('h3', '#logintab').click(function () {
        var $this = $(this),
            $sect = $this.next();
        if ($sect.is(':visible')) {
            $this.removeClass('opened');
            $sect.hide();
        } else {
            $this.addClass('opened');
            $sect.show();
        }
    });
});

(function ($) {
	$.fn.placeholder = function (customOptions) {
		var defaultOptions = {
			pclass: 'placeholder' 
		},
        options = $.extend({}, defaultOptions, customOptions);
		
		var fakeInput = document.createElement('input'),
			phsupport = ('placeholder' in fakeInput);
			
		return this.each(function () {
			if (!phsupport) {
				var field = $(this),
					orgText = field.attr('placeholder'),
					clearValue = function () {
                        if (field.val() === orgText) {
                            field.val('');
                        }
                    };
				field
					.val(orgText)
					.addClass('placeholder')
					.bind({
						focus: function () {
							field.removeClass('placeholder');
							clearValue();
						},
						blur: function () {
							if ($(this).val().length === 0) {
								$(this).val(orgText);
								$(this).addClass('placeholder');
							}
						}
					})
					.parents('form').submit(function () {
						clearValue();
					});
			}
		});
	};
}(jQuery));

jQuery.fn.setEqualHeight=function(o) {
    var maxHeight=0;
    var maxElement=null;
    	jQuery(this).each(function(i) {
      		if((jQuery(this).height()+parseInt(jQuery(this).css("padding-bottom"))+parseInt(jQuery(this).css("padding-top")))>maxHeight) {
    		maxHeight=jQuery(this).height()+parseInt(jQuery(this).css("padding-top"))+parseInt(jQuery(this).css("padding-bottom"));
    		maxElement=this;
    	}
    });
    //jQuery(this).not($(maxElement)).each(function() {$(this).height(maxHeight-parseInt(jQuery(this).css("padding-top"))-parseInt(jQuery(this).css("padding-bottom")))})
    jQuery(this).each(function() {$(this).height(maxHeight-parseInt(jQuery(this).css("padding-top"))-parseInt(jQuery(this).css("padding-bottom")))})
}
