    document.observe("dom:loaded", function() {

        $$('img.bbvid').each(function (element) {
           
            element.observe('click', function(event) {

            oheight = Event.element(event).getHeight();
            id = element.readAttribute('id');
            id = id.substring(4);

            height = (oheight * 2) + 20;
           
                var win = Popup.open({url: '/review/vid_popup/?id=' + id,'centre':true, 'width':'450','height': '400'}); 

                          if (window.focus) { win.focus(); }

                });

            element.observe('mouseover', function(event) {

                Event.element(event).setStyle({'cursor':'pointer'});

            });
        });

        $$('img.bbimg').each(function (element) {
           
            element.observe('click', function(event) {

                content = Event.element(event).readAttribute('src');
				
				alt = Event.element(event).readAttribute('alt');
 
                oheight = Event.element(event).getHeight();

                height = (oheight * 2) + 20;
  
                html = '<img style="padding:10px" src="' + content + '" alt="' + alt + '" title="' + alt + '"/>';

                var win = Popup.open({'centre':true, 'width':'450','height': '400'}); 

                win.document.open("text/html", "replace");
                win.document.write("<html><head><title>Brownbook</title></head><body><center>"+ html + "</center></body></html>");

                win.document.close();
                
                if (window.focus) { win.focus(); }

                });

            element.observe('mouseover', function(event) {

                Event.element(event).setStyle({'cursor':'pointer'});

            });

        });

        $$('img.bbembed').each(function (element) {
           
            content = element.readAttribute('alt');
            st = element.readAttribute('src');
            id = element.readAttribute('id');
            id = id.substring(4);
            
            oheight = element.getHeight();

            if (oheight < 1){
                oheight = 300;
            }

            height = oheight + 20;
            

            var flashvars = {};
            flashvars.file = content;
            flashvars.image = st;
            var params = {'allowscriptaccess': 'always'};
            var attributes = {};
            
            swfobject.embedSWF('/includes/flvplayer.swf',id,'400', height ,'7','', flashvars, params, attributes );
    
         });

 


    });

document.observe("dom:loaded", function() {

    $$('a.reviewhelpful').each(function(element) {
        Event.observe(element, 'click', function(event) {
        
            href = element.readAttribute('href');
           
            id = href.substring(16);
            
            aj = new Ajax.Request("/aj" + href, {
                method: 'get',
                onSuccess: function(transport) {
            
                    if (transport.responseText.match(/1/)) {
                        
                        $('cmarked_' + id).show();
                        $('rmarked_' + id).hide();
                        
                    } else {
                
                    }
                }
            });
            Event.stop(event);
        });
    });
	
	        $$('span.bbvid').each(function (element) {
										           
            element.observe('click', function(event) {
											  
											
            oheight = Event.element(event).getHeight();
            id = element.readAttribute('id');
            id = id.substring(4);

            height = (oheight * 2) + 20;
           
                var win = Popup.open({url: '/review/vid_popup/?id=' + id,'centre':true, 'width':'450','height': '400'}); 

                          if (window.focus) { win.focus(); }

                });

            element.observe('mouseover', function(event) {

                Event.element(event).setStyle({'cursor':'pointer'});

            });
        });
			
        $$('span.bbimg').each(function (element) {
           
            element.observe('click', function(event) {

                content = Event.element(event).readAttribute('src');
 
                oheight = Event.element(event).getHeight();

                height = (oheight * 2) + 20;
  
                html = '<img style="padding:10px" src="' + content + '" />';

                var win = Popup.open({'centre':true, 'width':'450','height': '400'}); 

                win.document.open("text/html", "replace");
                win.document.write("<html><head><title>Brownbook</title></head><body><center>"+ html + "</center></body></html>");

                win.document.close();
                
                if (window.focus) { win.focus(); }

                });

            element.observe('mouseover', function(event) {

                Event.element(event).setStyle({'cursor':'pointer'});

            });

        });
    
        $$('img.qrsmall').each(function (element) {
           
            element.observe('click', function(event) {

                content = Event.element(event).readAttribute('src');
				
				alt = Event.element(event).readAttribute('alt');
 				title = Event.element(event).readAttribute('title');

                oheight = Event.element(event).getHeight();

                height = (oheight * 2) + 20;
 
                html = '<p>Scan this with your mobile phone camera <a href="http://en.wikipedia.org/wiki/QR_Code" target="_new">[?]</a></p>';
                html += '<img src="' + content + '" alt="' + alt + '" title="' + alt + '"/>';

                var win = Popup.open({'centre':true, 'width':'450','height': '400'}); 

                win.document.open("text/html", "replace");
                win.document.write("<html><head><link href='/includes/BrownBook1204.css' rel='stylesheet' type='text/css' /><title>"+title+ "</title></head><body><center>"+ html + "</center></body></html>");

                win.document.close();
                
                if (window.focus) { win.focus(); }

                });

            element.observe('mouseover', function(event) {

                Event.element(event).setStyle({'cursor':'pointer'});

            });

        });

});

