function scroll_to ( element_position )
{
    $( 'html, body' ).animate( {scrollTop : element_position}, 'slow' );
}

$(document).ready(function() {
	
	$( '.contact_us' ).click(function(){
                tema = $(this).prev('h2').html();
                $('form#contact').append('<input type="hidden" name="tema" value="'+tema+'">');
		$( '#contact_popup' ).fadeIn();
		$( '#background' ).fadeIn();		
	});
	
	
	$( '#close_popup, #background' ).click(function(){
		$( '#contact_popup' ).fadeOut();
		$( '#background' ).fadeOut();		
	});
	
	/* var wi = $(window).width();
	if ( wi > 960 )
	{
		$( '#sidebar' ).fadeIn();
	}
		
	$( 'aside a').click( function(){
		scroll_to($($(this).attr('href')).position().top);
        return false;
	}); */
	
	// scrolinimas prie kontaktu q and d
	
	$( '#panevezys' ).click( function(){
		
		scroll_to ( $( '.panevezys' ).position().top - 10 );
	});
	
	$( '#ukmerge' ).click( function(){
		
		scroll_to ( $( '.ukmerge' ).position().top - 10 );
	});
        
	$( '#utena' ).click( function(){
		
		scroll_to ( $( '.utena' ).position().top - 10 );
	});        
        $( '#contact_submit' ).click(function(){
            vardas = $('input[name=vardas]').val();
            telefonas = $('input[name=telefonas]').val();
            mail = $('input[name=email]').val();
            klausimas = $('textarea[name=tekstas]').val();
            tema = $('input[name=tema]').val();
            funkcija = $('input[name=function]').val();
            $.ajax({
                    url: '/ajax/contact.php',
                    type: 'post',
                    data:
                    {
                        'vardas' : vardas,
                        'telefonas' : telefonas,
                        'email' : mail,
                        'klausimas' : klausimas,
                        'tema' : tema,
                        'funkcija' : funkcija
                    },
                    success: function(data){
						if ( data == 'success')
						{
							$( '.notification' ).html( 'Jūsų žinutę gavome, susisieksime artimiausiu metu!' );
							$( '#contact' ).delay(5000).html ( '' );
							window.location.href = "http://biworld.lt";
						}
						else
						{
							$( '.notification' ).html( 'Klaida išsiunčiant žinutę, patikrinkite ar visi laukai užpildyti gerai' );
						}
	
                    }
            });

			return false;
			
        });
        
        $( '#sidebar' ).click(function(){ 
            $('#paslauga').fadeOut(2000);
            $('#sidebar').fadeOut(2000);
            $('#load').fadeOut("fast").load('../views/page.html').fadeIn(2000);
        });
        
        $('#logo').click(function(){
            window.location.href = "http://biworld.lt";
        });
});

