$(document).ready(function() {

    $(".vertical").scrollable({ vertical: true, mousewheel: true, circular: true }).autoscroll({ interval:5000, autoplay: true });
$(".scrollable").scrollable({ next:'.nextPage', prev:'.prevPage', mousewheel: true, circular: true, step: 1 });
 });

var menus = new Array;


function menu() {

     $(document).ready(function(){
         $("ul.section_menu li.selected").parent().slideDown("normal", function() {});
         $("ul.iblock_menu li.selected").children().slideDown("normal", function() {});
    
});
    $("ul.section_menu li.level_2").children(".pseudo_link").click(
            function() {

                if (!$(this).attr("cl")) {

                    $(this).attr("cl", "1");
                    obj = $(this);
                    if (!$(this).parent().hasClass("active")) {

                        $("ul.section_menu li.level_2.active").children("ul").slideUp("normal",
                                function() {

                                    $(this).parent().attr("class", "level_2");
                                }
                                );

                        $(this).parent().addClass("active");
                        $(this).parent().children("ul").slideDown("normal", function() {
                            obj.attr("cl", "");
                        });
                    } else {

                        $("ul.section_menu li.active").children("ul").slideUp("normal",

                                function() {

                                    $(this).parent().removeClass("active");
                                    obj.attr("cl", "");
                                }
                                );
                    }
                }

                return false;
            }
    );

        $("ul.iblock_menu li.level_1").children(".pseudo_link").click(
            function() {

                if (!$(this).attr("cl")) {

                    $(this).attr("cl", "1");
                    obj = $(this);
                    if (!$(this).parent().hasClass("active")) {

                        $("ul.iblock_menu li.level_1.active").children("ul").slideUp("normal",
                                function() {

                                    $(this).parent().attr("class", "level_1");
                                }
                                );

                        $(this).parent().addClass("active");
                        $(this).parent().children("ul").slideDown("normal", function() {
                            obj.attr("cl", "");
                        });
                    } else {

                        $("ul.iblock_menu li.active").children("ul").slideUp("normal",

                                function() {

                                    $(this).parent().removeClass("active");
                                    obj.attr("cl", "");
                                }
                                );
                    }
                }

                return false;
            }
    );
}

function FormBlock(form_type) {

    var block = document.getElementById('fon-block');
    var page = document.getElementById('all');
    selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
        selects[i].style.visibility = "hidden";
    }
    block.style.height = page.clientHeight + 'px';
    block.style.display = 'block';
    block.onclick = function () {
        hideForm(form_type);
        return false;
    };
    var frmBlock = document.getElementById('blocks-form');
    var forma = document.getElementById(form_type);


    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {
        yScroll = document.body.scrollTop;
    }

    var windowHeight;
    if (self.innerHeight) {
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowHeight = document.body.clientHeight;
    }

    frmBlock.style.display = 'block';
    forma.style.display = 'block';
    frmBlock.style.top = windowHeight / 2 + yScroll - frmBlock.clientHeight / 2 + 'px';
    /*document.getElementById(form_type+'-forma').elements[0].focus();*/
}

function hideForm(hblock) {
    var hh = document.getElementById(hblock);
    hh.style.display = 'none';
    var f1 = document.getElementById('blocks-form');
    var f2 = document.getElementById('fon-block');
    f1.style.display = 'none';
    f2.style.display = 'none';
}

function hideBlock(hblock) {
    hh = document.getElementById(hblock);
    hh.style.display = 'none';
}


var photo = function(){
	this.init();
};

photo.prototype = {
	init: function(){
		this.photo_block = $('#photo, .photo_gallery');
		if(this.photo_block.length) {
			this.current_photo_img = $('#current_photo_img');
			this.previews = this.photo_block.find('.photo_previews li');
			this.current_preview = this.previews.filter('.selected');

			this.attach_events();
		}
	},

	attach_events: function(){
		var that = this;

		this.previews.find('a.photo').click(function(){
			$('#current_photo').removeClass('hidden');
			$('#video_box').addClass('hidden');

			that.current_photo_img.attr('src', this.href);

			that.current_preview.removeClass('selected');
			that.current_preview = $(this).parent().addClass('selected');
			return false;
		});

		this.previews.find('a.video').click(function(){
			$('#current_photo').addClass('hidden');
			$('#video_box').removeClass('hidden');

			that.current_preview.removeClass('selected');
			that.current_preview = $(this).parent().addClass('selected');
			return false;
		});
	}

}

$(function(){
	new photo();
});