var en = {};
var en_p = 1;
var en_perPage = 5;

function getendorsements(id) {

    new Ajax.Request('/aj/business/get_endorsements/' + id,
            {
                method: "get",
                onSuccess: function(rt) {
                    var json_data = rt.responseText;
                    eval("var json = ("+json_data+")");
                
                    getendorsements_h(json);
                }
            });

}

function getendorsements_h(json) {

    if (json.error == 1) {

        return;
    }
    
    en = json.endorsements;

    var total = en.length;
   
    if (total == 0) {

        return;
    }

    en_buildTable();

    $('endorsements_bpp').show();

}

function en_buildTable() {


    $$('tr.row').invoke('remove');
    $$('td.plinks').invoke('update', '');

    var total = en.length;

    var start = 0;
    var end = total;
    var pages = 1;

    pages = Math.ceil(total / en_perPage);
    start = (en_p - 1) * en_perPage;
    end = start + en_perPage;

    if (end > total) { end = total};

    for (var i=start;i<end;i++) {
        
        var tr = document.createElement('tr');
        $(tr).writeAttribute({className: 'row'});

        var td = document.createElement('td');
        var a  = document.createElement('a');

        $(a).update(en[i].business.business_name);
        $(a).writeAttribute({href: '/business/' + en[i].business.businessId + "/" + en[i].business.link});
        $(td).appendChild(a);
        $(tr).appendChild(td);

        td = document.createElement('td');
        $(td).update(en[i].business.business_postcode);
        $(tr).appendChild(td);

        td = document.createElement('td');
        a  = document.createElement('a');

        $(a).update(en[i].business.user_detail.user_screen);
        $(a).writeAttribute({href: '/account/profile/' + en[i].business.user_detail.userId});

        $(td).appendChild(a);
        $(tr).appendChild(td);

        $('endorse_tbody').appendChild(tr);
    }
   
    var plinks = 'en_links';

    if (en_p > 1) {
        a = document.createElement('a');
        $(a).writeAttribute({id: 'p_' + (en_p - 1), className: 'standardlink selectpage'}); 
        $(a).update('&lt; &lt; Prev');

        $(plinks).appendChild(a);

        text = document.createTextNode(" | ");
        $(plinks).appendChild(text);
    }

    for (var i=1;i<=pages;i++) {
        
        if (i == en_p) {

            text = document.createTextNode(i);
            $(plinks).appendChild(text);
        } else {

            a = document.createElement('a');
            $(a).writeAttribute({id: 'p_' + i, className: 'standardlink selectpage'}); 
            $(a).update(i);

            $(plinks).appendChild(a);

        }

        if (pages > 1 && i != pages) {

            text = document.createTextNode(" | ");
            $(plinks).appendChild(text);
            
        }
    }

    if (en_p < pages) {

        text = document.createTextNode(" | ");
        $(plinks).appendChild(text);

        a = document.createElement('a');
        $(a).writeAttribute({id: 'p_' + (en_p + 1), className: 'standardlink selectpage'}); 
        $(a).update('Next &gt;&gt;');

        $(plinks).appendChild(a);

    }

    var row = $('en_links_row').remove();
    $('endorse_tbody').insert(row, {position: 'bottom'});

    $$('a.selectpage').each(function(f) {

        $(f).observe('click', function(event) {

            Event.stop(event);

        var id = $(f).readAttribute('id');
        var p = parseInt(id.substring(2));

        en_p = p;

        en_buildTable();
        });
    });


}

