function setHome() {
	document.body.style.behavior = 'url(#default#homepage)';
	document.body.setHomePage(window.location.href);
}

function mycarousel_itemLoadCallback(carousel , state) {
	// Check if the requested items already exist
	if (carousel.has(carousel.first , carousel.last)) {
		return;
	}

	//var per_page = carousel.last - carousel.first + 1;
	var contentId = carousel.options.contentId;
	var galleryId = $(carousel.container).attr('id').substring(10);
	var allItems = 1;

	if(allItems == 1) {
		jQuery.get(app.absoluteUrl + '/gallery/jcarousel/id/' + contentId + '/parent/' + galleryId + '/all/1', null , function(xml) {
			mycarousel_itemAddCallback(carousel , carousel.first , carousel.last , xml , galleryId);
		} , 'xml');
	}
	else {
		jQuery.get(app.absoluteUrl + '/gallery/jcarousel/id/' + contentId + '/parent/' + galleryId + '/first/' + carousel.first + '/last/' + carousel.last, null, function(xml) {
			mycarousel_itemAddCallback(carousel , carousel.first , carousel.last , xml , galleryId);
		} , 'xml');
	}
}

function mycarousel_itemAddCallback(carousel , first , last , xml , galleryId) {

	var allElements = parseInt(jQuery('total' , xml).text());
	// Set the size of the carousel

	carousel.size(7); // allElements

	var j = 0;
	jQuery('image' , xml).each(function(i) {
			carousel.add(first + i , mycarousel_getItemHTML(jQuery(this).text() , galleryId));
			j = i;
	});

	j++;

	if(j<7) {
		var carouselId = carousel.container.attr('id');
		$('#'+carouselId+' .jcarousel-prev').fadeOut();
		$('#'+carouselId+' .jcarousel-next').fadeOut();
		
		for(; j<7; j++)
		{
			carousel.add(first + j , '<div style="background:#fff; height:85px;"></div>');
		}
	}

	$('.lightbox-enabled').lightbox();

	$("li.jcarousel-item a img").fadeTo(500 , 0.6);

	$("li.jcarousel-item a img").hoverIntent({
		interval: 100,
		over: function() {
			$(this).fadeTo(500 , 1.0);
		},
		out: function() {
			$(this).fadeTo(500 , 0.6);
		}
	});
}

