function init_galery() {

        jQuery(".choose_photo").hover(function () {
            jQuery(this).stop().animate({'opacity':'0.7'}, 200);
        }, function () {
            jQuery(this).stop().animate({'opacity':'1'}, 200);
        });

    function init_photos () {
        jQuery("#bilde_"+selected_photo).css("opacity", "0.5").removeClass("deselected_photo").addClass("selected_photo");

        jQuery(".selected_photo").unbind();
        jQuery(".deselected_photo").unbind();
        jQuery(".deselected_photo").hover(function () {
            jQuery(this).stop().animate({'opacity':'0.7'}, 200);
        }, function () {
            jQuery(this).stop().animate({'opacity':'1'}, 200);
        });
        jQuery(".deselected_photo").click(function () {
            selected_photo = jQuery(this).attr("value");
            jQuery("#bilde_preview").attr("bilde", jQuery(this).attr("bilde"));
            jQuery(".selected_photo").each(function() {
                jQuery(this).css("opacity", "1").removeClass("selected_photo").addClass("deselected_photo");
            });

            jQuery("#bilde_preview").animate({"opacity":"0"});

                jQuery("#bilde_preview").queue(function() {
                    jQuery(this).attr("src", jQuery(this).attr("path")+selected_photo+".jpg");
                    jQuery(this).dequeue();
                });
                jQuery("#bilde_preview").queue(function() {
                    jQuery(this).animate({"opacity":"1"});
                    jQuery(this).dequeue();
                });



            init_photos();
        });
    }
    init_photos();
                jQuery("#btn_palielinat").click(function(){
                    jQuery("#bilde_preview").click();
                });
	            jQuery("#bilde_preview").click(function(){
                        data = '<object  height="590" width="390" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" name="Preview" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"><param value="./zoom.swf" name="movie"/><param value="transparent" name="wmode"/><param value="high" name="quality"/><param value="loadimage=galery/original/'+jQuery(this).attr("bilde")+'" name="FlashVars"/><embed height="590" width="390" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" loadimage="sample.jpg" FlashVars="loadimage=galery/original/'+jQuery(this).attr("bilde")+'" name="Preview" wmode="transparent" quality="high" src="./zoom.swf"/></object>';
                        jQuery("#zoomer_place").html(data);
                        popupid="popup_preview";
                        centerPopup();
		                loadPopup();
	            });






    function load_collection (current_collection, first_time, cllection_caption) {
        jQuery.post("collections_single.php", {"current_collection":current_collection, "lang":lang} ,function(data){
            if (first_time == 1) {
                jQuery("#collection_single").html(data);
            } else {

                jQuery("#collection_single").animate({"opacity":"0"});
                jQuery("#collection_caption").animate({"opacity":"0"});

                jQuery("#collection_single").queue(function() {
                    jQuery(this).html(data);
                    jQuery("#collection_caption").html(cllection_caption);
                    jQuery(this).dequeue();
                });
                jQuery("#collection_single").queue(function() {
                    jQuery(this).animate({"opacity":"1"}, 500);
                    jQuery("#collection_caption").animate({"opacity":"1"});
                    jQuery(this).dequeue();
                });
            }


            function make_photos_clickable() {
            jQuery("#collection_single").queue(function() {
                jQuery(".selected_photo").css("opacity", "0.5");
                jQuery(".deselected_photo").css("opacity", "1");

                    jQuery(".deselected_photo").hover(function () {
                    jQuery(this).stop().animate({'opacity':'0.5'}, 200);
                     }, function () {
                        jQuery(this).stop().animate({'opacity':'1'}, 200);
                    });
                    jQuery(this).dequeue();

                jQuery(".deselected_photo").click(function () {
                    jQuery(".deselected_photo").unbind();
                    //alert(jQuery(this).attr("id"));
                    change_preview(jQuery(this).attr("id"));
                    jQuery(".selected_photo").each(function () {
                        jQuery(this).removeClass("selected_photo");
                        jQuery(this).addClass("deselected_photo");
                    });
                    jQuery(this).removeClass("deselected_photo");
                    jQuery(this).addClass("selected_photo");
                    make_photos_clickable();

                });
                jQuery("#g_poga_palielinat").click(function(){
                     jQuery("#collection_preview").click();
                })
	            jQuery("#collection_preview").click(function(){
                    //jQuery.post("collections_single.php", {"zoom":current_collection} ,function(data){
                        //alert(data);
                        data = '<object  height="590" width="390" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" name="Preview" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"><param value="./zoom.swf" name="movie"/><param value="transparent" name="wmode"/><param value="high" name="quality"/><param value="loadimage=galery/original/'+jQuery(this).attr("bilde")+'" name="FlashVars"/><embed height="590" width="390" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" loadimage="sample.jpg" FlashVars="loadimage=galery/original/'+jQuery(this).attr("bilde")+'" name="Preview" wmode="transparent" quality="high" src="./zoom.swf"/></object>';
                        //jQuery("#collection_single").animate({"opacity":"0"});
                        jQuery("#zoomer_place").html(data);
                        popupid="popup_preview";
                        centerPopup();
		                loadPopup();
                    //});

	            });

            });
            }
            make_photos_clickable();

        });
    }
    //load_collection(current_collection, "1");




    function make_collection_clickable() {
        jQuery(".selected_collection").css("opacity", "0.5");
        jQuery(".deselected_collection").css("opacity", "1");

        jQuery(".deselected_collection").hover(function () {
            jQuery(this).stop().animate({'opacity':'0.5'}, 200);
        }, function () {
            jQuery(this).stop().animate({'opacity':'1'}, 200);
        });


        jQuery(".deselected_collection").click(function () {
            jQuery(".deselected_collection").unbind();
            load_collection(jQuery(this).attr("id"), null, jQuery(this).attr("collection_caption"));
            jQuery(".selected_collection").each(function () {
                jQuery(this).removeClass("selected_collection");
                jQuery(this).addClass("deselected_collection");
            });
            jQuery(this).removeClass("deselected_collection");
            jQuery(this).addClass("selected_collection");
            make_collection_clickable();
        });

        //jQuery("#collection_preview").click(function(){

            //jQuery("#collection_preview").queue(function() {
                //jQuery("#collection_single").animate({"opacity":"0"});
                //jQuery(this).dequeue();
           // });
           // jQuery("#collection_preview").queue(function() {
               // centerPopup();
               // loadPopup();
               // jQuery(this).dequeue();
           // });

       // });
    }
    //make_collection_clickable();


    function change_preview(which_image) {
        //alert(which_image);
        jQuery.post("collections_single.php", {"preview_image":which_image} ,function(data){
                jQuery("#collection_preview").animate({"opacity":"0"});

                jQuery("#collection_preview").queue(function() {
                    jQuery(this).html('<img src="galery/large/'+data+'" /><div class="semi_transparent" style="position:absolute; width:33px; height:33px; left:245px; top:0px; background-image:url(template/lupa.png);"></div>');
                    jQuery(this).attr("bilde", data)
                    //alert(data);
                    jQuery(this).dequeue();
                });
                jQuery("#collection_preview").queue(function() {
                    jQuery(this).animate({"opacity":"1"}, 500);
                    jQuery(this).dequeue();
                });
        });
    }
}
