
    function make_photo_box(albom, user_name, imageURL, str_creation_date){
        imageURL = location.protocol+"//"+location.hostname+"/pic_resize.php?src="+imageURL;
        var template = ""+
            "<div class=\"people_small_photo\">"+
                "<div class=\"ptitle\">"+
                    "<h4>"+
                        "#str_creation_date# - #albom#" +
                        "<span style=\"margin-right: 20px; padding: 0px\"><b>Author: </b> #user_name#" +
                        "</span>" +
                    "</h4>"+
                "</div>"+
                "<div class='container' style=\"display:block\">"+
                    "<img src='#imageURL#' />"+
                "</div>"+
            "</div>";
            template = template.replace(/#albom#/, albom);
            template = template.replace(/#user_name#/, user_name);
            template = template.replace(/#imageURL#/, imageURL);
            template = template.replace(/#str_creation_date#/, str_creation_date);
        return template;
    };

    function make_video_box(albom, user_name, imageURL, str_creation_date){
        imageURL = imageURL.replace('.jpg', '.flv');
        var template = ""+
            "<div style=\"width: 500px\" class=\"people_small_photo\">"+
                "<div class=\"ptitle\">"+
                    "<h4>Video "+
                        "#str_creation_date# - #albom#" +
                        "<span><b>Author: </b> #user_name#" +
                        "</span>" +
                    "</h4>"+
                "</div>"+
                "<div class='container' style=\"display:block\">"+
                    '<embed '+
                        'width="480px" height="360px" '+
                        'wmode="opaque" '+
                        'pluginspage="http://www.adobe.com/go/getflashplayer" '+
                        'type="application/x-shockwave-flash" '+
                        'bgcolor="#000000" '+
                        'quality="high" '+
                        'allowscriptaccess="always" '+
                        'allowfullscreen="false" '+
                        'src="/flowplayer-3.1.1.swf" '+
                        'flashvars=\'config={"clip":{"url":"#imageURL#"}}\' '+
                    '</embed>'+
                "</div>"+
            "</div>";

            template = template.replace(/#albom#/, albom);
            template = template.replace(/#user_name#/, user_name);
            template = template.replace(/#imageURL#/, imageURL);
            template = template.replace(/#str_creation_date#/, str_creation_date);

        return template;
    };

    function full_size_photo(creation_date, imageUrl, albom, user_name){
        
        var placeholder = document.body;
        
        jQuery('#full_photo_view').remove();
        
        var template = ""+
        "<div id=\"full_photo_view\" class=\"modal\" style=\"display: none; position: absolute; top: 133px\">"+
        "<img src=\"/images/close.gif\" style=\"top: 5px; right: 5px; position: absolute; cursor: pointer;\" class=\"close-handle\"/>"+
            "<div class=\"title\" style=\"margin: 0px;\">"+
                "<h4 style='text-align: left'>"+creation_date+"&nbsp;&nbsp;"+albom+"<span><b>Author:"+user_name+"</b></span></h4>"+
            "</div>"+
            "<div style=\"padding: 10px; padding-top: 0px\">"+
            "<div id=\"image_placeholder\" style=\"height: 400px;\"><img style=\"margin-top: 180px\"src=\"/ani_load.gif\"/></div>"+
            "</div>"+
        "</div>";
        
        jQuery(placeholder).append(template);
        
        jQuery('#full_photo_view').find('.close-handle').bind('click', function(){
            jQuery('#full_photo_view').remove();
        });
        
        jQuery('#full_photo_view').css({
            width: '600px'
        }).show().css({
            left: (getClientWidth() - 600) / 2
        })
        
        var preloader = new Image();
        preloader.onload = function(){
            this.onload = null;
            
            jQuery('#full_photo_view').find('#image_placeholder').html(
                "<img src=\""+imageUrl+"\"/>"
            ).css('overflow', 'hidden').css('height', 'auto');
            
            var scrW = getClientWidth();
            
            var growWidth = this.width + 20;
            
            if ( growWidth >= scrW )
                growWidth = scrW;
            
            jQuery('#full_photo_view').animate({
                'width': growWidth,
                'left': (scrW - growWidth)/2
            }, 'slow', 'swing', function(){
                jQuery('#full_photo_view').find('#image_placeholder').css({'width': growWidth-20, 'overflow':'auto'});
            });
        };
        preloader.src = imageUrl;
    }
    
    function show_video(creation_date, imageUrl, albom, user_name){
        
        imageUrl = imageUrl.replace(/\.jpg/, ".flv");
        
        jQuery('#full_video_view').remove();
        
        var template = ''+
        "<div id=\"full_video_view\" style=\"background-color:#454545; position: absolute; top: 133px; width: 680px; height: 520px;\">"+
        "<img src=\"/images/close.gif\" style=\"top: 5px; right: 5px; position: absolute; cursor: pointer;\" class=\"close-handle\"/>"+
        '<div style="margin: 10px; width: 660px; height: 500px;">'+
        '<a href="'+imageUrl+'" style="display:block;width:640px;height:480px; margin:0; padding:0;" id="player"></a>'+
        '</div>'+
        '</div>';
        
        jQuery(document.body).append(template);
        
        jQuery('#full_video_view').css('left', (getClientWidth() - 680)/2);
        
        jQuery('#full_video_view').find('.close-handle').bind('click', function(){ jQuery('#full_video_view').remove(); });
        
        flowplayer("player", "/flowplayer-3.1.1.swf");
        
        
    }
    
    function media_nav_block_toggle(){
        jQuery('#media_nav_block_body').toggle();
        
        jQuery('#media_nav_block_toggler').toggleClass('minimized').toggleClass('maximized');
        
    }
    
    function media_next(){
    
        var total  = jQuery('#media_total').val() * 1,
            offset = jQuery('#media_offset').val() * 1,
            limit  = jQuery('#media_nav_limit').val() * 1,
            old_limit = jQuery('#media_limit').val() * 1,
            album =  jQuery('#media_nav_album').val() * 1;
        
        if (!album) return 'no album chosen';
        
        if (offset + limit > total){
            jQuery(this).addClass('disabled'); return 'moving far to border';
        }
        
        media_load_album( album, offset + old_limit );
    }
    
    function media_prev(){
    
        var total  = jQuery('#media_total').val() * 1,
            offset = jQuery('#media_offset').val() * 1,
            limit  = jQuery('#media_nav_limit').val() * 1,
            old_limit = jQuery('#media_limit').val() * 1,
            album =  jQuery('#media_nav_album').val() * 1;
        
        if (!album) return 'no album chosen';
        
        if (offset - limit <0){
            media_load_album( album, 0 ); return;
        }
        
        media_load_album( album, offset - limit );
    }
    
    function media_load_album( album_id , offset){
        
        if (typeof(offset) == 'undefined')
            offset = 0;
        
        media_load_album.album_id = album_id;
        
        var width = getClientWidth() - 2;
        
        width = width || 585;
        
        var limit = jQuery('#media_nav_limit').val() || 20;
        
        var height = jQuery(document.body).get(0).clientHeight;
        
        jQuery('#how_to_align').html('');
        jQuery('#media-map-container').html('<img src="/ani_load.gif" valign="middle"/> Loading ... please wait ');
        
        var url = '/?do=media-album&width='+width+'&height='+height+'&id='+album_id+'&limit='+limit+'&offset='+offset;
        
        //alert(url);
        jQuery('#how_to_align').load(url, function(){
            jQuery('#media-map-container').html('');
            window.scrollTo(0,133);
            
            var total  = jQuery('#media_total').val() * 1,
                offset = jQuery('#media_offset').val() * 1,
                limit  = jQuery('#media_limit').val() * 1;
                
            var str = 'Showing ' + (offset+1) + '-' + (offset+limit>total?total:offset+limit) + ' of ' + total;
            jQuery('#media_nav_position').html(str);
            
            if (offset+limit>total)
                jQuery('#media_nav_btn_next').addClass('disabled');
            else
                jQuery('#media_nav_btn_next').removeClass('disabled');
                
            if (offset == 0)
                jQuery('#media_nav_btn_prew').addClass('disabled');
            else
                jQuery('#media_nav_btn_prew').removeClass('disabled');
            
        });
    }
    
    function setMediaMap(map) {
            
        var srv = location.hostname;
        mapobj = new GMap2(map);
        mapobj.addControl(new GSmallMapControl());
        mapobj.addControl(new GMapTypeControl());
        mapobj.setMapType(G_HYBRID_MAP);
        mapobj.setCenter(new GLatLng(48.129434, 10.019531), 4);
        time = Math.random();
        layer = new GGeoXml("http://"+srv+"/?type=getStatObj&amp;rand="+time);

        GEvent.addListener(layer, "load", function(){    
            this.gotoDefaultViewport(mapobj);
        });
        mapobj.addOverlay(layer);
        SetMediaListeners(mapobj);
    }
    
    function SetMediaListeners (map) {
        var mouseoverListener = GEvent.addListener(map, "click", function(overlay, point) { 
            if (point){     // background clicked
            } else if (overlay.parentGeoXml) {   // marker clicked
                coord = overlay.getPoint();
                coord = coord.toString();
                lol=function(o){
                    var html = "<div style='color: #000'>";
                    var username = o[0]['fullName'].replace(/ /g, '_');
                    html += ""+
                        "Album: <b>"+o[0]['name']+"</b> <br/> by "+'<a onclick="make_request_from_this(this); return false;" href="'+
                        location.protocol+'//'+location.hostname+'/'+username+'">'+o[0]['fullName']+'</a>';
                    
                    html += '<br/> <a style="cursor: pointer" onclick="media_load_album('+o[0].id+')">go to album</a>';
                    
                    html += "</div>";
                    overlay.openInfoWindow(html);
                } 
                //html=$.getJSON("","point="+coord,lol);    
                jQuery.ajax(
                {
                    type: "GET",
                    url: "index.php",
                    data: "point="+coord,
                    dataType: "json",
                    success: lol
                });
                
            }
        });
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    