$(document).ready(function(){
		//index
		$('#index .opacity').css('opacity', .5);

		//fonts
		Cufon.replace('#menu a'); 
		Cufon.replace('#content h2'); 
		Cufon.replace('#sliderHeader'); 
		Cufon.replace('#collections .collection h3'); 
		Cufon.replace('#aboutBox  h2 '); 
		Cufon.replace('#news  h2 '); 
		Cufon.replace('#distribution'); 		

		//scroler
	  var currentPosition = 0;
	  var slideWidth = 920;
	  var slides = $('.slide');
	  var numberOfSlides = slides.length;

	  // Remove scrollbar in JS
	  $('#slidesContainer').css('overflow', 'hidden');

	  // Wrap all .slides with #slideInner div
	  slides
	  .wrapAll('<div id="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').css('width', slideWidth * numberOfSlides);

	  // Insert left and right arrow controls in the DOM
	  $('#slideshow')
	    .prepend('<span class="control" id="leftControl">Move left</span>')
	    .append('<span class="control" id="rightControl">Move right</span>');

	  // Hide left arrow control on first load
	  manageControls(currentPosition);

	  // Create event listeners for .controls clicks
	  $('.control')
	    .bind('click', function(){
	    // Determine new position
	      currentPosition = ($(this).attr('id')=='rightControl')
	    ? currentPosition+1 : currentPosition-1;

	      // Hide / show controls
	      manageControls(currentPosition);
	      // Move slideInner using margin-left
	      $('#slideInner').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').hide() }
	    else{ $('#leftControl').show() }
	    // Hide right arrow if position is last slide
	    if(position==numberOfSlides-1){ $('#rightControl').hide() }
	    else{ $('#rightControl').show() }
	    }


	//menu
	$('#menu ul').superfish({ 
			hoverClass:    'active',     
            delay:       10,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
        });
		
	$("form#getCatalog").submit(function () { 
			$.ajax({
				type: "POST",
				url: "js/_jsGetCatalog.php",
				data: $("form#getCatalog").serialize(),
				success: function(msg){
					$('#getCatalogReturnBox').fadeIn(1300).html(msg);
				}
			});
		return false;		
	});	
	$("form#contactForm").submit(function () { 
			$.ajax({
				type: "POST",
				url: "js/_jsContactBox.php",
				data: $("form#contactForm").serialize(),
				success: function(msg){
					$('#getCatalogReturnBox').fadeIn(1300).html(msg);
				}
			});
		return false;		
	});
	$("form#Architekci").submit(function () { 
			$.ajax({
				type: "POST",
				url: "js/_jsArchitekci.php",
				data: $("form#Architekci").serialize(),
				success: function(msg){
					$('#ArchitekciReturnBox').fadeIn(1300).html(msg);
				}
			});
		return false;		
	});
});

	function dystrybucja(wojewodztwo, typ) {
		$("#showDistributionData").css('display', 'block').html('<h2 id="distribution">Trwa ładowanie zawartości</h2>');
			$.post("js/_jsGetDistribution.php", { wojewodztwo: wojewodztwo, typ: typ },
					  function(data){
						 $("#showDistributionData").css('display', 'block').html(data);
						});
	
	};	

function slideSwitch() {
    var $active = $('#slideshow_main IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow_main IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow_main IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
function slideSwitchCollection() {
    var $active = $('#slideshow_collection IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow_collection IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow_collection IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 4000 );
	setInterval( "slideSwitchCollection()", 3000 );
});

$(function(){
    $('.gallery-jquery a').lightBox({
         fixedNavigation: true
	});
});

