//nadpisanie hoverów, żeby js animował od pierwszego najechania
document.write(
	'<style type="text/css">' +
	'#lewy ul.menu li a:hover {color: #3F3F3F; border-color: #EBEBEB;}' +
	'.przycisk_galeria img:hover {background-color: #FFFFFF;}' +
	'.highslide img:hover {background-color: #FFFFFF;}' +
	'<\/style>');
hs.graphicsDir = 'http://js.odyn.net.pl/highslide/graphics/';
hs.outlineType = 'rounded-white';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.fadeInOut = true;
hs.dimmingOpacity = 0.8;
hs.captionEval = 'this.thumb.alt';
hs.numberPosition = 'caption';
hs.Expander.prototype.onInit = function() {
	if (this.slideshowGroup == 'gr') hs.marginBottom = 135;
	else hs.marginBottom = 15;
}; 
var g = {slideshowGroup: 'gr'};

hs.addSlideshow({
	slideshowGroup: 'gr',
	interval: 5000,
	repeat: false,
	useControls: true,
	overlayOptions: {
		className: 'text-controls',
		position: 'bottom center',
		relativeTo: 'viewport',
		offsetY: -70
	},
	thumbstrip: {
		slideshowGroup: 'gr',
		position: 'bottom center',
		mode: 'horizontal',
		relativeTo: 'viewport'
	}
});

// Funkcja opóźniająca
$.fn.delay = function(time, callback){
	jQuery.fx.step.delay = function(){};
	return this.animate({delay:1}, time, callback);
}

var loaders = 0;

$(window).bind('load', function(){
	if(loaders.length != 0){
		loaders.each(function(){
			$(this).animate({opacity: '0'}, 300, function(){
				$(this).css({display: 'none'});
			});
		});
	}
});

$(document).ready(function(){
	loaders = $('.preloader');
	
	if(loaders.length != 0){
		/*loaders.each(function(){
			$(this).css({display: 'block', opacity: '0'});
			$(this).animate({opacity: '0.8'}, 300);
		});*/
	}
	
	$('.paginacja a').live('click', function(e){
		e.preventDefault();
		var href = $(this).attr('href');
		var start = href.replace(/.*\/[a-z_]*?-([0-9]*)\.html/i, '$1');
		var gal = href.replace(/.*\/([a-z_]*?)-[0-9]*\.html/i, '$1');
		
		$('.zdjecia .preloader').css({display: 'block'}).animate({opacity: '0.8'}, 300);
		var cont_h = $('#prawy').height();
		var prev_pics_h = $('.zdjecia').height();
		$('#prawy').css({'height': cont_h});
		var all_photo = $('.zdjecia a.highslide, .zdjecia .paginacja');
		
		$.ajax({
			type: "POST",
			url: "_funkcje.php",
			data: "ajax=TRUE&gallery=" + gal + "&page=" + start,
			success: function(data) {
				
				$('.zdjecia .preloader').animate({opacity: '1'}, 60, function(){
					//$(all_photo).fadeOut(80, function(){$(this).remove()});
					$(all_photo).remove();
					$('.zdjecia').append(data);
					
					var new_cont_h = cont_h - (prev_pics_h - $('.zdjecia').height());
					$(this).animate({opacity: '0.8'}, 60);
					$('#prawy').animate({height: new_cont_h}, 200);
				});
				$('.zdjecia .preloader').delay(500).animate({opacity: '0'}, 300, function(){
					$(this).css({display: 'none'});
				});
			}
		});
	});
	
	// Animacja koloru obramowania zdjec galerii
	$(".highslide img").hover(function() {
		$(this).animate({backgroundColor: "#DFDFDF"}, 400);
	},function() {
		$(this).animate({backgroundColor: "#FFFFFF"}, 250);
	});
	// Animacja koloru obramowania zdjec menu galerii
	$(".przycisk_galeria img").hover(function() {
		$(this).animate({backgroundColor: "#DFDFDF",}, 400);
	},function() {
		$(this).animate({backgroundColor: "#FFFFFF"}, 250);
	});
	// Wyświetlanie losowego zdjęcia
	$('#img_scroll').cycle({
		fx:     'scrollDown',
		timeout: 8000,
		easing: 'backinout',
		sync:   0,
		random: 0,
		speed:  700,
		delay:  8000,
		next: '#nexti',
		prev: '#previ'
	});

	// Wyświetlanie losowego cytatu 
	function onAfter(curr, next, opts, fwd) {
		var $ht = $(this).height();
		//ustawienie wysokości kontenera na wysokość obecnego elementu
		$(this).parent().animate({height: $ht+40});
	}
	$('#q_scroll').cycle({
		fx:     'fade',
		after : onAfter,
		timeout: 12000,
		sync:   0,
		random: 1,
		speed:  700,
		delay:  12000,
		next: '#nextq',
		prev: '#prevq'
	});
	
	// Łagodna zmiana koloru odnośnika cytatu
	$("#los_cytaty a").hover(function() {
		$(this).animate({color: '#1783BF'}, 200);
	  },function(){
		$(this).animate({color: '#1D5678'}, 150);
	  });   
	// Animacja menu
	var config = {    
	sensitivity: 3,
	interval: 80,
	over: function() {
	  $(this).animate({
		color: '#1783BF',
		borderLeftColor: '#1783BF'
	  }, 200);
	}, 
	timeout: 20, //milliseconds delay before onMouseOut
	out: function(){
	  $(this).animate({ 
		color: '#3F3F3F',
		borderLeftColor: '#EBEBEB'
	  }, 250);
	}
	};
	$("#lewy ul.menu li a").hoverIntent( config );
	
	// Przewijanie do góry strony
	$('a[title="W górę!"]').bind("click", function(e){
		e.preventDefault();
		var target = $(this).attr("href");
		$('html,body').animate({	//get top-position of target-element and set it as scroll target
			scrollTop: $(target).offset().top
		},500,function(){	//attach the hash (#jumptarget) to the pageurl
			location.hash = target;
		});
	});
	
});
