$(document).ready(function(){
	/*$("#gallery_item_1").mouseover(function(){
		show_gallery(1);
	});
	$("#gallery_item_2").mouseover(function(){
		show_gallery(2);
	});
	$("#gallery_item_3").mouseover(function(){
		show_gallery(3);
	});
	$(".gallery_item_content").mouseleave(function(){
        //$(".gallery_item_anim_content").stop(true, true);
		hide_gallery(1);
		hide_gallery(2);
		hide_gallery(3);
	}); */

    $("#gallery_item_1").hover(
        function(){
            show_gallery(1);
        },
        function(){
            hide_gallery(1);
    });
    $("#gallery_item_2").hover(
        function(){
            show_gallery(2);
        },
        function(){
            hide_gallery(2);
    });
    $("#gallery_item_3").hover(
        function(){
            show_gallery(3);
        },
        function(){
            hide_gallery(3);
    });
	/*hide_gallery(1);
	hide_gallery(2);
	hide_gallery(3);*/

    currentBg = $("#header_bg_1");
    nextBg = $("#header_bg_2");
    timer = window.setInterval("toggleHeaderBg();", 7000);
});

function show_gallery(num) {
    //$("#gallery_content_"+num).fadeIn(700);
    /*while (!can_start) {
        true;
    } */
    $("#gallery_content_"+num).attr({
          style: "top: 178px;"
        });
    $("#gallery_content_"+num).animate({
        top: "0px"
    }, 1500 );
}

function hide_gallery(num) {
    //$("#gallery_content_"+num).fadeOut(700);
    /*while (!can_start) {
        true;
    } */
    //$("#gallery_content_"+num).stop();
    $("#gallery_content_"+num).animate({
        top: "-178px"
    }, 1500, function(){$("#gallery_content_"+num).attr({
          style: "top: 178px;"
        });});
}
var can_start=true;

var timer;
var currentBg;
var nextBg;
var nextNum = 2;
var maxImagesForSlideShow = 0;

function toggleHeaderBg() {
    if (maxImagesForSlideShow > 1) {
        currentBg.attr({style: "z-index:2;"});
        nextBg.attr({style: "z-index:1; display: block;"});
        /*nextBg.fadeIn(0); */
        currentBg.fadeOut(3000);

        currentBg = nextBg;
        nextNum += 1;
        if (nextNum > maxImagesForSlideShow) nextNum = 1;
        nextBg = $("#header_bg_"+nextNum);
    }
}
