jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};


jQuery(function( $ ){

	$("#slideshow").touchwipe({
     wipeLeft: function() { $("#screen2 a.next").click(); },
     wipeRight: function() { $("#screen2 a.prev").click(); },
     min_move_x: 60,
     preventDefaultEvents: false
	});



var hashto = ( window.location.hash.substring(1, window.location.hash.length) )*(-1)-1;
if (hashto<0) hashto=0;

	$('#slideshow').serialScroll({
		items:'li',
		prev:'#screen2 a.prev',
		next:'#screen2 a.next',
		offset:$(window).width()*(-0.5)+450, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:hashto, //as we are centering it, start at the 2nd
		duration:600,
		navigation:'#navigation li',
		force:true,
		stop:true,
		lock:true,
		event:'click',
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect    ----    easeOutQuart
		jump: true, //click on the images to scroll to them
		onBefore:function( e, elem, $pane, $items, pos ){
			var numer = $(elem).attr('id');
			$('#navigation a').css("background","url(../images/pagination.png) 0px 0px no-repeat");
			$('#slideshow li').css('cursor','pointer');
            jQuery.fx.on = true;
			$('#fordescription').fadeOut('fast');
		},
		onAfter:function( elem ){
			var numer = $(elem).attr('id');
			$('#navigation a.ali'+numer).css("background","url(../images/pagination.png) 0px -13px no-repeat");
			$('#slideshow li#'+numer).css('cursor','default');
            jQuery.fx.on = true;
			$('#fordescription').html($('#slideshow li div#span'+numer).html());
			$('#fordescription').fadeIn('slow');
			if ((numer>1)||(window.location.hash!="")) window.location.hash = '#' + (numer*(-1));
		},


	});


    function showKey(e){
        var key;
        if (window.event){
            key=window.event.keyCode;
        }
        else{
              key=e.keyCode;
        }
        if (key==37) $("#screen2 a.prev").click();
        if (key==39) $("#screen2 a.next").click();
    }




   window.onload=function(){



   $(window).resize(function(){
   	var hashto = ( window.location.hash.substring(1, window.location.hash.length) )*(-1)-1;
	if (hashto<0) hashto=0;

	//$('#ta').html($(window).width() + " " + $('#ta').html());

	$('#screen2').css('width',$(window).width()+'px');
	$('#slideshow').css('width',$(window).width()+'px');
	$('.lastli').css("padding-right",$(window).width()*(0.5)-450);
	$('.firstli').css("padding-left",$(window).width()*(-0.5)+450);

	$('#slideshow').serialScroll({
		items:'li',
		prev:'#screen2 a.prev',
		next:'#screen2 a.next',
		offset:$(window).width()*(-0.5)+450, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:hashto, //as we are centering it, start at the 2nd
		duration:600,
		navigation:'#navigation li',
		force:true,
		stop:true,
		lock:true,
		event:'click',
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: true, //click on the images to scroll to them
		onBefore:function( e, elem, $pane, $items, pos ){
			var numer = $(elem).attr('id');
			$('#navigation a').css("background","url(../images/pagination.png) 0px 0px no-repeat");
			$('#slideshow li').css('cursor','pointer');
            jQuery.fx.on = true;
			$('#fordescription').fadeOut('fast');
				$('#screen2').css('width',$(window).width()+'px');
	$('#slideshow').css('width',$(window).width()+'px');
	$('.lastli').css("padding-right",$(window).width()*(0.5)-450);
	$('.firstli').css("padding-left",$(window).width()*(-0.5)+450);

		},
		onAfter:function( elem ){
			var numer = $(elem).attr('id');
			$('#navigation a.ali'+numer).css("background","url(../images/pagination.png) 0px -13px no-repeat");
			$('#slideshow li#'+numer).css('cursor','default');
            jQuery.fx.on = true;
			$('#fordescription').html($('#slideshow li div#span'+numer).html());
			$('#fordescription').fadeIn('slow');
			if ((numer>1)||(window.location.hash!="")) window.location.hash = '#' + (numer*(-1));
				$('#screen2').css('width',$(window).width()+'px');
	$('#slideshow').css('width',$(window).width()+'px');
	$('.lastli').css("padding-right",$(window).width()*(0.5)-450);
	$('.firstli').css("padding-left",$(window).width()*(-0.5)+450);

		},

	});



   });

	$('#screen2').css('width',$(window).width()+'px');
	$('#slideshow').css('width',$(window).width()+'px');
	$('.lastli').css("padding-right",$(window).width()*(0.5)-450);
	$('.firstli').css("padding-left",$(window).width()*(-0.5)+450);

	/* если захотите активировать прокрутку колесом мыши - раскомментируйте этот код
	$('#slideshow').mousewheel(function(event, delta) {
    	if (delta > 0) $("#screen2 a.prev").click();
    	if (delta < 0) $("#screen2 a.next").click();
	}); */

        document.onkeydown=showKey;
    }


});
