$(document).ready(function() {

	var play = true;

	$('#slider #list li').click(function(){
		changeSlider($(this).attr('id'));
		play = false;
	});


	if ($('#thumbs').length > 0){
	    var gallery = $('#thumbs').galleriffic({
	        delay:                     1000, // in milliseconds
	        numThumbs:                 20, // The number of thumbnails to show page
	        preloadAhead:              40, // Set to -1 to preload all images
	        enableTopPager:            false,
	        enableBottomPager:         true,
	        maxPagesToShow:            7,  // The maximum number of pages to display in either the top or bottom pager
	        imageContainerSel:         '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
	        controlsContainerSel:      '#controls', // The CSS selector for the element within which the slideshow controls should be rendered
	        captionContainerSel:       '#caption', // The CSS selector for the element within which the captions should be rendered
	        loadingContainerSel:       '#loading', // The CSS selector for the element within which should be shown when an image is loading
	        renderSSControls:          false, // Specifies whether the slideshow's Play and Pause links should be rendered
	        renderNavControls:         true, // Specifies whether the slideshow's Next and Previous links should be rendered
	        playLinkText:              'Play',
	        pauseLinkText:             'Pause',
	        prevLinkText:              '&lsaquo; Poprzednie',
	        nextLinkText:              'Następne &rsaquo;',
	        nextPageLinkText:          'Następna &rsaquo;',
	        prevPageLinkText:          '&lsaquo; Poprzednia',
	        enableHistory:             false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
	        enableKeyboardNavigation:  true, // Specifies whether keyboard navigation is enabled
	        autoStart:                 false, // Specifies whether the slideshow should be playing or paused when the page first loads
	        syncTransitions:           false, // Specifies whether the out and in transitions occur simultaneously or distinctly
	        defaultTransitionDuration: 1000, // If using the default transitions, specifies the duration of the transitions
	        onSlideChange:             undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
	        onTransitionOut:           undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
	        onTransitionIn:            undefined, // accepts a delegate like such: function(slide, caption, isSync) { ... }
	        onPageTransitionOut:       undefined, // accepts a delegate like such: function(callback) { ... }
	        onPageTransitionIn:        undefined, // accepts a delegate like such: function() { ... }
	        onImageAdded:              undefined, // accepts a delegate like such: function(imageData, $li) { ... }
	        onImageRemoved:            undefined  // accepts a delegate like such: function(imageData, $li) { ... }
	    });
	}


	$(window).load(function() {

	    $('#main-slider').nivoSlider({
	        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
	        slices:15, // For slice animations
	        boxCols: 8, // For box animations
	        boxRows: 4, // For box animations
	        animSpeed:1600, // Slide transition speed
	        pauseTime:4500, // How long each slide will show
	        startSlide:0, // Set starting Slide (0 index)
	        directionNav:false, // Next & Prev navigation
	        directionNavHide:true, // Only show on hover
	        controlNav:false, // 1,2,3... navigation
	        controlNavThumbs:false, // Use thumbnails for Control Nav
	        controlNavThumbsFromRel:false, // Use image rel for thumbs
	    });
	});


	$("a.fancybox").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600,
		'speedOut'		:	200,
		'overlayShow'	:	true
	});


	$('#news-show #main-photo a:first-child').removeClass('hidden').addClass('current');
	$('#news-show #news-thumbs .news-photo').click(function(){
		var id = $(this).attr('id');
		$('#news-show #main-photo a.current').addClass('hidden').removeClass('current').css('display', 'none');
		$('#news-show #main-photo a#' + id).fadeIn('500').removeClass('hidden').addClass('current');
	});



	$('#product #main-photo a:first-child').removeClass('hidden').addClass('current');
	$('#product #product-thumbs .product-thumb').click(function(){
		var id = $(this).attr('id');
		$('#product #main-photo a.current').addClass('hidden').removeClass('current').css('display', 'none');
		$('#product #main-photo a#' + id).fadeIn('500').removeClass('hidden').addClass('current');
	});


	$('#product #product-thumbs .profile-thumb').click(function(){
		var id = $(this).attr('id');
		$('#product #main-photo a.current').addClass('hidden').removeClass('current').css('display', 'none');
		$('#product #main-photo a#' + id).fadeIn('500').removeClass('hidden').addClass('current');
	});


	$('.submenu').mouseleave(function(){
		$(this).hide();
	});

	$('.btn').mouseenter(function(){
		$('.submenu').hide();
	});

});

function changeSlider(id){
		var current = $('#main-photo div.main-current');
		current.removeClass('main-current').addClass('hidden').css('display', 'none');
		$('#slider #list li.main-current').removeClass('main-current');

		var to_on = $('#main-photo div#big-' + id);
		to_on.fadeIn(500).removeClass('hidden').addClass('main-current');
		$('#slider #list li#' + id).addClass('main-current');

}

function playSlider(){
		var current = $('#main-photo div.main-current');
		current.removeClass('main-current').addClass('hidden').css('display', 'none');
		$('#slider #list li.main-current').removeClass('main-current');

		if (current.next().length > 0){
			current.next().fadeIn(500).removeClass('hidden').addClass('main-current');
			var id = current.next().attr('id').substr(4);
			$('#slider #list li#' + id).addClass('main-current');

		}
		else{
			$('#main-photo div.first').addClass('main-current').removeClass('hidden');
			$('#slider #list li.first').addClass('main-current');
		}

}

function hideSubmenu(selector){
	var time = 1000;
	setTimeout(function(){
		if (!$(selector).focus()){
			$(selector).hide();
		}
	}, 500);

}

function showSubmenu(selector){
		 $('.submenu').stop(false, true).hide();
		 var submenu = $(selector);
		 submenu.stop().show();
		 submenu.mouseleave(function(){
			 $(this).hide();
		 });
}

function changeLang(){
	$('.nav-controls .prev').html('&lsaquo; Previous');
	$('.nav-controls .next').html('Next &rsaquo;');
}

