$(document).ready(function() {

    $("#feedbackform a").click(function(){
        
        $("#asform").slideToggle("slow");
        return false;
    });
    
    $(".gallery a").fancybox({
         'overlayShow' : true,
         'zoomSpeedIn' : 300,
         'zoomSpeedOut' : 300,
         'centerOnScroll' : true
    });
    
    $(".comment a").fancyZoom({width:640, height:480});

    //	vacancies
    $(".vacancy a").click(function()
    {
    	$(this).parent().find("div").slideToggle("fast");
    	return false;
    });

	$("a.popup").fancybox({
	  'titlePosition':'over',
	  'zoomSpeedIn': 300, 
      'zoomSpeedOut': 300,
      'frameWidth':$(document).width()-200, 
      'frameHeight': window.innerHeight-90,
      'hideOnContentClick':false,
      'overlayOpacity':0.9,
      'overlayColor':'black',
      'titleFormat' : function(title, currentArray, currentIndex, currentOpts) 
      {
        return '<span id="fancybox-title-over">Картинка ' + (currentIndex + 1) + ' из ' + currentArray.length +'<br/>'+title+ '</span>';
      }, 
      'callbackOnShow':function(){
		 initGallery();
        }
	}); 
});

function initGallery(){
    $("#fancy_right, #fancy_left").remove();
    var galleries = $('.ad-gallery').adGallery({
        thumb_opacity: 0.2, // Opacity that the thumbs fades to/from, (1 removes fade effect)
        // Note that this effect combined with other effects might be resource intensive
        // and make animations lag
        start_at_index: 0, // Which image should be displayed at first? 0 is the first image
        animate_first_image: false, // Should first image just be displayed, or animated in?
        animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
        display_next_and_prev: true, // Can you navigate by clicking on the left/right on the image?
        display_back_and_forward: true, // Are you allowed to scroll the thumb list?
        scroll_jump: 0, // If 0, it jumps the width of the container
        effect: 'fade', // or 'slide-vert', 'resize', 'fade', 'none' or false
        enable_keyboard_move: false, // Move to next/previous image with keyboard arrows?
        cycle: true, // If set to false, you can't go from the last image to the first, and vice versa
        callbacks: {
            // This gets fired right after the new_image is fully visible
            afterImageVisible: function() {
                // For example, preload the next image
                var context = this;
                this.loading(true);
                //	alt 2 span   
                this.preloadImage(this.current_index + 1, function() {
                        // This function gets executed after the image has been loaded
                        context.loading(false);
                        //$(".ad-gallery, .ad-nav").css("width",($("#fancybox-inner").width()-100)+"px");
                    }
                );
            }
        
        }
    
    });

}


function LoadByURL(xurl, id){
	//	remove them!
	$(".second a").removeClass('a');
	$(".portfolio_groups a").removeClass('a');
	$("#x"+id).addClass('a');
	$(".content").load(xurl);
}

function showInfo(id){
	var curID = id;
	var fBoxTemplate = "<script>var newContent=new Array(); newContent=content;curID="+curID+";</script><span id='xContent'>"+content[id]['Descr']+"</span><br><img id='xImage' src=\""+content[id]['img']+"\" alt=\""+content[id]['Descr']+"\">";
	$.floatbox({
        content: fBoxTemplate,
        fade: true
    });
}

function prevSlide(){
	curID--;
	if (curID==0) {
		curID = 12;
	}
	$('#xContent').html(newContent[curID]['Descr']);
	$('#xImage').attr('src',newContent[curID]['img']);
	return curID;
}

function nextSlide(){
	curID++;
	if (curID==13) {
		curID = 1;
	}
	$('#xContent').html(newContent[curID]['Descr']);
	$('#xImage').attr('src',newContent[curID]['img']);
	return curID;
}
