this.accNavi = function(){
	$('#cnt> div').hide();
	$('#cnt> h3').click(function() {
		var $nextDiv = $(this).next();
		var $visibleSiblings = $nextDiv.siblings('div:visible');
		if ($visibleSiblings.length ) {
			$visibleSiblings.slideUp('fast', function() {
			$nextDiv.slideToggle('fast');
		});
		} else {
			$nextDiv.slideToggle('fast');
		}
	});
}
this.imagePreview = function(){	
	/* CONFIG */
		
	var xOffset = 400;
	var yOffset = 100;
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";
		this.image = this.href;
		this.href = "#";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.image +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX - xOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;
		this.href = this.image;
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX - xOffset) + "px");
	});			
};
this.imagePreview2 = function(){	
	/* CONFIG */
		
	var xOffset = 200;
	var yOffset = 100;
		
	/* END CONFIG */
	$("a.preview2").hover(function(e){
		this.t = this.title;
		this.title = "";
		this.image = this.href;
		this.href = "#";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview2'><img src='"+ this.image +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview2")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX - xOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;
		this.href = this.image;
		$("#preview2").remove();
    });	
	$("a.preview2").mousemove(function(e){
		$("#preview2")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX - xOffset) + "px");
	});			
};

this.showSlideShow = function(){
	$('.slideshow').each(function(){
		var currentPosition = 0;
		var slideWidth = 800;
		var slides = $('.slide',this);
		var numberOfSlides = slides.length;
		var currentGallery = $(this);
		// Remove scrollbar in JS
		$('.slidesContainer',currentGallery).css('overflow', 'hidden');

		// Wrap all .slides with #slideInner div
		slides
			.wrapAll('<div class="slideInner"></div>')
			// Float left to display horizontally, readjust .slides width
			.css({
				'float' : 'left',
				'width' : slideWidth
			});

		// Set #slideInner width equal to total width of all slides
		$('.slideInner',currentGallery).css('width', slideWidth * numberOfSlides);

		// Insert controls in the DOM
		$(currentGallery)
			.prepend('<span class="leftControl control">Przewin w lewo</span>')
			.append('<span class="rightControl control">Przewin w prawo</span>');

		// Hide left arrow control on first load
		manageControls(currentPosition);

		// Create event listeners for .controls clicks
		$('.control',currentGallery)
			.bind('click', function(){
				// Determine new position
				currentPosition = ($(this).attr('class')=='rightControl control') ? currentPosition+1 : currentPosition-1;
				// Hide / show controls
				manageControls(currentPosition);
				// Move slideInner using margin-left
				$('.slideInner',currentGallery).animate({
					'marginLeft' : slideWidth*(-currentPosition)
				});
			});

		// manageControls: Hides and Shows controls depending on currentPosition
		function manageControls(position){
			// Hide left arrow if position is first slide
			if(position==0){ $('.leftControl',currentGallery).hide() } else{ $('.leftControl',currentGallery).show() }
			// Hide right arrow if position is last slide
			if(position==numberOfSlides-1){ $('.rightControl',currentGallery).hide() } else{ $('.rightControl',currentGallery).show() }
		}
	});
};

// starting the script on page load
$(document).ready(function(){
	accNavi();
	imagePreview();
	imagePreview2();
	showSlideShow();
	//$('a[@rel*=gallery].lightbox').lightBox();
	$('a.lightbox').lightBox();
});
