// Flag for fix bug of showing menu
var animateShowMenu = true;

var primg = ['secret2butt2.jpg','secret2flow2.jpg'];
for (x in primg) (new Image()).src = '../images/'+primg[x];
$(document).ready(function(){
jQuery.preloadImages = function()
{
 var arguments_length = arguments.length;
 for(var i = 0; i<arguments_length; i++)
 {
  jQuery("<img>").attr("src", arguments[i]);
 }
};

// Использование
$.preloadImages('../images/secret2butt2.jpg','../images/secret2flow2.jpg');

menuh=$('#menutop').height()-21;
$('#menutop').height(menuh);
$('#menutop').css("top","-"+menuh+"px");


	$('#menutop').hover(
       function() { $(this).animate({top: "0px"}, 300); },
       function() { $(this).animate({top: "-"+menuh+"px"}, 300); }
	   );


$("#listok").easydrag();
 
	// set a function to be called on a drop event
	$("#listok").ondrop(function(e, element){ 
							
	$("#listok").animate({
	left: "829px",
    top: "89px"
  }, 1000 );				 	 
								 });

// Contuct US


	$('#myForm').ajaxForm(function(data) {
				if (data==1){
					$('#def').hide();
					$('#bad').hide();
					$('#success').fadeIn("slow");
					$('#myForm').resetForm();
				}
				else {
					$('#def').hide();
					$('#success').hide();
					$('#bad').fadeIn("slow");
				}
				
				
			});
$('#myForm2').ajaxForm(function(data) {
				if (data==1){
					$('#myForm2').hide();
					$('#bad').hide();
					$('#ok').fadeIn("slow");
					$('#myForm').resetForm();					
				}
				else {
					$('#ok').hide();
					$('#bad').fadeIn("slow");
				}
				
				
			});

		
  				
// Contuct US
    
	$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
	$('.gallery_demo2_unstyled').addClass('gallery_demo2'); // adds new class name to maintain degradability
	
		$('ul.gallery_demo, ul.gallery_demo2').galleria({
			history   : false, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
			
		});
		
		
$("#qqq").click(function () {
 
  $("#q1").slideToggle("slow");

 
});


$("#sknopka").hover(
		function() { $(this).removeClass().addClass("coll")
					 $("#scvetok").removeClass().addClass("cofl")},
        function() {$(this).removeClass().addClass("cola")
					$("#scvetok").removeClass().addClass("cofa")}
		);


$("#sleft, #sright, #listing li").css("opacity",0.5);
$("#sleft, #sright, #listing li").hover(
		function() { $(this).css("opacity",1);},
        function() {if ( $(this).hasClass("active") ) {$(this).css("opacity",1);} else $(this).css("opacity",0.5);     });

var kolvo=9;
var screennow=1;
var x=(screennow-1)*700;
function testpm() {
	if (screennow<=1) {$("#sleft").hide(); screennow=1} else $("#sleft").show()
	if (screennow>=kolvo) {$("#sright").hide(); screennow=kolvo} else $("#sright").show()
	$("#listing li").css("opacity",0.5).removeClass();
	$("#listing li:eq("+(screennow-1)+")").css("opacity",1).addClass("active");;						 

}
testpm();
$("#sleft").click(function () {						
 screennow--;
 testpm();
 x+=700;

  $("#scrooo").stop().animate({
      left: x
    }, 1000, "easeOutElastic");

 
});		

$("#sright, #rightt").click(function () {						
screennow++;
testpm();
x-=700;

  $("#scrooo").stop().animate({
      left: x
    }, 1000, "easeOutElastic");
 });	

$("#listing li").click(function () { 
		$("#listing li").css("opacity",0.5).removeClass();						 
		$(this).css("opacity",1);
		$(this).addClass("active");
		screennow=$("ul#listing li").index(this)+1;
		testpm();
 		x=-(screennow-1)*700;
		$("#scrooo").stop().animate({
      left: x
    }, 1000, "easeOutElastic");
		

								 });

/*$(".imgava").hover(
		function() { $(this).animate({height:150, width:150}, 100);},
        function() {$(this).animate({height:140, width:140}, 100);}
		);*/
});
