var splashes 	= 0;
var cSplash	= -1;

function sendContactForm() {
    if( $('#main-contact-form').valid() ) {
        var ret = false;


        $.ajax({
            url: "/ajax-send-contact.php",
            global: false,
            type: "POST",
            data: ({name: $('#name').val(), email: $('#email').val(), phone: $('#phone').val(), message: $('#message').val(), lang: $('#lang').val() }),
            dataType: "html",
            success: function( data ){
                $('#contact-form-content').html( data );
            }
        });

        return ret;
    }
}


function init() {
	var cn = 0;
	var sn = 0;
	$('.content-viewer .position').each( function( i ) {
            cn++;
        });
	$('.splash').each( function( i ) {
		splashes++;
		$(this).css( 'z-index', ( 1000 + splashes ) );
	});
	$('.content-viewer .container').css( 'width', ( cn * 530 ) + 'px' );	
	setInterval ( "animSplashes()", 5000 );
}

function animSplashes() {
	
	
	var ns = 0;
	ns = cSplash + 1;
	if( ns == splashes ) {
		ns = 0;	
	}
	
	$('.splash').each( function( i ) {
        if( i == ns ) {
			if( ns == 0 ) {
				$(this).animate({
						opacity: 1
					}, 2400, function() {
						$('.splash').animate({
						opacity: 1
					}, 400, function() {
					});
				  });
			} else {
					$(this).animate({
						opacity: 0
					}, 2400, function() {
						
				  });
			}
		}
    });
	
	cSplash = ns;
}

function selectContent( cn, obj ) {

	$('.content .sidebar a').removeClass( 'active' );
	$(obj).addClass( 'active' );
	
	leftPos = ( cn * 530 - 530) * -1;
	topPos = ( cn * 50 - 50 ) + 20;
    $('.content-viewer .container').animate({
        left: leftPos + 'px'
    }, 300, function() {
		
  });
  
  $('.sidebar .select').animate({
        top: topPos + 'px'
    }, 380, function() {
		
  });
}

$(document).ready(function(){
	init();
	$('.gallery a').colorbox();
	$('.colorbox').colorbox();
        $('.cboxElement').colorbox();
	$('.colorbox-inline').colorbox( {inline: true} );
	
	$('#contact-map-flash').flash(
        { src: '/swf/dojazd.swf',
          width: 800,
          height: 532 },
        { version: 8 }
    );

});