/* Item html creation helper. */
function mycarousel_getItemHTML(url , galleryId) {
	urlBig = url.replace(/mini\//g , '');
	return '<a class="lightbox-enabled" rel="lightbox-myGroup-' + galleryId + '" href="' + urlBig + '"><img src="' + url + '" alt="" /></a>';
}

$(document).ready(function() {

	/* ************************************************************************************************************** */
	/* ************************************************************************************************************** */

	$("#calendar").datepicker({
		beforeShowDay: function(date) {
			var x = nationalDays(date);
			return x;
		}
	})

	function wielkanoc() {
		var y = yearValue;
		var a = y % 19;
		var b = parseInt(y / 100);
		var c = y % 100;
		var d = parseInt(b / 4);
		var e = b % 4;
		var f = parseInt((b + 8) / 25);
		var g = parseInt((b - f + 1) / 3);
		var h = (19 * a + b - d - g + 15) % 30;
		var i = parseInt(c / 4);
		var k = c % 4;
		var l = (32 + 2 * e + 2 * i - h - k ) % 7;
		var m = parseInt((a + 11 * h + 22 * l) / 451);
		var p = (h + l - 7 * m + 114) % 31;
		p++;
		var n = parseInt((h + l - 7 * m + 114) / 31);
		n--;
		var w = new Date(y , n , p);
		return w.getTime();
	}

	function pwielkanoc() {
		return new Date(wielkanoc() + 86400 * 1000);
	}

	function zieloneSwiatki() {
		return wielkanoc() + (49 * 86400 * 1000);
	}

	function bozeCialo() {
		return wielkanoc() + (60 * 86400 * 1000);
	}

	/* dodaje do datepickera dni wolne czyli święta; */
	function nationalDays(date) {

		yearValue = date.getFullYear();

		var getMonth;
		var w = new Date(wielkanoc());
		var pw = new Date(pwielkanoc());
		var zS = new Date(zieloneSwiatki());
		var bC = new Date(bozeCialo());

		var dayOff = [
			[''  ,  1,	1, 'Nowy Rok'],
			[''  ,  5,  1, 'Święto Pracy'],
			[''  ,  5,  3, 'Święto Konstytucji 3 Maja'],
			[''  ,  7, 15, 'Święto Wojska Polskiego, Wniebowzięcie Najświętszej Maryi Panny'],
			[''  , 11,  1, 'Wszystkich Świętych'],
			[''  , 11, 11, 'Święto Niepodległości'],
			[''  , 12, 25, 'Boże Narodzenie (pierwszy dzień)'],
			[''  , 12, 26, 'Boże Narodzenie (drugi dzień)'],

			[w.getFullYear(),   w.getMonth() + 1,  w.getDate(), 'Wielkanoc'],
			[pw.getFullYear(), pw.getMonth() + 1, pw.getDate(), 'Poniedziałek Wielkanocny'],
			[zS.getFullYear(), zS.getMonth() + 1, zS.getDate(), 'Zesłanie Ducha Świętego (Zielone Świątki)'],
			[bC.getFullYear(), bC.getMonth() + 1, bC.getDate(), 'Boże Ciało']
		];

		for (var i = 0; i < dayOff.length; i++) {
			getMonth = date.getMonth() + 1;

			if (((dayOff[i][0] == '') || (date.getFullYear() == dayOff[i][0])) && (getMonth == dayOff[i][1]) && (date.getDate() == dayOff[i][2])) {
				var dateClass = date.getFullYear() + '-' + getMonth + '-' + date.getDate();

				// bo tak
				window.setTimeout("$('." + dateClass + "').attr('title', '" + dayOff[i][3] + "').tipTip();" , 100);
				return [true, dateClass + ' dayFreeYellow' ];
			}
		}

		return [true, ''];
	}

	/* ************************************************************************************************************** */
	/* ************************************************************************************************************** */

	$(document).pngFix();

	// initialise plugins
	jQuery(function() {
		jQuery('ul.sf-menu').superfish({
			pathLevels:	1,				  // the number of levels of submenus that remain open or are restored using pathClass
			delay:		 800,				// the delay in milliseconds that the mouse can remain outside a submenu without it closing
			animation:	 {
				opacity: 'show',
				height: 'show'
			},									// an object equivalent to first parameter of jQuery’s .animate() method
			speed:		 'normal',		   // speed of the animation. Equivalent to second parameter of jQuery’s .animate() method
			autoArrows:	true,			   // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance
			dropShadows:   true,			   // completely disable drop shadows by setting this to false
			disableHI:	 false			   // set to true to disable hoverIntent detection
		});
	});

	$("a.category").css({cursor:'normal'}).click(function() {
		return false;
	});


//	$('#accordion').accordion({
//		autoHeight: false,
//		collapsible: true,
//		icons: {
//			'header': 'collapsed',
//			'headerSelected': 'expanded'
//		}
//	});


$("ul#accordion")
	.addClass("ui-accordion ui-widget ui-helper-reset ui-accordion-icons")
	.find("a")
	.addClass("ui-accordion-header ui-helper-reset ui-state-default ui-state-active ui-corner-top")
	.hover(function() {
		$(this).toggleClass("ui-state-hover");
	}).prepend('<span class="ui-icon collapsed"></span>')
	.click(function() {
		var icon = $(this).toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom").find("> .ui-icon");

		if(icon.hasClass('collapsed')) {
			icon.removeClass("ui-icon collapsed");
			icon.addClass("ui-icon expanded");
		}
		else {
			icon.removeClass("ui-icon expanded");
			icon.addClass("ui-icon collapsed");
		}

		icon.end().next().toggleClass("ui-accordion-content-active").slideToggle();
	return false;
	})
	.next().addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active").hide();




	$('.openDialogRegister').click(function() {
		var link = $(this).attr('href');
		var title_ = $(this).attr('title');
		$("#openDialog").dialog({
			title: title_,
			autoOpen: false,
			height: 400,
			width: 450,
			modal: true
		});
		$('#openDialog').load(link , function() {
			initFormRegister(link);
		});
		$('#openDialog').dialog('open');
	});

	$("#commentForm").validate();

	$("#formTest").validate();

	$.datepicker.setDefaults($.datepicker.regional['pl']);

	$("#tabs").tabs();

	$(function() {
		$("#dialog").dialog();
	});

	$('.openDialogLoginForm').click(function() {
		var link = $(this).attr('href');
		var title_ = $(this).attr('title');
		$("#openDialog").dialog({
			title: title_,
			autoOpen: false,
			height: 222,
			width: 175,
			modal: true
		});

		$('#openDialog').dialog('open');
		return false;
	});


	$('#slider').nivoSlider({
		effect: 'random', //Specify sets like: 'fold,fade,sliceDown'
		slices: 15,
		animSpeed: 1000, //Slide transition speed
		pauseTime: 10000,
		startSlide: 0, //Set starting Slide (0 index)
		directionNav: false, //Next & Prev
		directionNavHide: true, //Only show on hover
		controlNav: false, //1,2,3...
		controlNavThumbs: false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel: false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav: false, //Use left & right arrows
		pauseOnHover: false, //Stop animation while hovering
		manualAdvance: false, //Force manual transitions
		captionOpacity: 0.8, //Universal caption opacity
		beforeChange: function() {},
		afterChange: function() {},
		slideshowEnd: function() {}, //Triggers after all slides have been shown
		lastSlide: function() {}, //Triggers when last slide is shown
		afterLoad: function() {} //Triggers when slider has loaded
    });
	
});

$(window).load(function() {

});

