/*
 * Funkcja tworzy dymek podpowiedzi dla podanej tablicy elementów
 */
(function($) {jQuery.fn.generateHints = function(el) {
		var offsetParent = this;
		var o = el.shift();
		var selector = o.selector;
		$(selector)
				.bt(
						'<div style="line-height: 18px;"><span style="float:right;"><a id="close_hint" href="#" class="black">x</a></span><span class="grey4">'
								+ o.content
								+ '</span><p><a id="next_hint" href="#" class="black">'
								+ o.next + '</a></p></div>', {
							preShow : function(box) {
								$(box).css( {
									"text-align" : 'left'
								})
							},
							showTip : function(box) {
								$(box).fadeIn(500);
							},
							hideTip : function(box, callback) {
								$(box).animate( {
									opacity : 0
								}, 500, callback);
							},
							postShow : function(box) {
								$('a#close_hint', box).click(function() {
									$(selector).btOff();
									return false;
								});
								$('a#next_hint', box).click(function() {
									if (el.length > 0) {
										offsetParent.generateHints(el);
									} else {
										$(selector).btOff();
									};
									return false;
								});
							},
							trigger : 'none',
							cornerRadius : 10,
							fill : 'RGB(240,240,240)',
							offsetParent : offsetParent,
							strokeWidth : 1,
							strokeStyle : '#8f8e8e',
							clickAnywhereToClose : false,
							closeWhenOthersOpen : true,
							shadow : true,
							shadowOffsetX : 2,
							shadowOffsetY : 2,
							shadowBlur : 8,
							shadowColor : 'rgba(0,0,0,.9)',
							shadowOverlap : false,
							positions : o.positions
						}).btOn();
	};
})(jQuery);

// przypina dymki w momencie załadowania się strony
$(document).ready(function() {
	// niepotrzebne w przypadku elementu już pozycjonowanego relatywnie najlepiej przenieść do css
	$('#doc').css( {
		position : 'relative'
	});

	if (document.cookie != "") {
		var cookies = document.cookie.split("; ");
		if ($.inArray('_hints=true', cookies) != -1) {
			return;
		}
	}

	$('#doc').generateHints($.hintArray);

	var exdate = new Date(); exdate.setDate(exdate.getDate() + 366);

	document.cookie = "_hints=true; expires=" + exdate.toGMTString();
});

