var Pikout=Class.create();
var PPSizerSize=10;
var PPSizerHalf=PPSizerSize/2;
var PPBubbleGap=24;
var PPBubbleGapHalf=PPBubbleGap/2;
var PPBubbleWidth=30;
var PPBubbleWidthHalf=PPBubbleWidth/2;
var offsetWidgetSize=5;
var iconWidth=55;
var isLoggedIn=false;
var noFileUploadAllowed=false;
var AllowedProperties={border:1,vspace:1,lowsrc:1,useMap:1,align:1,width:1,src:1,hspace:1,alt:1,height:1,tabIndex:1,accessKey:1,title:1,lang:1,"class":1,language:1,cellPadding:1,cellSpacing:1,contentEditable:1};
var effect_opts=[{code:"rcolor",range:$R(0,10),defaultval:1},{code:"sketch",range:$R(1,10),defaultval:1,excludebling:true},{code:"oil",range:$R(0,10),defaultval:1},{code:"halftone",range:$R(0,9),defaultval:1},{code:"news",range:$R(2,4),values:[2,3,4],defaultval:2},{code:"mblur",range:$R(1,20),defaultval:1},{code:"misty",range:$R(1,20),defaultval:1,excludebling:true},{code:"rblur",range:$R(0,15),defaultval:1,excludebling:true},{code:"contrast",range:$R(0,10),values:[1,2,3,4,5,6,7,8,9],defaultval:5},{code:"bright",range:$R(0,300),defaultval:100},{code:"sat",range:$R(0,300),defaultval:100},{code:"tint",range:$R(0,255),defaultval:100}];
var fonts=["Arial","Tahoma","Times New Roman","Verdana"];

// DIV Menu : Flip, Rotation.... suivant type navigateur
/*
var type_0= '<div id="mp_[ID]" style="display:none;margin-top:2px;width:450px;background-color:#282828;" class="managepaneoff" stopdeselect="true" >'+
            '<table border="0" cellspacing="0" cellpadding="0" width="100%">'+
// top arrondi
                '<tr>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_left_top.gif);background-repeat:no-repeat;background-position:top left;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                    '<td style="background-color:#68ADE6"><img src="images/spacer.gif" width="1" height="6" border="0" alt="" /></td>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_right_top.gif);background-repeat:no-repeat;background-position:top right;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                '</tr>'+
                '<tr>'+
                '<td style="background-image:url(themes/kubrick/images/blue_middle.gif);background-repeat:repeat-x;background-position:bottom;background-color:#6BADE1"><img src="images/spacer.gif" width="6" height="170" border="0" alt="" /></td>'+
                '<td>'+
                  '<table class="managepane" border="0">'+
                    '<tr style="height:168px">'+
                      '<td style="width:90px" align="center" valign="top"><img src="/images/circle_with_triangle.gif" id="mp_[ID]_bli" border="0" style="margin-top:7px;"/><br>'+
                      '<a id="mp_[ID]_bll" href="#"><img src="/images/move_left.gif" title="Deform -" title="Deform -" border="0" style="margin-left:5px;margin-right:5px;" /></a>'+
                      '<a id="mp_[ID]_blr" href="#"><img src="/images/move_right.gif" title="Deform +" title="Deform +" border="0" style="margin-left:5px;margin-right:5px;" /></a>'+
                      '<input name="bezierL" type="hidden" size="1" maxlength="3" style="margin-left:5px;margin-bottom:1px;" id="mp_[ID]_bl" class="front"/></td>'+
                      '<td style="width:90px">'+
                        '<table style="width:90px">'+
                          '<tr>'+
                            '<td align="center"><a id="mp_[ID]_fh" href="#"><img src="/images/flip_horizontal.gif" title="Flip" border="0" style="margin-left:10px;margin-right:10px;" /></a></td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td class="inneroff" id="mp_[ID]_tn" align="center" valign="center">'+
                              '<img src="/images/smaple_hat.gif" id="mp_[ID]_img"/>'+
                            '</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td valign="bottom" align="center"><img src="/images/circle_with_carre.gif" id="mp_[ID]_roi" border="0"/><br>'+
                            '<a id="mp_[ID]_rol" href="#"><img src="/images/move_left.gif" title="Rotation -" border="0" style="margin-left:5px;margin-right:5px;" /></a>'+
                            '<a id="mp_[ID]_ror" href="#"><img src="/images/move_right.gif" title="Rotation +" border="0" style="margin-left:5px;margin-right:5px;" /></a>'+
                            '<input name="rotate" type="hidden" size="1" maxlength="3" style="margin-left:5px;margin-bottom:1px;" id="mp_[ID]_ro" class="front"/></td>'+
                          '</tr>'+
                        '</table>'+
                      '</td>'+
                      '<td style="width:90px" align="center" valign="middle"><img src="/images/circle_with_triangle.gif" id="mp_[ID]_bri" border="0"/><br>'+
                      '<a id="mp_[ID]_brl" href="#"><img src="/images/move_left.gif" title="Deform -" border="0" style="margin-left:5px;margin-right:5px;" /></a>'+
                      '<a id="mp_[ID]_brr" href="#"><img src="/images/move_right.gif" title="Deform +" border="0" style="margin-left:5px;margin-right:5px;" /></a>'+
                      '<input name="bezierR" type="hidden" size="1" maxlength="3" style="margin-left:5px;margin-bottom:1px;" id="mp_[ID]_br" class="front"/></td>'+
                      '<td valign="top" style="width:120px">'+
                        '<table cellpadding="0" cellspacing="0">' +
                          '<tr>'+
                            '<td align="center">'+
                              '<img src="/images/lightbar.gif" width="60" height="15" style="margin-top:5px;margin-left:5px;margin-right:5px;margin-bottom:12px;"/>'+
                            '</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td style="border-bottom: 2px solid #959595;" align="center">'+
                              '<a id="mp_[ID]_trl" href="#"><img src="/images/move_left.gif" title="Transparent -" border="0" valign="bottom" style="margin-left:5px;margin-right:5px;" /></a>'+
                              '<input name="transparency" style="margin-bottom:10px;" type="text" size="1" maxlength="3" id="mp_[ID]_tr" class="front"/>'+
                              '<a id="mp_[ID]_trr" href="#"><img src="/images/move_right.gif" title="Transparent +" border="0" style="margin-left:5px;margin-right:5px;" /></a>'+
                              '<input name="top" type="hidden" size="1" maxlength="3" id="mp_[ID]_t" class="front"/>'+
                              '<input name="left" type="hidden" size="1" maxlength="3" id="mp_[ID]_l" class="front"/>'+
                              '<input name="height" type="hidden" size="1" maxlength="3" id="mp_[ID]_h" class="front"/>'+
                              '<input name="width" type="hidden" size="1" maxlength="3" id="mp_[ID]_w" class="front"/>'+
                            '</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td align="center">'+
                              '<img src="/images/hide.gif" width="48" height="48" style="margin-top:5px;margin-left:5px;margin-right:5px;margin-bottom:5px;"/><br>'+
                              '<img src="/images/move_left.gif" title="move back in order" id="mp_[ID]_zd" style="cursor:pointer;margin-left:5px;margin-right:5px;"/>'+
                              '<input style="margin-bottom:10px;" name="order" type="text" id="mp_[ID]_order" class="front"/>'+
                              '<input name="move_up" type="hidden" id="mp_[ID]_zvalue" class="front"/>'+
                              '<img src="/images/move_right.gif" title="move up in order" id="mp_[ID]_zu" style="cursor:pointer;margin-left:5px;margin-right:5px;"/>'+
                            '</td>'+
                          '</tr>'+
                        '</table>'+
                      '</td>'+
                      '<td style="width:40px" valign="top" align="right">'+
                        '<img src="/images/delete.gif" title="delete" id="mp_[ID]_del" style="cursor:pointer"/>'+'<br />'+
                      '</td>'+
                    '</tr>'+
                  '</table>'+
                '</td>'+
                '<td style="background-image:url(themes/kubrick/images/blue_middle.gif);background-repeat:repeat-x;background-position:bottom;background-color:#6BADE1"><img src="images/spacer.gif" width="6" height="170" border="0" alt="" /></td>'+
                '</tr>'+
                '<tr>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_bottom_left.gif);background-repeat:no-repeat;background-position:top left;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                    '<td style="background-color:#3F80B6"><img src="images/spacer.gif" width="1" height="6" border="0" alt="" /></td>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_bottom_right.gif);background-repeat:no-repeat;background-position:top right;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                '</tr>'+
            '</table>'+
            '</div>';
*/

var type_0= '<div id="mp_[ID]" style="display:none;margin-top:2px;width:450px;background-color:#282828;" class="managepaneoff" stopdeselect="true" >'+
            '<table border="0" cellspacing="0" cellpadding="0" width="100%">'+
// top arrondi
                '<tr>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_left_top.gif);background-repeat:no-repeat;background-position:top left;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                    '<td style="background-color:#68ADE6"><img src="images/spacer.gif" width="1" height="6" border="0" alt="" /></td>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_right_top.gif);background-repeat:no-repeat;background-position:top right;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                '</tr>'+
                '<tr>'+
                '<td style="background-image:url(themes/kubrick/images/blue_middle.gif);background-repeat:repeat-x;background-position:bottom;background-color:#6BADE1"><img src="images/spacer.gif" width="6" height="82" border="0" alt="" /></td>'+
                '<td>'+
                  '<table class="managepane" border="0">'+
                    '<tr style="height:80px">'+
                      '<td valign="top" style="width:130px">'+
                        '<table style="width:160px">'+
                          '<tr>'+
                            '<td align="center">'+
                            '<img src="/images/smaple_hat.gif" id="mp_[ID]_srcf0"/>'+
                            '<a id="mp_[ID]_fh" href="#"><img src="/images/flip_horizontal.gif" title="Flip" border="0" style="cursor:pointer;margin-left:3px;margin-right:3px;" /></a>'+
                            '<img src="/images/smaple_hat.gif" id="mp_[ID]_srcfh"/></td>'+
                          '</tr>'+
                        '</table>'+
                      '</td>'+
                      '<td valign="top" style="width:130px">'+
                        '<table>'+
                          '<tr>'+
                            '<td align="center">'+
                              '<a id="mp_[ID]_rol" href="#"><img valign="center" src="/images/turn_left.gif" title="Rotation -" border="0" width="30" height="30" style="cursor:pointer;margin-left:3px;" /></a>'+
                              '<img src="/images/circle_with_carre.gif" id="mp_[ID]_roi" border="0"/>'+
                              '<a id="mp_[ID]_ror" href="#"><img valign="center" src="/images/turn_right.gif" title="Rotation +" border="0" width="30" height="30" style="cursor:pointer;margin-right:3px;" /></a>'+
                              '<input name="rotate" type="hidden" size="1" maxlength="3" id="mp_[ID]_ro" class="front"/>'+
                            '</td>'+
                          '</tr>'+
                        '</table>'+
                      '</td>'+
                      '<td valign="top" style="width:110px">'+
                        '<table cellpadding="0" cellspacing="0">' +
                          '<tr>'+
                            '<td align="center">'+
                              '<img src="/images/smaple_hat.gif" id="mp_[ID]_srct0"/><img src="/images/smaple_hat.gif" id="mp_[ID]_srct100"/>'+
                            '</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td align="center">'+
                              '<a id="mp_[ID]_trl" href="#"><img src="/images/move_left.gif" title="Transparent -" border="0" valign="bottom" style="cursor:pointer;margin-left:3px;margin-right:3px;" /></a>'+
                              '<input name="transparency" style="margin-bottom:10px;" type="text" size="1" maxlength="3" id="mp_[ID]_tr" class="front"/>'+
                              '<a id="mp_[ID]_trr" href="#"><img src="/images/move_right.gif" title="Transparent +" border="0" style="cursor:pointer;margin-left:3px;margin-right:3px;" /></a>'+
                              '<input name="top" type="hidden" size="1" maxlength="3" id="mp_[ID]_t" class="front"/>'+
                              '<input name="left" type="hidden" size="1" maxlength="3" id="mp_[ID]_l" class="front"/>'+
                              '<input name="height" type="hidden" size="1" maxlength="3" id="mp_[ID]_h" class="front"/>'+
                              '<input name="width" type="hidden" size="1" maxlength="3" id="mp_[ID]_w" class="front"/>'+
                            '</td>'+
                          '</tr>'+
                        '</table>'+
                      '</td>'+
                      '<td style="width:30px" valign="top" align="right">'+
                        '<img src="/images/delete.gif" title="delete" id="mp_[ID]_del" style="cursor:pointer"/>'+'<br />'+
                      '</td>'+
                    '</tr>'+
                    '<tr>'+
                      '<td align="center" valign="top">Flip</td>'+
                      '<td align="center" valign="top">Rotation</td>'+
                      '<td align="center" valign="top">Transparency</td>'+
                      '<td align="center" valign="top">&nbsp;</td>'+
                    '</tr>'+
                  '</table>'+
                '</td>'+
                '<td style="background-image:url(themes/kubrick/images/blue_middle.gif);background-repeat:repeat-x;background-position:bottom;background-color:#6BADE1"><img src="images/spacer.gif" width="6" height="82" border="0" alt="" /></td>'+
                '</tr>'+
                '<tr>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_bottom_left.gif);background-repeat:no-repeat;background-position:top left;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                    '<td style="background-color:#3F80B6"><img src="images/spacer.gif" width="1" height="6" border="0" alt="" /></td>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_bottom_right.gif);background-repeat:no-repeat;background-position:top right;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                '</tr>'+
            '</table>'+
            '</div>';

/*
var type_0= '<div id="mp_[ID]" style="display:none;margin-top:2px;width:600px;background-color:#282828;" class="managepaneoff" stopdeselect="true" >'+
            '<table border="0" cellspacing="0" cellpadding="0" width="100%">'+
                '<tr>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_left_top.gif);background-repeat:no-repeat;background-position:top left;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                    '<td style="background-color:#68ADE6"><img src="images/spacer.gif" width="1" height="6" border="0" alt="" /></td>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_right_top.gif);background-repeat:no-repeat;background-position:top right;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                '</tr>'+
                '<tr>'+
                '<td style="background-image:url(themes/kubrick/images/blue_middle.gif);background-repeat:repeat-x;background-position:bottom;background-color:#6BADE1"><img src="images/spacer.gif" width="6" height="170" border="0" alt="" /></td>'+
                '<td>'+
                  '<table class="managepane" border="1">'+
                    '<tr style="height:100px">'+
                      '<td style="width:20px">'+
                        '<input name="move_up" type="hidden" id="mp_[ID]_zvalue" class="front"/>'+
                        '<img src="/images/move_up.gif" width="18" height="18" alt="move up in order" id="mp_[ID]_zu" style="cursor:pointer"/>'+
                        '<br />'+
                        '<br />'+
                        '<input name="order" type="text" align="center" id="mp_[ID]_order" class="front"/>'+
                        '<br />'+
                        '<br />'+
                        '<img src="/images/move_down.gif" width="18" height="18" alt="move back in order" id="mp_[ID]_zd" style="cursor:pointer"/>'+
                      '</td>'+
                      '<td align="center" valign="top"><img src="/images/circle_with_line.gif" id="mp_[ID]_bli" border="0" style="margin-bottom:7px;"/></td>'+
                      '<td align="center"><a id="mp_[ID]_bll" href="#"><img src="/images/move_left.gif" alt="Deform -" title="Deform -" border="0" style="margin-left:5px;margin-right:5px;" /></a></td>'+
                      '<td align="center"><a id="mp_[ID]_blr" href="#"><img src="/images/move_right.gif" alt="Deform +" title="Deform +" border="0" style="margin-left:5px;margin-right:5px;" /></a></td>'+
                      '<td valign="top"><input name="bezierL" type="text" size="1" maxlength="3" style="margin-left:5px;margin-bottom:1px;" id="mp_[ID]_bl" class="front"/> degrees</td>'+
                      '<td class="inneroff" id="mp_[ID]_tn" align="center" valign="center">'+
                        '<img src="/images/smaple_hat.gif" id="mp_[ID]_img"/>'+
                      '</td>'+
                      '<td align="center" valign="bottom"><img src="/images/circle_with_line.gif" id="mp_[ID]_bri" border="0" style="margin-bottom:7px;"/></td>'+
                      '<td align="center"><a id="mp_[ID]_brl" href="#"><img src="/images/move_left.gif" alt="Deform -" title="Deform -" border="0" style="margin-left:5px;margin-right:5px;" /></a></td>'+
                      '<td align="center"><a id="mp_[ID]_brr" href="#"><img src="/images/move_right.gif" alt="Deform +" title="Deform +" border="0" style="margin-left:5px;margin-right:5px;" /></a></td>'+
                      '<td valign="bottom"><input name="bezierR" type="text" size="1" maxlength="3" style="margin-left:5px;margin-bottom:1px;" id="mp_[ID]_br" class="front"/> degrees</td>'+
                      '<td valign="top">'+
                        '<table border="1" cellpadding="0" cellspacing="0">' +
                          '<tr>'+
                            '<td align="center">transparency <input name="transparency" type="text" size="1" maxlength="3" id="mp_[ID]_tr" class="front"/> %</td>'+
                            '<td align="center"><a id="mp_[ID]_trl" href="#"><img src="/images/move_left.gif" alt="Transparent -" title="Transparent -" border="0" style="margin-left:5px;margin-right:5px;" /></a></td>'+
                            '<td align="center"><a id="mp_[ID]_trr" href="#"><img src="/images/move_right.gif" alt="Transparent +" title="Transparent +" border="0" style="margin-left:5px;margin-right:5px;" /></a></td>'+
                            '<td align="center"><a id="mp_[ID]_fh" href="#"><img src="/images/[PREFIX]flip_horizontal.gif" title="Flip Horizontal" border="0" style="margin-left:10px;margin-right:10px;" /></a></td>'+
                            '<td align="center"><img src="/images/circle_with_line.gif" id="mp_[ID]_roi" border="0" style="margin-bottom:7px;"/></td>'+
                            '<td align="center"><a id="mp_[ID]_rol" href="#"><img src="/images/move_left.gif" title="Rotation -" border="0" style="margin-left:10px;margin-right:10px;" /></a></td>'+
                            '<td align="center"><a id="mp_[ID]_ror" href="#"><img src="/images/move_right.gif" title="Rotation +" border="0" style="margin-left:10px;margin-right:10px;" /></a></td>'+
                            '<td><input name="rotate" type="text" size="1" maxlength="3" style="margin-left:5px;margin-bottom:1px;" id="mp_[ID]_ro" class="front"/> degrees</td>'+
                          '</tr>'+
                            '<input name="top" type="text" size="1" maxlength="3" style="margin-right:10px;" id="mp_[ID]_t" class="front"/>'+
                            '<input name="left" type="text" size="1" maxlength="3" style="margin-right:10px;" id="mp_[ID]_l" class="front"/>'+
                            '<input name="height" type="text" size="1" maxlength="3" style="margin-right:10px;" id="mp_[ID]_h" class="front"/>'+
                            '<input name="width" type="text" size="1" maxlength="3" id="mp_[ID]_w" class="front"/>'+
                        '</table>'+
                      '</td>'+
                      '<td style="width:20px" valign="top">'+
                        '<img src="/images/delete.gif" width="18" height="18" alt="delete item" id="mp_[ID]_del" style="cursor:pointer"/>'+'<br />'+
                      '</td>'+
                    '</tr>'+
                  '</table>'+
                '</td>'+
                '<td style="background-image:url(themes/kubrick/images/blue_middle.gif);background-repeat:repeat-x;background-position:bottom;background-color:#6BADE1"><img src="images/spacer.gif" width="6" height="170" border="0" alt="" /></td>'+
                '</tr>'+
                '<tr>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_bottom_left.gif);background-repeat:no-repeat;background-position:top left;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                    '<td style="background-color:#3F80B6"><img src="images/spacer.gif" width="1" height="6" border="0" alt="" /></td>'+
                    '<td width="6" style="background-image:url(themes/kubrick/images/blue_bottom_right.gif);background-repeat:no-repeat;background-position:top right;background-color:#68ADE6"><img src="images/spacer.gif" width="6" height="6" border="0" alt="" /></td>'+
                '</tr>'+
            '</table>'+
            '</div>';
*/

// DIV Menu : Flip, Rotation.... suivant type navigateur
var type_1= '<div id="mp_[ID]" style="display:none;margin-top:2px;width:400px;background-color:#282828;" class="managepaneoff" stopdeselect="true">'+
            '<table class="managepane" border="1">'+
              '<tr>'+
                '<td class="inneroff" id="mp_[ID]_tn" align="center" valign="center">'+
                  '<img src="/images/smaple_hat.gif" id="mp_[ID]_img"/>'+
                '</td>'+
                '<td>'+
                  '<img src="/images/move_up.gif" width="18" height="18" alt="move up in order" id="mp_[ID]_zu"/>'+
                  '<br />'+
                  '<img src="/images/delete.gif" width="18" height="18" alt="delete item" id="mp_[ID]_del"/>'+
                  '<br />'+
                  '<img src="/images/move_down.gif" width="18" height="18" alt="move back in order" id="mp_[ID]_zd"/>'+
                '</td>'+
                '<td>'+
                    '<table border="0" cellpadding="0" cellspacing="0" class="managepane"><tr><td valign="top">text</td><td valign="top">'+
                    '<textarea name="text" cols="15" rows="3" style="margin-bottom:1px;margin-right:5px;" id="mp_[ID]_text" class="front">Bubble Text</textarea>'+
                '</td><td>'+
                    'font <select class="frontpanel" style="margin-bottom:1px;" id="mp_[ID]_font"></select><br/>'+
                    'size <input name="size" type="text" size="1" maxlength="3" id="mp_[ID]_fs" class="front" value="10"/> '+'Bold:<input name="size" type="checkbox" id="mp_[ID]_b"/> '+'Italics:<input name="size" type="checkbox" id="mp_[ID]_i"/> '+'</td></tr><tr><td colspan="3">'+'top <input name="top" type="text" size="1" maxlength="3" style="margin-right:19px;" id="mp_[ID]_t" class="front"/> left <input name="left" type="text" size="1" maxlength="3" style="margin-right:19px;" id="mp_[ID]_l" class="front"/> height <input name="height" type="text" size="1" maxlength="3" style="margin-right:19px;" id="mp_[ID]_h" class="front"/> width <input name="width" type="text" size="1" maxlength="3" id="mp_[ID]_w" class="front"/>'+'</td></tr></table>'+'</td>'+'</tr>'+'</table>'+'</div>';

// DIV Menu : Flip, Rotation.... suivant type navigateur
var type_2='<div id="mp_[ID]" style="display:none;margin-top:2px;width:400px;background-color:#282828;" class="managepaneoff" stopdeselect="true">'+
                    '<table class="managepane">'+
                      '<tr>'+
                        '<td class="inneroff" id="mp_[ID]_tn" align="center" valign="center" style="display:none;">'+
                          '<img src="/images/smaple_hat.gif" id="mp_[ID]_img"/>'+
                        '</td>'+
                        '<td>'+
                          '<img src="/images/move_up.gif" width="18" height="18" alt="move up in order" id="mp_[ID]_zu" style="cursor:pointer;"/>'+
                          '<br />'+
                          '<img src="/images/delete.gif" width="18" height="18" alt="delete item" id="mp_[ID]_del" style="cursor:pointer;"/>'+
                          '<br />'+
                          '<img src="/images/move_down.gif" width="18" height="18" alt="move back in order" id="mp_[ID]_zd" style="cursor:pointer;"/>'+
                        '</td>'+
                        '<td>'+
                          '<table border="0" cellpadding="0" cellspacing="0" class="managepane"><tr><td>'+
                          '<textarea name="text" cols="20" rows="3" style="margin-bottom:1px;margin-right:1px;" id="mp_[ID]_text" class="front">Bubble Text</textarea>'+
                        '</td><td rowspan="2" valign="top">'+
                          '<table cellspacing="0" cellpadding="0" border="0">'+
                          '<tr>'+
                            '<td id="et_font_[ID]" class="et_selected_tab"><a href="#" id="etc_font_[ID]">Font</a></td>'+
                            '<td class="et_no_tab">&nbsp;</td>'+
                            '<td id="et_colors_[ID]" class="et_unselected_tab"><a href="#" id="etc_colors_[ID]">Colors</a></td>'+
                            '<td class="et_no_tab">&nbsp;</td>'+
                            '<td id="et_effects_[ID]" class="et_unselected_tab"><a href="#" id="etc_effects_[ID]">Effects</a></td>'+
                            '<td class="et_no_tab">&nbsp;</td>'+
                            '<td id="et_shape_[ID]" class="et_unselected_tab"><a href="#" id="etc_shape_[ID]">Shape</a></td>'+
                            '<td class="et_no_tab">&nbsp;</td>'+
                            '<td id="et_rotate_[ID]" class="et_unselected_tab"><a href="#" id="etc_rotate_[ID]">Rotate</a></td>'+
                            '<td class="et_no_tab" width="40">&nbsp;</td>'+
                          '</tr>'+
                          '<tr>'+
                            '<td colspan="10" class="et_tab_pane" valign="top">'+
                              '<div id="ep_font_[ID]">'+
                                'font <select class="frontpanel" id="mp_[ID]_font"></select><br/>'+
                                'size <input name="size" type="text" size="1" maxlength="3" id="mp_[ID]_fs" class="front" value="12"/> '+
                                'Bold:<input name="size" type="checkbox" id="mp_[ID]_b"/> '+
                                'Italics:<input name="size" type="checkbox" id="mp_[ID]_i"/> '+
                              '</div>'+
                              '<div id="ep_colors_[ID]" style="display:none;">'+
                                'text color: <div align="absmiddle" id="ep_textcolor_[ID]" class="color_button" style="width:10px;display:inline;margin-right:2px;font-size:8px;height:10px;" onclick="pp.selectColor(this,4);"><img src="/images/sb/trans.gif" width="10" height="10" border="0"/></div> '+
                                'outline width:<input name="size" type="textbox" size="1" class="front" id="ep_stroke_width_[ID]"/> '+
                                'color: <div align="absmiddle" id="ep_stroke_color_[ID]" class="color_button" style="width:10px;display:inline;font-size:8px;height:10px;" onclick="pp.selectColor(this,6);"><img src="/images/sb/trans.gif" width="10" height="10" border="0"/></div><br/>'+
                                'gradient: <select class="frontpanel" style="margin-bottom:1px;margin-top:2px;" id="ep_gradienttype_[ID]"><option value="0">None</option><option value="1">Vertical</option><option value="2">Horizontal</option></select> '+
                                'color: <div id="ep_gradient_color_[ID]" class="color_button" style="width:10px;display:inline;font-size:8px;height:10px;" onclick="pp.selectColor(this,5);"><img src="/images/sb/trans.gif" width="10" height="10" border="0"/></div><br/>'+
                              '</div>'+
                              '<div id="ep_effects_[ID]" style="display:none;">'+
                                '<table cellspacing="0" cellpadding="0" border="0"><tr><td colspan="2">'+
                                'effect type: <select class="frontpanel" id="ep_effecttype_[ID]"><option value="0">None</option><option value="1">Shadow</option><option value="2">Glow</option></select>'+
                                '</td><td valign="top" rowspan="2">'+
                                '<div id="shadow_effects_[ID]" style="display:none;margin-left:4px;"> '+
                                '<table><tr><td valign="center">offset:</td><td valign="top"><div id="mp_[ID]_offset" style="background-image: url(/images/circle_without_line.gif);background-position:0px 0p;width:36px;height:36px;" align="absmiddle">'+
                                '<img id="mp_[ID]_offset_handle" src="/images/sizer.gif" style="cursor:pointer;position:relative;top:15px;left:15px;" border="0"/></div></td></tr></table>'+
                                '</div><div id="glow_effects_[ID]" style="display:none;margin-left:4px;margin-top:8px;"> '+
                                'glow strength:'+
                                '<div id="ep_g_str_[ID]_t" style="width:70px;background-color:#aaa;height:5px;">'+
                                '<div id="ep_g_str_[ID]_s" style="width:5px;height:10px;background-color:#f00;cursor:e-resize;"> </div>'+
                                '</div>'+
                                '</div>'+
                              '</td></tr><tr><td style="padding-top:2px;white-space:nowrap;">'+
                              'color:<div align="absmiddle" id="ep_effectcolor_[ID]" class="color_button" style="width:10px;display:inline;margin-right:2px;font-size:8px;height:10px;" onclick="pp.selectColor(this,7);"><img src="/images/sb/trans.gif" width="10" height="10" border="0"/></div>'+
                              ' blur:</td><td style="padding-top:2px;">'+
                              '<div align="absmiddle" id="ep_b_str_[ID]_t" style="width:70px;background-color:#aaa;height:5px;">'+
                              '<div id="ep_b_str_[ID]_s" style="width:5px;height:10px;background-color:#f00;cursor:e-resize;"> </div>'+
                              '</div></td>'+
                              '</tr></table>'+
                              '</div>'+
                              '<div id="ep_shape_[ID]" style="display:none;">'+
                              '<table cellspacing="0" cellpadding="0"><tr><td><div id="ep_shape_sel_[ID]" class="ac_combo" style="width:70px;" allow_move="false">Select Shape</div></td><td><img src="/images/text/dropdown.gif" allow_move="false" id="ep_shape_sel_down_[ID]" border="0" style="cursor:pointer;"/></td></tr></table>'+
                              '<table cellspacing="0" cellpadding="0"><tr><td>'+
                              '<div id="ep_s_x_[ID]">width: '+
                              '<div id="ep_x_str_[ID]_t" style="width:100px;background-color:#aaa;height:5px;">'+
                              '<div id="ep_x_str_[ID]_s" style="width:5px;height:10px;background-color:#f00;cursor:e-resize;"> </div>'+
                              '</div>'+
                              '</div>'+
                            '</td><td style="padding-left:4px;">'+
                              '<div id="ep_s_y_[ID]">height: '+
                              '<div id="ep_y_str_[ID]_t" style="width:100px;background-color:#aaa;height:5px;">'+
                              '<div id="ep_y_str_[ID]_s" style="width:5px;height:10px;background-color:#f00;cursor:e-resize;"> </div>'+
                              '</div>'+
                              '</div>'+
                              '</td></tr></table>'+
                              '</div>'+
                              '<div id="ep_rotate_[ID]" style="display:none;">'+
                              '<img src="/images/circle_with_line.gif" id="mp_[ID]_roi" border="0" style="margin-bottom:0px;" align="absmiddle"/> <input name="rotate" type="text" size="1" maxlength="3" style="margin-left:5px;margin-bottom:1px;" id="mp_[ID]_ro" class="front"/> degrees'+
                              '</div>'+
                             '</td>'+
                          '</tr>'+
                      '</table>'+
                    '</td>'+
                  '</tr>'+
                  '<tr>'+
                    '<td>'+
                      'top <input name="top" type="text" size="1" maxlength="3" id="mp_[ID]_t" class="front"/> left <input name="left" type="text" size="1" maxlength="3" id="mp_[ID]_l" class="front"/> trans <input name="transparency" type="text" size="1" maxlength="3" id="mp_[ID]_tr" class="front"/> %'+
                    '</td>'+
                  '</tr></table>'+
                '</td>'+
              '</tr>'+
            '</table>'+
            '</div>';

var back_html='<div style="border: 1px solid #303030;margin-top:2px;width:400px;z-index:3000;background-color:#282828;" id="mp_[ID]" stopdeselect="true"><table class="managepane">'+
                  '<tr>'+
                    '<td rowspan="3" class="inneroff" id="mp_[ID]_tn" align="center" valign="center">'+
                      '<img src="/images/smaple_hat.gif" id="mp_[ID]_img"/>'+
                    '</td>'+
                    '<td valign="top" colspan="2">'+
                      'height <input name="height" type="text" size="1" maxlength="3" style="margin-right:19px;" id="mp_[ID]_h" class="front"/> width <input name="width" type="text" size="1" maxlength="3" id="mp_[ID]_w" class="front" style="margin-right:19px;"/> Maintain Aspect Ratio:<input name="aspect" type="checkbox" checked="true" id="mp_[ID]_a"/>'+
                    '</td></tr><tr><td>'+
                      '<a id="b_[ID]_c" href="#" onclick="pp.startCrop(); return false;"><img src="/images/crop.gif"  alt="Start Crop Image" border="0" vspace="2" hspace="2" /></a><a id="b_[ID]_dc" href="#" onclick="pp.doCrop(); return false;" style="display:none;"><img src="/images/[PREFIX]commit.gif"  alt="Commit Crop" border="0" vspace="2" hspace="2"/></a><a id="b_[ID]_cc" href="#" onclick="pp.cancelCrop(); return false;" style="display:none;"><img src="/images/cancel.gif"  alt="Cancel Crop Image" border="0" vspace="2" hspace="2" /></a>'+
                      '<a id="b_[ID]_tbgrr" href="#" onclick="pp.transformBG(\'rotRight\'); return false;"><img src="/images/[PREFIX]rotate_right.gif"  alt="Rotate Right" border="0" vspace="2" hspace="2" /></a><a id="b_[ID]_tbgrl" href="#" onclick="pp.transformBG(\'rotLeft\'); return false;"><img src="/images/[PREFIX]rotate_left.gif"  vspace="2" hspace="2" alt="Rotate Left" border="0"/></a><a id="b_[ID]_tbgfv" href="#" onclick="pp.transformBG(\'flipVert\'); return false;"><img src="/images/[PREFIX]flip_vertical.gif"  vspace="2" hspace="2" alt="Flip Vertical" border="0"/></a><a id="b_[ID]_tbgfh" href="#" onclick="pp.transformBG(\'flipHoriz\'); return false;"><img src="/images/[PREFIX]flip_horizontal.gif"  alt="Flip Horizontal" border="0" vspace="2" hspace="2"/></a>'+
                    '</td><td rowspan="2"><a href="#" onclick="pp.showSettings(); return false;" border="0"><img src="images/item_effects.gif" alt="effects" border="0"></a></td></tr><tr><td>'+
                      '<input id="b_[ID]_cb" type="checkbox" checked="true"/> Crop objects to background image'+
                    '</td>'+
                  '</tr>'+
                '</table>'+
              '</div>';

var bubble_html='<table id="sb_[ID]" border="0" cellpadding="0" cellspacing="0"  style="display:none;width:40px;height:60px;">'+
                  '<tr> '+
                    '<td align="right" valign="bottom"><img src="/images/sb/tl_m.png" width="5" height="5"></td>'+
                    '<td align="left" valign="bottom"><img src="/images/sb/tl_r.png" width="6" height="6"></td>'+
                    '<td bgcolor="#FFFFFF" style="border-top: 2px solid #000000"><img id="sbt_[ID]" src="/images/sb/trans.gif" width="2" height="2"/></td>'+
                    '<td align="right" valign="bottom"><img src="/images/sb/tr_t.png" width="6" height="6"></td>'+
                    '<td align="left" valign="bottom"><img src="/images/sb/tr_m.png" width="5" height="5"></td>'+
                  '</tr>'+
                  '<tr> '+
                    '<td align="right" valign="top"><img src="/images/sb/tl_b.png" width="6" height="6"></td>'+
                    '<td colspan="3" rowspan="3" bgcolor="#FFFFFF" id="[ID]_editor" align="center" valign="center"></td>'+
                    '<td align="left" valign="top"><img src="/images/sb/tr_b.png" width="6" height="6"></td>'+
                  '</tr>'+
                  '<tr> '+
                    '<td style="border-left: 2px solid #000000" bgcolor="#FFFFFF"><img id="sbl_[ID]" src="/images/sb/trans.gif" width="2" height="2"/></td>'+
                    '<td style="border-right: 2px solid #000000" bgcolor="#FFFFFF"><img id="sbr_[ID]" src="/images/sb/trans.gif" width="2" height="2"/></td>'+
                  '</tr>'+
                  '<tr> '+
                    '<td align="right" valign="bottom"><img src="/images/sb/bl_t.png" width="6" height="6"></td>'+
                    '<td align="left" valign="bottom"><img src="/images/sb/br_t.png" width="6" height="6"></td>'+
                  '</tr>'+
                  '<tr> '+
                    '<td align="right" valign="top"><img src="/images/sb/bl_m.png" width="5" height="5"></td>'+
                    '<td align="left" valign="top"><img src="/images/sb/bl_r.png" width="6" height="6"></td>'+
                    '<td style="border-bottom: 2px solid #000000" bgcolor="#FFFFFF"><img id="sbb_[ID]" src="/images/sb/trans.gif" width="2" height="2"/></td>'+
                    '<td align="right" valign="top"><img src="/images/sb/br_l.png" width="6" height="6"></td>'+
                    '<td align="left" valign="top"><img src="/images/sb/br_m.png" width="5" height="5"></td>'+
                  '</tr>'+
                '</table>';

var bubble_html_ie='<table id="sb_[ID]" border="0" cellpadding="0" cellspacing="0"  style="display:none;width:40px;height:60px;">'+
                     '<tr> '+
                       '<td align="right" valign="bottom"><span style="font-size:1px;width:5px;height:5px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/tl_m.png\', sizingMethod=\'scale\');"/></td>'+
                       '<td align="left" valign="bottom"><span style="font-size:1px;width:6px;height:6px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/tl_r.png\', sizingMethod=\'scale\');"/></td>'+
                       '<td bgcolor="#FFFFFF" style="border-top: 2px solid #000000"><img id="sbt_[ID]" src="/images/sb/trans.gif" width="2" height="2"/></td>'+
                       '<td align="right" valign="bottom"><span style="font-size:1px;width:6px;height:6px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/tr_t.png\', sizingMethod=\'scale\');"/></td>'+
                       '<td align="left" valign="bottom"><span style="font-size:1px;width:5px;height:5px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/tr_m.png\', sizingMethod=\'scale\');"/></td>'+
                     '</tr>'+
                     '<tr> '+
                       '<td align="right" valign="top"><span style="font-size:1px;width:6px;height:6px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/tl_b.png\', sizingMethod=\'scale\');"/></td>'+
                       '<td colspan="3" rowspan="3" bgcolor="#FFFFFF" id="[ID]_editor" align="center" valign="center"></td>'+
                       '<td align="left" valign="top"><span style="font-size:1px;width:6px;height:6px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/tr_b.png\', sizingMethod=\'scale\');"/></td>'+
                     '</tr>'+
                     '<tr> '+
                       '<td style="border-left: 2px solid #000000" bgcolor="#FFFFFF"><img id="sbl_[ID]" src="/images/sb/trans.gif" width="2" height="2"/></td>'+
                       '<td style="border-right: 2px solid #000000" bgcolor="#FFFFFF"><img id="sbr_[ID]" src="/images/sb/trans.gif" width="2" height="2"/></td>'+
                     '</tr>'+
                     '<tr> '+
                       '<td align="right" valign="bottom"><span style="font-size:1px;width:6px;height:6px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/bl_t.png\', sizingMethod=\'scale\');"/></td>'+
                       '<td align="left" valign="bottom"><span style="font-size:1px;width:6px;height:6px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/br_t.png\', sizingMethod=\'scale\');"/></td>'+
                     '</tr>'+
                     '<tr> '+
                       '<td align="right" valign="top"><span style="font-size:1px;width:5px;height:5px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/bl_m.png\', sizingMethod=\'scale\');"/></td>'+
                       '<td align="left" valign="top"><span style="font-size:1px;width:6px;height:6px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/bl_r.png\', sizingMethod=\'scale\');"/></td>'+
                       '<td style="border-bottom: 2px solid #000000" bgcolor="#FFFFFF"><img id="sbb_[ID]" src="/images/sb/trans.gif" width="2" height="2"/></td>'+
                       '<td align="right" valign="top"><span style="font-size:1px;width:6px;height:6px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/br_l.png\', sizingMethod=\'scale\');"/></td>'+
                       '<td align="left" valign="top"><span style="font-size:1px;width:5px;height:5px;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/sb/br_m.png\', sizingMethod=\'scale\');"/>></td>'+
                     '</tr>'+
                   '</table>';

var box_html='<table id="sb_[ID]" border="2" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: 2px solid #000000;display:none;width:40px;height:40px;">'+
               '<tr>'+
                 '<td id="[ID]_editor" align="center" valign="center"></td>'+
               '</tr>'+
             '</table>';

var text_html='<table id="sb_[ID]" border="0" cellpadding="0" cellspacing="0"  style="display:none;width:40px;height:40px;">'+
                '<tr>'+
                  '<td id="[ID]_editor" align="center" valign="center" style="padding:20px;"></td>'+
                '</tr>'+
              '</table>';

// Type navigateur ??
var types={0:type_0,1:type_1,2:type_2,3:type_0};

var useAlphaHack=false;
if((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<7.0)&&(BrowserDetect.version>=5.5)){useAlphaHack=true}
var useNLHack=false;
if((BrowserDetect.browser=="Safari")||(BrowserDetect.browser=="Firefox")){useNLHack=true}
var useRelHack=false;
if(BrowserDetect.browser=="Explorer"){useRelHack=true}

var hosting_domain="hosted.mimilook.com";
var pik_domain="www.mimilook.com";

// Fonctions du Menu dynamique Element Effects (Apply setting, Color mode, Effects...)
var Pikout=Class.create({CLASSDEF:{name:'Pikout'},
  initialize:function(canvas,sizer,debug,is_default,pdom,hdom,cur_bling_tab,cur_bling_tab_id){
    //log("class Pikout");
    //log("initialize PP");
    hosting_domain=hdom;
    pik_domain=pdom;
    this.dropables={};
    this.bling={};
    this.canvas=canvas;
    this.idCount=0;
    this.nextz=100;
    this.sizer=sizer;
    this.cur_bling_tab=cur_bling_tab;
    this.cur_bling_tab_id=cur_bling_tab_id;
    this.selected=null;
    this.debug=debug;
    this.fps=10;
    this.sortable={};
    this.bgEffectProperties={};
    this.textSizers={};
    this.textSizers["TR"]=$("ts_tr");
    this.textSizers["TL"]=$("ts_tl");
    this.textSizers["BR"]=$("ts_br");
    this.textSizers["BL"]=$("ts_bl");
    var pos=Position.cumulativeOffset(this.canvas);
    this.canvas_x=pos[0];
    this.canvas_y=pos[1];
    //log("canvas_x "+pos[0]);
    //log("canvas_y "+pos[1]);
    var _this=this;
    this.canvas.onclick=function(event){_this.canvas_click(event)};
    document.onkeyup=function(event){_this.keyup(event)};
    this.background_loaded=false;
    this.sortEventStart=this.sortStarted.bindAsEventListener(this);
    this.sortEventMove=this.sortMoving.bindAsEventListener(this);
    this.sortEventEnd=this.sortEnded.bindAsEventListener(this);
    this.cropBling=null;
    var re=new RegExp("\\[PREFIX\\]","g");
    if(is_default){
      types[0]=types[0].replace(re,"");
      back_html=back_html.replace(re,"");
      types[3]=types[3].replace(re,"")
    }else{
      types[0]=types[0].replace(re,"g_");
      back_html=back_html.replace(re,"g_");
      types[3]=types[3].replace(re,"g_")
    }
    this.optionsDialog=$("options_dialog");
    var d1=new Draggable("options_dialog",{revert:false,
      starteffect:function(element){},
      endeffect:function(element){},
      change:function(dragable){}}
    );
    this.blingOptionsDialog=$("bling_options_dialog");
    var d1=new Draggable("bling_options_dialog",{revert:false,
      starteffect:function(element){},
      endeffect:function(element){},
      change:function(dragable){}}
    );
    var odhe=new Effect.Opacity('od_section1_body',{to:0.0});
    odhe=new Effect.Opacity('od_section2_body',{to:0.0});
    odhe=new Effect.Opacity('od_section3_body',{to:0.0});
    odhe=new Effect.Opacity('od_section4_body',{to:0.0});
    odhe=new Effect.Opacity('e_odb_section1_body',{to:0.0});
    odhe=new Effect.Opacity('e_odb_section2_body',{to:0.0});
    odhe=new Effect.Opacity('e_odb_section3_body',{to:0.0});
    odhe=new Effect.Opacity('e_odb_section4_body',{to:0.0});
    this.sliders={};
    for(var i=0;i<effect_opts.length;i++){
      var effect=effect_opts[i];
      var code=effect["code"];
      var func=eval("_this.buildBGFunc('"+code+"');");
      if(effect["values"]!=null){
        this.sliders[effect["code"]]=new Control.Slider('od_'+code+'_s','od_'+code+'_t',{range:effect["range"],values:effect["values"],sliderValue:effect["defaultval"],onChange:func})
      }else{
        this.sliders[effect["code"]]=new Control.Slider('od_'+code+'_s','od_'+code+'_t',{range:effect["range"],sliderValue:effect["defaultval"],onChange:func})
      }
      code=null
    }
    this.bsliders={};
    for(var i=0;i<effect_opts.length;i++){
      var effect=effect_opts[i];
      if(effect["excludebling"]!=true){
        var code=effect["code"];
        var func=eval("_this.buildBlingFunc('"+code+"');");
        if(effect["values"]!=null){
          this.bsliders[effect["code"]]=new Control.Slider('e_odb_'+code+'_s','e_odb_'+code+'_t',{range:effect["range"],values:effect["values"],sliderValue:effect["defaultval"],onChange:func})
        }else{
          this.bsliders[effect["code"]]=new Control.Slider('e_odb_'+code+'_s','e_odb_'+code+'_t',{range:effect["range"],sliderValue:effect["defaultval"],onChange:func})
        }
        code=null
      }
    }
  },
  
  buildBGFunc:function(code){
    return function(v){
      pp.setBackgroundEffectProperty("e_"+code+"_a",v);
      pp.changeConditionally("e_od_"+code+"_c")
    }
  },
  
  buildBlingFunc:function(code){
    return function(v){
      pp.setBlingEffectProperty("e_"+code+"_a",v);
      pp.changeBlingConditionally("e_odb_"+code+"_c")
    }
  },
  
  selectBlingTypeTab:function(new_tab,new_tab_id){
    if(new_tab==this.cur_bling_tab){return}
    $(this.cur_bling_tab+"_tab_on").style.display='none';
    $(this.cur_bling_tab+"_tab_off").style.display='';
    $("blingdisplay_"+this.cur_bling_tab).style.display='none';
    $(new_tab+"_tab_on").style.display='';
    $(new_tab+"_tab_off").style.display='none';
    var newDis=$("blingdisplay_"+new_tab);
    newDis.style.display='';
    this.cur_bling_tab=new_tab;
    this.cur_bling_tab_id=new_tab_id;
    if(newDis.firstChild==null){this.update_bling_category(true,true)}
    if(new_tab_id==0){
      $("view_type_options").style.display='';
      if($("view_by_category").checked){
        this.showByCat()
      }else{
        this.showByDate()
      }
    }else{
      $("view_type_options").style.display='none';
      $("blingbddisplay").style.display='none'
    }
  },
    
  showSettings:function(){
    if(this.optionsDialog.style.display=='none'){
      if($('od_section1_body').style.display!='none'){
        Effect.Appear("od_section1_body",{from:0.0,to:0.9})
      }
      if($('od_section2_body').style.display!='none'){
        Effect.Appear("od_section2_body",{from:0.0,to:0.9})
      }
      if($('od_section3_body').style.display!='none'){
        Effect.Appear("od_section3_body",{from:0.0,to:0.9})
      }
      if($('od_section4_body').style.display!='none'){
        Effect.Appear("od_section4_body",{from:0.0,to:0.9})
      }
      this.optionsDialog.style.display=''
    }
  },
  
  toggleOptionsDisplay:function(ah,num){
    var id="od_section"+num+"_body";
    var el=$(id);
    if(el.style.display=='none'){
      Effect.BlindDown(id);
      ah.firstChild.src="/images/settings_colapse.gif"
    }else{
      Effect.BlindUp(id);
      ah.firstChild.src="/images/settings_expand.gif"
    }
  },
    
  closeOptionsDisplay:function(){
    if(this.optionsDialog!=null){
      if($('od_section1_body').style.display!='none'){
        var e1=new Effect.Opacity("od_section1_body",{to:0.0})
      }
      if($('od_section2_body').style.display!='none'){
        var e2=new Effect.Opacity("od_section2_body",{to:0.0})
      }
      if($('od_section3_body').style.display!='none'){
        var e3=new Effect.Opacity("od_section3_body",{to:0.0})
      }
      if($('od_section4_body').style.display!='none'){
        var e4=new Effect.Opacity("od_section4_body",{to:0.0})
      }
      this.optionsDialog.style.display='none'
    }
  },
  
  changeConditionally:function(chkbox){
    if(this.settingOD){return}
    if(!$(chkbox).checked){
      $(chkbox).checked=true;
      this.setBackgroundEffectProperty(chkbox,"1")
    }
    this.transformBG('',true)
  },
    
  bgOptClicked:function(chkbox,slider_prop,slider_value){
    if(chkbox.checked){
      this.setBackgroundEffectProperty(chkbox.id,"1");
      if(this.bgEffectProperties[slider_prop]==null){
        this.setBackgroundEffectProperty(slider_prop,slider_value)
      }
    }else{
      this.setBackgroundEffectProperty(chkbox.id,null)
    }
    this.transformBG('',true)
  },
  
  setColorMode:function(mode){
    var curMode=this.getBackgroundEffectProperty("e_color_mode",1);
    if(curMode!=mode){
      this.setBackgroundEffectProperty("e_color_mode",mode);
      this.transformBG('',true);
      this.showColorModeOptions(mode)
    }
  },
  
  showColorModeOptions:function(mode){
    if(mode!=1){
      $('color_mode_opt_1').style.display='none';
      $('color_mode_opt_2').style.display='none'
    }else{
      $('color_mode_opt_1').style.display='';
      $('color_mode_opt_2').style.display=''
    }
    if(mode!=4){
      $('color_mode_opt_3').style.display=''
    }else{
      $('color_mode_opt_3').style.display='none'
    }
  },
  
  bgOptApplyClicked:function(el,opt){
    if(el.checked){
      this.setBackgroundEffectProperty(opt,"1")
    }else{
      this.setBackgroundEffectProperty(opt,"0")
    }
  },
    
  blingOptClicked:function(chkbox,slider_prop,slider_value){
    if(chkbox.checked){
      this.setBlingEffectProperty(chkbox.id,"1");
      if(this.bgEffectProperties[slider_prop]==null){
        this.setBlingEffectProperty(slider_prop,slider_value)
      }
    }else{
      this.setBlingEffectProperty(chkbox.id,null)
    }
    this.updateCurrentBling()
  },
  
  showBlingColorModeOptions:function(mode){
    if(mode!=1){
      $('bcolor_mode_opt_1').style.display='none';
      $('bcolor_mode_opt_2').style.display='none'
    }else{
      $('bcolor_mode_opt_1').style.display='';
      $('bcolor_mode_opt_2').style.display=''
    }
    if(mode!=4){
      $('bcolor_mode_opt_3').style.display=''
    }else{
      $('bcolor_mode_opt_3').style.display='none'
    }
  },
  
  setBlingColorMode:function(mode){
    var curMode=this.getBlingEffectProperty("e_color_mode",1);
    if(curMode!=mode){
      this.setBlingEffectProperty("e_color_mode",mode);
      this.showBlingColorModeOptions(parseInt(mode));
      this.updateCurrentBling()
    }
  },
    
  showBlingSettings:function(){
    if(this.blingOptionsDialog.style.display=='none'){
      if($('e_odb_section1_body').style.display!='none'){
        Effect.Appear("e_odb_section1_body",{from:0.0,to:0.9})
      }
      if($('e_odb_section2_body').style.display!='none'){
        Effect.Appear("e_odb_section2_body",{from:0.0,to:0.9})
      }
      if($('e_odb_section3_body').style.display!='none'){
        Effect.Appear("e_odb_section3_body",{from:0.0,to:0.9})
      }
      if($('e_odb_section4_body').style.display!='none'){
        Effect.Appear("e_odb_section4_body",{from:0.0,to:0.9})
      }
      this.blingOptionsDialog.style.display='';
      if(this.positioned_bling_dialog!=true){
        this.positioned_bling_dialog=true
      }
    }
  },
  
  toggleBlingOptionsDisplay:function(ah,num){
    var id="e_odb_section"+num+"_body";
    var el=$(id);
    if(el.style.display=='none'){
      Effect.BlindDown(id);
      ah.firstChild.src="/images/settings_colapse.gif"
    }else{
      Effect.BlindUp(id);
      ah.firstChild.src="/images/settings_expand.gif"
    }
  },
  
  closeBlingOptionsDisplay:function(){
    log("closeBlingOptionsDisplay");
    if(this.blingOptionsDialog!=null){
      if($('e_odb_section1_body').style.display!='none'){
        var e1=new Effect.Opacity("e_odb_section1_body",{to:0.0})
      }
      if($('e_odb_section2_body').style.display!='none'){
        var e2=new Effect.Opacity("e_odb_section2_body",{to:0.0})
      }
      if($('e_odb_section3_body').style.display!='none'){
        var e3=new Effect.Opacity("e_odb_section3_body",{to:0.0})
      }
      if($('e_odb_section4_body').style.display!='none'){
        var e4=new Effect.Opacity("e_odb_section4_body",{to:0.0})
      }
      this.blingOptionsDialog.style.display='none'
    }
  },
  
  blingEffectSetting:function(mode){
    var curMode=this.getBlingEffectProperty("e_apply_bling_mode",0);
    if(curMode!=mode){
      this.setBlingEffectProperty("e_apply_bling_mode",mode);
      this.updateCurrentBling()
    }
  },
  
  changeBlingConditionally:function(chkbox){
    if(this.settingOD){return}
    if(!$(chkbox).checked){
      $(chkbox).checked=true;
      this.setBlingEffectProperty(chkbox,"1")
    }
    if($(chkbox).checked){
      this.updateCurrentBling()
    }
  },
    
  serializeBGEffects:function(queryComponents,prefix){
    if(prefix==null){prefix="bling"}
    if(queryComponents==null){queryComponents=new Array()}
    if(prefix==null){prefix="bling"}
    for(k in this.bgEffectProperties){
      if(this.bgEffectProperties[k]!=null){
        queryComponents.push(encodeURIComponent(prefix+"[bg]["+k+"]")+"="+encodeURIComponent(this.bgEffectProperties[k]))
      }
    }
    return queryComponents.join('&')
  },
  
  setBackgroundEffectProperty:function(name,value){
    if(this.settingOD){return}
    //log("setting bg effect "+name+" = "+value);
    this.bgEffectProperties[name]=value
  },
  
  getBackgroundEffectProperty:function(name,defaultValue){
    if(this.bgEffectProperties[name]==null){return defaultValue}
    return this.bgEffectProperties[name]
  },
    
  getBlingEffectProperty:function(name,defaultValue){
    if(this.selected==null){return defaultValue}
    return this.selected.getBlingEffectProperty(name,defaultValue)
  },
  
  setBlingEffectProperty:function(name,value){
    if(this.settingOD){return}
    if(this.selected==null){return}
    //log("setting bling effect "+name+" = "+value);
    this.selected.setBlingEffectProperty(name,value)
  },
  
  updateCurrentBling:function(){
    if(this.selected==null){return}
    this.selected.updateBling()
  },
  
  setBGOptChkBox:function(name,value){
    if(value=="1"){$(name).checked=true}else{$(name).checked=false}},
  
  setBlingEffectsDialog:function(){
    log("setBlingEffectsDialog");
    this.settingOD=true;
    for(var i=0;i<effect_opts.length;i++){
      var effect=effect_opts[i];
      if(effect["excludebling"]!=true){
        this.bsliders[effect["code"]].setValue(this.getBlingEffectProperty("e_"+effect["code"]+"_a",effect["defaultval"]));
        this.setBGOptChkBox("e_odb_"+effect["code"]+"_c",this.getBlingEffectProperty("e_odb_"+effect["code"]+"_c",null))
      }
    }
    var curMode=this.getBlingEffectProperty("e_color_mode",1);
    $('e_odb_colormode_'+curMode).checked=true;
    this.showBlingColorModeOptions(curMode);
    curMode=parseInt(this.getBlingEffectProperty("e_apply_bling_mode","0"));
    if(curMode==0){
      $('e_odb_apply_bling_def').checked=true
    }else{
      $('e_odb_apply_bling_or').checked=true
    }
    this.settingOD=false
  },
  
  setBGEffectsDialog:function(){
    this.settingOD=true;
    for(var i=0;i<effect_opts.length;i++){
      var effect=effect_opts[i];
      this.sliders[effect["code"]].setValue(this.getBackgroundEffectProperty("e_"+effect["code"]+"_a",effect["defaultval"]));
      this.setBGOptChkBox("e_od_"+effect["code"]+"_c",this.getBackgroundEffectProperty("e_od_"+effect["code"]+"_c",null))
    }
    var curMode=this.getBackgroundEffectProperty("e_color_mode",1);
    $('od_colormode_'+curMode).checked=true;
    this.showColorModeOptions(curMode);
    if(this.getBackgroundEffectProperty("e_apply_bling","1")=="1"){
      $('e_od_apply_bling').checked=true
    }else{
      $('e_od_apply_bling').checked=false
    }
    if(this.getBackgroundEffectProperty("e_apply_sb",null)=="1"){
      $('e_od_apply_sb').checked=true
    }else{
      $('e_od_apply_sb').checked=false
    }
    this.settingOD=false
  },
  
  pageLoadedCallback:function(){this.recalibrateCanvas()},
  
  recalibrateCanvas:function(){
    var _this=this;
    window.setTimeout(function(){
      var pos=Position.cumulativeOffset(_this.canvas);
      _this.canvas_x=pos[0];
      _this.canvas_y=pos[1];
      //alert("recalibrateCanvas");
      _this.repositionManagePanel();
      for(key in _this.bling){
        if(_this.bling[key]!=null){
          _this.bling[key].setSize()
        }
      }
    },100)
  },
  
  initManageList:function(manage_list){
    this.manage_list=manage_list;
    Event.observe(this.manage_list,"mousedown",this.sortEventStart);
    var _this=this;
    this.fps_slider=new Control.Slider('fps_s','fps_t',{range:$R(1,10),sliderValue:10,onChange:function(v){_this.fps=v}})
  },
  
  initBackgroundContainer:function(container){this.backgroundContainer=container},
  
  nextId:function(){this.idCount++;return this.idCount-1},
  
  nextZ:function(){this.nextz+=2;return this.nextz-2},
  
  registerDropable:function(dropable){this.dropables[dropable.id]=dropable},
  
  drop:function(el){
    //log("start drop");
    if(this.cropBling!=null){
      this.cropBling.moveFinished();
      return
    }
    if(this.bling[el.id]!=null){
      if(this.selected!=null){
        this.selected.moveFinished()
      }
      return
    }
    var dropped=this.dropables[el.id];
    //log("got dropable:"+el.id);
    var newBling=dropped.copy();
    this.bling[newBling.id]=newBling;
    this.checkIfAnimated();
    newBling.select()
  },
  
  selectBling:function(newBling){
    log ("selectBling");
    if(this.selected!=null){this.selected.deselect()}
    if(newBling==null){this.closeBlingOptionsDisplay()}
    this.selected=newBling
  },
  
  insertManagePane:function(type,bling){
    log("insertManagePane");
    var id=this.nextId();
    //log("manage_list id:" + id);
    var re=new RegExp("\\[ID\\]","g");
    //log("manage_list re:" + re);
    var html=types[type].replace(re,id);
    //log("manage_list:" + this.manage_list.id);
    var t1=new Insertion.Top(this.manage_list.id,html);
    //log("inserted");
    var panel=$("mp_"+id);
    Sortable.destroy(this.manage_list);
    this.sortable[panel.id]=bling;
    var _this=this;
// ajout FL
// suppression du déplacement vertical du bind panel
//    Sortable.create(this.manage_list.id,{tag:"DIV",overlap:"vertical",dropOnEmpty:false,constraint:"vertical",onChange:function(el){_this.sortChanged(el)}});
// ajout FL
    this.hideAbsElementsOnPanels();
    this.fixManagePaneIEBug();
    //log("binding panel:" + id);
    bling.bindPanel(panel,id);
    //log("binding panel finished");
    Effect.BlindDown(panel.id,{duration:1.0,
      afterFinish:function(el){panel.style.zoom=1;_this.recalibrateCanvas()}});
    Event.observe(panel,"mousedown",this.sortEventStart)
  },
  
  sortChanged:function(el){
    //log("sort changed:"+el.id);
    var movedBling=this.sortable[el.id];
    var movedWith=null;
    var otherBling=null;
    if(el.previousSibling!=null){
      //log("sortChanged:" + el.previousSibling);
      otherBling=this.sortable[el.previousSibling.id];
      if(otherBling.z<movedBling.z){log("DOWN");movedWith=otherBling}
    }
    if(movedWith==null){
      if(el.nextSibling!=null){
        otherBling=this.sortable[el.nextSibling.id];
        if(otherBling.z>movedBling.z){log("UP");movedWith=otherBling}
      }
    }
    if(movedWith!=null){movedBling.swapZOrder(movedWith)}
  },
  
  delBling:function(bling){
    this.bling[bling.id]=null;
    this.sortable[bling.id]=null;
    this.checkIfAnimated();
    this.recalibrateCanvas()
  },
  
  from_x:function(x){return x-this.canvas_x},
  
  from_y:function(y){return y-this.canvas_y},
  
  to_x:function(x){return x+this.canvas_x},
  
  to_y:function(y){return y+this.canvas_y},
  
  update_bling_category:function(ignore_sub,ignore_cat){
    var el=$("bling_category_"+this.cur_bling_tab);
    var id="";
    if(!ignore_cat){
      id=el.options[el.selectedIndex].value
    }else{
      id="-1"
    }
    var sEl=$("bling_subcategory_"+this.cur_bling_tab);
    var sid="";
    if((sEl!=null)&&(ignore_sub!=true)){sid=sEl.options[sEl.selectedIndex].value}
    var _this=this;
    startAsyncAction();
    // ajout fl
    //var t1=new Ajax.Updater('blingdisplay_'+this.cur_bling_tab,'/home/getblings?page=1&bcid='+id+"&bscid="+sid+"&bt="+this.cur_bling_tab_id,{asynchronous:true,evalScripts:true,onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(){finishAsyncAction();_this.recalibrateCanvas()}})
    var t1=new Ajax.Updater('blingdisplay_'+this.cur_bling_tab,'getblings.php?page=1&cat='+id,{asynchronous:true,evalScripts:true,onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(){finishAsyncAction();_this.recalibrateCanvas()}})
    // fin ajout fl
  },
  
  canvas_click:function(event){
    if(this.cropBling!=null){return}
    if(this.selected!=null){this.selected.deselect()}
    this.selected=null
  },
  
  keyup:function(event){
    if(this.selected!=null){
      if(event==null){event=window.event}
      if(event.keyCode==Event.KEY_DELETE){
        var el=Event.element(event);
        var allowDelete=true;
        while(el!=null){
          if(el.tagName=="INPUT"||el.tagName=="SELECT"||el.tagName=="TEXTAREA"){return}
            else if(el.getAttribute("allow-delete")=="true"){return}
            el=el.parentElement}this.selected.del()
      }
    }},
  
  readyBackground:function(src,height,width){
    this.ready_background=src;
    this.ready_background_height=height;
    this.ready_background_width=width;
    //log("readying background")
    },
  
  updateBackground:function(){
    //log("updateBackground");
    var _this=this;
    if(this.ready_background_width!=null){
      this.canvas.width=this.ready_background_width;
      this.ready_background_width=null
    }else{
      this.canvas.removeAttribute("width")
    }
    if(this.ready_background_width!=null){
      this.canvas.height=this.ready_background_height;
      this.ready_background_height=null
    }else{
      this.canvas.removeAttribute("height")
    }
    startAsyncAction();
    this.canvas.onload=function(){_this.loadBackground()};
    if(this.ready_background==null){
      this.canvas.src='/home/get_back_image?ts='+new Date().getTime()
    }else{
      this.canvas.src=this.ready_background+'?ts='+new Date().getTime();
      this.ready_background=null}log("updateBackground done")},
  
  loadBackground:function(){
    //log("loadBackground");
    if(!this.background_loaded){
      var id=this.nextId();
      var re=new RegExp("\\[ID\\]","g");
      var html=back_html.replace(re,id);
      Element.replace(this.backgroundContainer,html);
      this.backgroundContainer=$("mp_"+id);
      this.bg_width_input=$("mp_"+id+"_w");
      this.bg_height_input=$("mp_"+id+"_h");
      this.bd_crop_link=$("b_"+id+"_c");
      this.bd_crop_cancel_link=$("b_"+id+"_cc");
      this.bd_crop_do_link=$("b_"+id+"_dc");
      this.bd_crop_bling=$("b_"+id+"_cb");
      var _this=this;
      this.bg_width_input.onkeyup=function(){_this.bgWidthChange()};
      this.bg_height_input.onkeyup=function(){_this.bgHeightChange()};
      this.background_loaded=true;
      this.bg_tn=$("mp_"+id+"_img");
      this.bg_aspect=$("mp_"+id+"_a");
      this.bg_aspect.onclick=function(){_this.bg_ratio=_this.canvas.width/_this.canvas.height}
    }
    this.backgroundContainer.style.display='';
    this.recalibrateCanvas();
    if((this.canvas.width>iconWidth)||(this.canvas.height>iconWidth)){
      var ratio=this.canvas.width/this.canvas.height;
      if(this.canvas.width>this.canvas.height){
        this.bg_tn.width=iconWidth;
        this.bg_tn.height=iconWidth/ratio
      }else{
        this.bg_tn.height=iconWidth;
        this.bg_tn.width=iconWidth*ratio
      }
    }
    this.bg_tn.src=this.canvas.src;
    this.canvas.width=this.canvas.width;
    this.bg_original_width=this.canvas.width;
    this.canvas.height=this.canvas.height;
    this.bg_original_height=this.canvas.height;
    this.bg_width_input.value=this.canvas.width;
    this.bg_height_input.value=this.canvas.height;
    this.bg_ratio=this.canvas.width/this.canvas.height;
    if(this.backgoundLoadedCallback!=null){
      //log("calling backgoundLoadedCallback");
      this.backgoundLoadedCallback();
      //log("calling backgoundLoadedCallback DONE");
      this.backgoundLoadedCallback=null
    }
    finishAsyncAction();
    //log("loadBackground DONE")
    },
  
  bgWidthChange:function(){
    if(this.bg_width_input.value==""){
      this.bg_width_input.value=this.bg_original_width
    }
    if(this.bg_aspect.checked){
      var height=parseFloat(this.bg_width_input.value)/this.bg_ratio;
      this.canvas.height=height;
      this.bg_height_input.value=Height
    }
    this.canvas.width=parseFloat(this.bg_width_input.value);
    this.recalibrateCanvas()},
  
  bgHeightChange:function(){
    if(this.bg_height_input.value==""){
      this.bg_height_input.value=this.bg_original_height
    }
    if(this.bg_aspect.checked){
      var width=parseFloat(this.bg_height_input.value)*this.bg_ratio;
      this.canvas.width=width;
      this.bg_width_input.value=width
    }
    this.canvas.height=parseFloat(this.bg_height_input.value);
    this.recalibrateCanvas()},
    
  hideBlings:function(includeBackground){
    //log("hiding bling");
    for(key in this.bling){
      if(this.bling[key]!=null){this.bling[key].hide()}
    }
    if(includeBackground){
      if(this.background_loaded){
        var t1=new Effect.Opacity(this.backgroundContainer,{duration:0.3,to:0.1});
        this.bg_width_input.disabled=true;
        this.bg_height_input.disabled=true;
        this.bg_aspect.disabled=true;
        this.bd_crop_link.style.display='none'
      }
      //log("Removing sorter");
      Sortable.destroy(this.manage_list)}},
      
    restoreBlings:function(includeBackground){
      for(key in this.bling){
      	if(this.bling[key]!=null){
      	  this.bling[key].restore()
      	}
      }
      if(includeBackground){
      	if(this.background_loaded){
      	  var t1=new Effect.Opacity(this.backgroundContainer,{duration:0.3,to:1.0});
      	  this.bg_width_input.disabled=false;
      	  this.bg_height_input.disabled=false;
      	  this.bg_aspect.disabled=false;
      	  this.bd_crop_link.style.display=''
      	}
      	var _this=this;
      	Sortable.create(this.manage_list.id,{tag:"DIV",overlap:"vertical",dropOnEmpty:false,constraint:"vertical",onChange:function(el){_this.sortChanged(el)}});
      	this.fixManagePaneIEBug()
      }},
      
    startCrop:function(){
      this.hideBlings();
      var cropDiv=document.createElement("div");
      var pos=Position.cumulativeOffset(this.canvas);
      cropDiv.style.left=(pos[0]+10)+"px";
      cropDiv.style.top=(pos[1]+10)+"px";
      cropDiv.style.width=(this.canvas.width-20)+"px";
      cropDiv.style.height=(this.canvas.height-20)+"px";
      cropDiv.style.position="absolute";
      document.body.appendChild(cropDiv);
      this.crop_top=pos[1];
      this.crop_left=pos[0];
      this.crop_width=this.canvas.width;
      this.crop_height=this.canvas.height;
      this.cropBling=new CropBling(cropDiv,this,{on_image:true,no_manage_pane:true},-1,-1);
      this.bd_crop_link.style.display="none";
      this.bd_crop_cancel_link.style.display="";
      this.bd_crop_do_link.style.display=""},
      
    doCrop:function(){
      var dims=this.cropBling.getDims();
      var t=dims[0];
      var l=dims[1];
      var h=dims[2];
      var w=dims[3];
      this.crop_delta_x=l;
      this.crop_delta_y=t;
      t=this.from_y(t);
      l=this.from_x(l);
      this.cropBling.del();
      this.cropBling=null;
      this.bd_crop_cancel_link.style.display="none";
      this.bd_crop_do_link.style.display="none";
      startAsyncAction();
      var t1=new Ajax.Request("/home/crop_back_image?x="+l+"&y="+t+"&w="+w+"&h="+h+"&bw="+this.crop_width+"&bh="+this.crop_height,{asynchronous:true,evalScripts:true,onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(){finishAsyncAction()}})},
      
    cancelCrop:function(){
      this.cropBling.del();
      this.cropBling=null;
      this.restoreBlings();
      this.bd_crop_link.style.display="";
      this.bd_crop_cancel_link.style.display="none";
      this.bd_crop_do_link.style.display="none"},
      
    backgroundCropped:function(){
      var _this=this;
      this.backgoundLoadedCallback=function(){y=_this.from_y(_this.crop_delta_y);x=_this.from_x(_this.crop_delta_x);for(key in _this.bling){if(_this.bling[key]!=null){_this.bling[key].translate(x,y)}}_this.restoreBlings();_this.bd_crop_link.style.display=""};
      this.updateBackground()},
      
    transformBG:function(trans,doDelay){
      var deg=0;
      var flip='';
      if(trans=='rotRight'){deg=90}
      else if(trans=='rotLeft'){deg=-90}
      else if(trans=='flipVert'){flip="V"}
      else if(trans=='flipHoriz'){flip="H"}
      startAsyncAction();
      if(doDelay==null){doDelay=false}
      var _this=this;
      if(this.bgTransDelay!=null){
      	window.clearTimeout(this.bgTransDelay);
      	this.bgTransDelay=null
      }
      if(doDelay){
      	this.bgTransDelay=window.setTimeout(function(){_this.transformBG(trans,false)},1000);
      	return
      }
      var t1=new Ajax.Request("/home/transform_back_image?deg="+deg+"&flip="+flip+"&h="+this.canvas.height+"&w="+this.canvas.width+"&"+this.serializeBGEffects(),{onlyLatestOfClass:"bgtransform",asynchronous:true,evalScripts:true,onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)}})},
      
    backgroundTransformed:function(){this.updateBackground()},
    
    serialize:function(queryComponents,prefix){
      log ("serialize bling");
      if(prefix==null){prefix="bling"}
      if(queryComponents==null){queryComponents=new Array()}
      /*
      queryComponents.push(encodeURIComponent(prefix+"[bg][h]")+"="+encodeURIComponent(this.bg_height_input.value));
      queryComponents.push(encodeURIComponent(prefix+"[bg][w]")+"="+encodeURIComponent(this.bg_width_input.value));
      if(this.bd_crop_bling.checked){
      	queryComponents.push(encodeURIComponent(prefix+"[bg][c]")+"="+encodeURIComponent("1"))
      }else{
        queryComponents.push(encodeURIComponent(prefix+"[bg][c]")+"="+encodeURIComponent("0"))
      }
      queryComponents.push(encodeURIComponent(prefix+"[bg][fps]")+"="+encodeURIComponent(this.fps));
      this.serializeBGEffects(queryComponents,prefix);
      */
      // il faut trier le tableau dans l'ordre des z croissant
      var elements = new Array();
      for(key in this.bling){
        if(this.bling[key]!=null){
          //log ("key----------------------" + key);
          //log ("id:" + this.bling[key].id);
          //log ("z :" + this.bling[key].z);
          var element = new Array();
          element.push(this.bling[key].z);
          element.push(this.bling[key].id);
          elements.push(element);
        }
      }
      // on trie le tableau
      elements.sort();
      //log ("------tri-------------");
      // on serialise
      for(var i=0;i<elements.length;i++){
        this.bling[elements[i][1]].serialize(queryComponents,prefix);
        //log ("id:" + this.bling[elements[i][1]].id);
        //log ("z :" + this.bling[elements[i][1]].z);
      }
      
/*      
      for(key in this.bling){
        if(this.bling[key]!=null){
          log ("z:" + this.bling[key].z);
          this.bling[key].serialize(queryComponents,prefix)
        }
      }*/
      return queryComponents.join('&')},

preview:function(){
    if(!this.background_loaded){alert("You must upload your image first (step 1)");return}
    if(this.blingCount()==0){alert("You must drag objects onto your image (step 2) before you can preview your image");return}
    startAsyncAction();
    var _this=this;
    popup("image_preview");
    var t1=new Ajax.Request("/home/update_image",
                            {asynchronous:true,
                            evalScripts:true,
                            parameters:this.serialize(),
                            onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},
                            onComplete:function(request){finishAsyncAction();_this.showPreviewImage()}})
  },
showPreviewImage:function(){
  $("preview_img").onload=function(){repositionPopup("image_preview")};
  $("preview_img").src=this.compiled_image_url+'?ts='+new Date().getTime()},
closePreview:function(){
  closePopup("image_preview");
  $("preview_img").onload=null;
  $("preview_img").src="/images/loading.gif"},

save:function(){
/*
  if(!this.background_loaded){
    alert("You must upload your image first (step 1)");
    return
  }
*/
  if(this.blingCount()==0){
    alert("You must drag objects onto your image before you can save it");
  return
  }
/*
  var isPubEl=$('is-public');
  var isPriv=false;
  if(!isPubEl.checked){isPriv=true}
*/
  /*
  if((!isPriv)||(isLoggedIn)){
    $('td_pd1').style.display='';
    $('td_pd2').style.display='';
    $('td_pd3').colSpan=5
  }else{
    $('td_pd1').style.display='none';
    $('td_pd2').style.display='none';
    $('td_pd3').colSpan=4
  }*/
/*
  for(key in this.bling){
    if(this.bling[key]!=null){
    log("------------------------------------------------");
    log("id :" + this.bling[key].managePane.id);
    var id = this.bling[key].managePane.id;
    log("order :" + document.getElementById(id + "_order").value);
    log("trans :" + document.getElementById(id + "_tr").value);
    log("img   :" + document.getElementById(id + "_img").src);
    log("top   :" + document.getElementById(id + "_t").value);
    log("left  :" + document.getElementById(id + "_l").value);
    log("height:" + document.getElementById(id + "_h").value);
    log("width :" + document.getElementById(id + "_w").value);
    }
  }
*/
  var pid = document.getElementById('pid').value;
  startAsyncAction();
  var _this=this;
  //popup("save_preview");
  //var t1=new Ajax.Request("/home/update_image?do_save=true&isprivate="+isPriv,
  var t1=new Ajax.Request("save.php?pid="+pid,
                          {asynchronous:true,
                          evalScripts:true,
                          parameters:this.serialize(),
                          onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},
                          onComplete:function(request){finishAsyncAction();_this.showSave(request)}})},
  
showSave:function(request){
  // on recupere url qui vient de save.php
  var url  = request.responseText;
  if (url.indexOf("ERROR")!=-1){
    alert("Error quota excedeed !!!");
  }else{
    //alert("Successfull !!!" + url);
    alert("Successfull !!!");
    document.location.href=url;
  }
},

closeSave:function(){
  closePopup("save_preview");
  $("save_img").onload=null;
  $("save_img").src="/images/loading.gif";
  $("save_code").value="";
  $('download-link').href="#"},
  
updatePhotoDetails:function(){
  startAsyncAction();
  var _this=this;
  var t1=new Ajax.Request("/home/update_image_details",{asynchronous:true,evalScripts:true,parameters:Form.serialize("photo_details"),onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(request){finishAsyncAction();closePopup("save_preview")}})},
  
blingCount:function(){
  var cnt=0;
  for(key in this.bling){
    if(this.bling[key]!=null){cnt++}
  }
  return cnt},
  
clear:function(removeBackground){
  for(key in this.bling){
    if(this.bling[key]!=null){
      this.bling[key].del()
    }
  }
  this.bling={};
  this.nextz=100;
  this.selected=null;
  this.sortable={};
  this.bling_to_add=new Array();
  if(removeBackground==true){
    this.canvas.removeAttribute("width");
    this.canvas.removeAttribute("height");
    if(this.background_loaded){
      this.backgroundContainer.style.display='none';
      this.background_loaded=false
    }
    this.canvas.onload=null;
    this.canvas.src="/images/sample-image.gif"
  }else{
    var _this=this;
    this.backgoundLoadedCallback=function(){_this.addBlingsAfterBGLoaded()}
  }
  this.checkIfAnimated()},
  
addBling:function(src,options,tn_width,tn_height){
  var newBling={};
  newBling["src"]=src;
  newBling["options"]=options;
  newBling["tn_width"]=tn_width;
  newBling["tn_height"]=tn_height;
  this.bling_to_add.push(newBling)},
  
addBlingsAfterBGLoaded:function(){
  for(var i=0;i<this.bling_to_add.length;i++){
    var options=this.bling_to_add[i]["options"];
    var src=this.bling_to_add[i]["src"];
    var iel=document.createElement("IMG");
    iel.src=src;
    iel.id="bling_ls_"+this.nextId();
    iel.style.display="none";
    iel.style.height=this.bling_to_add[i]["tn_height"]+"px";
    iel.style.width=this.bling_to_add[i]["tn_width"]+"px";
    if(useAlphaHack){
      iel.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')"
    }
    options["tn_image"]=iel;
    document.body.appendChild(iel);
    var srcBling=null;

  if((options["btype"]==0)||(options["btype"]==3)){
    srcBling=new ImgBling(iel,this,options,options["type"],options["btype"],1)
  }else if(options["btype"]==1){
    srcBling=new SpeechBling(iel,this,options,options["type"],options["btype"],1)
  }else if(options["btype"]==2){
  	srcBling=new TextBling(iel,this,options,options["type"],options["btype"],1)
  }
  if(options["z"]!=null){
    var the_z=parseInt(options["z"]);
    if(the_z>=this.nextz){
      this.nextz=the_z+1
    }
  }

  newBling=srcBling.copy(options);
  this.bling[newBling.id]=newBling}finishAsyncAction();
  this.bling_to_add=null;
  this.checkIfAnimated()},

setupBlingIcon:function(src,height,width,id,container_id){
  var html="";
  //log("setupBlingIcon");
  if(useAlphaHack){
    html='<img src="/images/sb/trans.gif" style="font-size:1px;width:'+width+'px;height:'+height+'px;display:inline-block;" id="'+id+'"/>';html+='<img src="'+src+'" height="'+height+'" width="'+width+'" id="tn_'+id+'" style="display:none;width:'+width+'px;height:'+height+'px;" onload="$(\''+id+'\').style.filter=\'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\\\''+src+'\\\', sizingMethod=\\\'scale\\\')\';"/>'
  }else{
    html='<img src="'+src+'" height="'+height+'" width="'+width+'" id="'+id+'"/>'
  }
  Element.update(container_id,html);
  //log("bling icon created")
  },

getDims:function(){
  var pos=Position.cumulativeOffset(this.canvas);
  return[pos[1],pos[0],this.canvas.height,this.canvas.width]
},

sortStarted:function(event){
  if(useRelHack){
    var el=Event.element(event);
    if(el!=null){
      if(el.tagName=="SELECT"){log("avoiding sortStarted");return}
      if(el.getAttribute("allow_move")=="false"){return}
      el=Event.findElement(event,"div");
      if(el!=null){if(el.className=="cbo_autocomplete"){return}}
    }
    this.fixManagePaneIEBug(true)}
    Event.observe(document,"mousemove",this.sortEventMove);
    Event.observe(document,"mouseup",this.sortEventEnd);
    this.sortedMoved=false},

sortMoving:function(event){
  if(!this.sortedMoved){
    log("sortedMoved");
    this.hideAbsElementsOnPanels();
    this.sortedMoved=true}},

sortEnded:function(event){
  //log("sortEnded, sortedMoved="+this.sortedMoved);
  if(this.sortedMoved){
    //alert("sortEnded");
    this.repositionManagePanel()
  }
  Event.stopObserving(document,"mousemove",this.sortEventMove);
  Event.stopObserving(document,"mouseup",this.sortEventEnd);
  if(useRelHack){
    this.fixManagePaneIEBug()
  }},

fixManagePaneIEBug:function(cancel_only){
  if(!useRelHack){return}
  if(cancel_only==null){
    cancel_only=false
  }
  if(this.fmpie!=null){
    window.clearTimeout(this.fmpie);
    this.fmpie=null
  }
  if(cancel_only){
    for(key in this.bling){
      if((this.bling[key]!=null)&&(this.bling[key].managePane!=null)){
        this.bling[key].managePane.style.position="relative"
      }
    }
  }else{
    var _this=this;
    this.fmpie=window.setTimeout(function(){
      for(key in _this.bling){
        if((_this.bling[key]!=null)&&(_this.bling[key].managePane!=null)){
          _this.bling[key].managePane.style.position="static"}
        }
      },500)}},

hideAbsElementsOnPanels:function(){
  for(key in this.bling){
    if(this.bling[key]!=null){
      this.bling[key].hideAbsPanelElements()}
    }
  },

repositionManagePanel:function(){
  for(key in this.bling){
    if(this.bling[key]!=null){
      //alert("showAbsPanelElements:"+this.bling[key].managePane.id);
      this.bling[key].showAbsPanelElements();
    }
  }},

checkPageWidth:function(){
  if(this.page_width_test_element==null){
    this.page_width_test_element=$("page_width_change_test_el");
    var pos=Position.cumulativeOffset(this.page_width_test_element);
    this.last_page_with_test=pos[0]
  }else{
    var pos=Position.cumulativeOffset(this.page_width_test_element);
    if(pos[0]!=this.last_page_with_test){
      this.recalibrateCanvas()
    }
    this.last_page_with_test=pos[0]
  }
  var _this=this;
  window.setTimeout(function(){
    _this.checkPageWidth()
  },500)},

pingServer:function(){
  var _this=this;
  window.setTimeout(function(){
    var t1=new Ajax.Request("/home/ping?ts="+new Date().getTime(),
                            {asynchronous:true,evalScripts:true});
    _this.pingServer()},3600000)},

showByCat:function(){
  $("blingdisplay_img").style.display='';
  $("blingbddisplay").style.display='none'},

showByDate:function(){
    $("blingdisplay_img").style.display='none';
    $("blingbddisplay").style.display='';
    if(this.loaded_by_date!=true){
      this.loaded_by_date=true;
      startAsyncAction();
      var t1=new Ajax.Updater('blingbddisplay',
                              '/home/getblings_bydate?page=1',
                              {asynchronous:true,evalScripts:true,
                              onFailure:function(t){
                                alert('Error '+t.status+' -- '+t.statusText)},
                              onComplete:function(request){
                                finishAsyncAction()}
                              })
    }},

tbTransformed:function(fname,bling,width,height){
  //log("sb.tbTransformed(2)");
  var b=this.bling[bling];
  if(b==null){
    alert("ERROR: Unable to get text bling:"+bling);
    return
  }
  //log("sb.tbTransformed(3)");
  b.tbTransformed(fname,width,height)},

selectColor:function(el,dest){
  var _this=this;
  if(this.selected!=null){
    this.selectedColorBling=this.selected
  }
  showColorPicker(el,function(c){_this.colorCallback(c,el,dest)})},

colorCallback:function(color,el,dest){
  el.style.backgroundColor=color;
  if(this.selectedColorBling!=null){
    this.selectedColorBling.colorCallback(color,dest)
  }},

checkIfAnimated:function(){
  var isAnimated=false;
  for(key in this.bling){
    if(this.bling[key]!=null){
      if(this.bling[key].isAnimated()){isAnimated=true}
    }
  }
  if(isAnimated){
    if($("fps_pane").style.display!=''){
      $("fps_pane").style.display='';
      this.repositionManagePanel()
    }
  }else{
    if($("fps_pane").style.display!='none'){
      $("fps_pane").style.display='none';
      this.repositionManagePanel()
    }
  }},

setFPS:function(fps){
  this.fps=fps;
  this.fps_slider.setValue(fps)
  }
});

// Fonctions du bling en lui męme
var Bling=Class.create({CLASSDEF:{name:'Bling'},
  initialize:function(element,pp,opts,bling_id,bling_type,thumb_factor){
    //log("class Bling element:" + element + " pp:" + pp + " opts:" + opts + " bling_id:" + bling_id + " bling_type:" + bling_type + " thumb_factor:" + thumb_factor);
    //log(pp);
    if(thumb_factor==null){
      this.thumb_factor=1
    }else{
      this.thumb_factor=thumb_factor
    }
  this.el=element;
  this.effectProperties={};
  if(element==null){
    log("ERROR: NULL EL PASSED TO Bling.initialize()")
  }else{
    log("initialize from el.id="+element.id)
  }
  if(pp==null){
    log("initialize pp==null")
  }else{
    log(pp.nextId());
    this.pp=pp
  }
  if(opts["z"]==null){
    this.z=pp.nextZ()
  }else{
    this.z=parseInt(opts["z"])
  }
  if(opts["tn_image"]!=null){
    this.tn_image=opts["tn_image"]
  }else{
    this.tn_image=$("tn_"+element.id);
    if(this.tn_image==null){
      this.tn_image=this.el
    }
  }
  if(opts['on_image']==true){
    this.id="bling_"+pp.nextId();
    this.el.id=this.id
  }else{
    this.id=this.el.id
  }
  log("new id =="+this.el.id);
  this.el.style.cursor='move';
  this.el.style.zIndex=this.z;
  this.selected=false;
  this.bling_id=bling_id;
  this.bling_type=bling_type;
  this.isMoving=false;
  var _this=this;
  if(opts['on_image']==true){
    this.on_image=true;
    //log("Setting Draggable on "+_this.el.id);
    // Si Internet Explorer
    if(useAlphaHack){
      var t1=new Draggable(_this.el.id,
                          {revert:false,starteffect:function(element){},
                                        endeffect:function(element){_this.dragEnded()},
                                        change:function(dragable){_this.moving(dragable)}
                          })
    }else{
      var t2=new Draggable(_this.el.id,
                          {revert:false,change:function(dragable){_this.moving(dragable)},
                                        endeffect:function(element){
                                          var t1=new Effect.Opacity(element,{duration:0.2,from:0.7,to:1.0});
                                          _this.dragEnded()
                                        }
                          })
    }
    //log("Set Draggable on "+_this.el.id);
    // ajout fl
    // pour supprimer le clignotement du manage
    //_this.el.onmousemove=function(ev){_this.rollover()};
    // fin ajout fl
    _this.el.onmouseout=function(ev){_this.leave()};
    _this.el.onclick=function(ev){_this.select()};
    if(opts['no_manage_pane']!=true){
      //log("initManagePane()");
      this.initManagePane();
      //log("initManagePane() DONE")
    }
  }else{
    this.on_image=false;
    // Si Internet Explorer
    if(useAlphaHack){
      var t3=new Draggable(_this.el.id,
                          {revert:true,starteffect:function(element){},
                                       endeffect:function(element){}
                          })
    }else{
      var t4=new Draggable(_this.el.id,
                          {revert:true})
    }
  }
  this.eventResizeStart=this.resizeStart.bindAsEventListener(this);
  this.eventResizeMouseUp=this.resizeFinished.bindAsEventListener(this);
  this.eventResizeMouseMove=this.resizeMove.bindAsEventListener(this);
  this.initBlingEffects(opts)}, isAnimated:function(){return false},
                                
                                loadPosition:function(){},
                                
                                copy:function(extraOpts){
                                  log ("copy Bling");
                                  var el=document.createElement("DIV");
                                  el.src=this.el.src;
                                  el.id=this.pp.nextId();
                                  if(extraOpts!=null){
                                    el.style.left=this.pp.to_x(parseInt(extraOpts["x"]))+"px";
                                    el.style.top=this.pp.to_y(parseInt(extraOpts["y"]))+"px";
                                    el.style.width=extraOpts["w"]+"px";
                                    el.style.height=extraOpts["h"]+"px"
                                  }else{
                                    var pos=Position.cumulativeOffset(this.el);
                                    el.style.left=pos[0]+"px";el.style.top=pos[1]+"px"
                                  }
                                  el.style.position="absolute";
                                  el.style.opacity="";
                                  el.style.filter="";
                                  document.body.appendChild(el);
                                  if(extraOpts==null){
                                    extraOpts={on_image:true,tn_image:this.tn_image}
                                  }else{
                                    extraOpts["on_image"]=true;
                                    extraOpts["tn_image"]=this.tn_image
                                  }
                                  return new Bling(el,this.pp,extraOpts,this.bling_id,this.bling_type,this.thumb_factor)},
                                
                                initManagePane:function(){
                                  this.pp.insertManagePane(this.bling_type,this)},
                                
                                getApplyType:function(){return 0},
                                
                                bindPanel:function(panel,id){
                                  //log("binding base object panel");
                                  var _this=this;
                                  this.managePane=panel;
                                  this.managePane.onmousemove=function(ev){_this.rollover()};
                                  this.managePane.onmouseout=function(ev){_this.leave()};
                                  this.managePane.onclick=function(ev){_this.select()};
                                  var obj=$("mp_"+id+"_tn");
                                  this.thumbContainer=obj;
                                  log ("bling.z haut 1:" + this.el.id + " z:" + _this.z);
                                  //obj=$("mp_"+id+"_zu");
                                  //obj.onclick=function(ev){_this.zUp()};
                                  //obj=$("mp_"+id+"_zd");
                                  //obj.onclick=function(ev){_this.zDown()};
                                  // ajout fl
                                  //obj=$("mp_"+id+"_zvalue");
                                  //obj.value = _this.el.style.zIndex;
                                  //obj=$("mp_"+id+"_order");
                                  //obj.value = this.managePane.parentNode.childNodes.length - 1;
                                  // fin ajout fl
                                  obj=$("mp_"+id+"_del");
                                  obj.onclick=function(ev){_this.del()};
                                  this.top_input=$("mp_"+id+"_t");
                                  this.top_input.onkeyup=function(el){_this.setSize()};
                                  this.top_input.onchange=function(el){_this.validateInput(_this.top_input,0,function(){_this.setSize()})};
                                  this.left_input=$("mp_"+id+"_l");
                                  this.left_input.onkeyup=function(el){_this.setSize()};
                                  this.left_input.onchange=function(el){_this.validateInput(_this.left_input,0,function(){_this.setSize()})};
                                  this.width_input=$("mp_"+id+"_w");
                                  if(this.width_input!=null){
                                    this.width_input.onkeyup=function(el){_this.setSize()};
                                    this.width_input.onchange=function(el){_this.validateInput(_this.width_input,100,function(){_this.setSize()})}
                                  }
                                  this.height_input=$("mp_"+id+"_h");
                                  if(this.height_input!=null){
                                    this.height_input.onkeyup=function(el){_this.setSize()};
                                    this.height_input.onchange=function(el){_this.validateInput(_this.height_input,100,function(){_this.setSize()})}
                                  }
                                  var dims=this.getDims();
                                  var t=dims[0];
                                  var l=dims[1];
                                  var h=dims[2];
                                  var w=dims[3];
                                  this.top_input.value=this.pp.from_y(t);
                                  this.left_input.value=this.pp.from_x(l);
                                  if(this.width_input!=null){
                                    this.width_input.value=w
                                  }
                                  if(this.height_input!=null){
                                    this.height_input.value=h
                                  }
                                  //log("binding base object panel finished" + t +"/"+ l +"/"+ h +"/"+ w)
                                  },
                                
                                validateInput:function(inputEl,defaultVal,callback){
                                  if(inputEl.value==""){
                                    inputEl.value=defaultVal;
                                    //log("fixing input (blank)");
                                    callback()
                                  }else if(parseInt(inputEl.value)==NaN){
                                    inputEl.value=defaultVal;
                                    //log("fixing input (NaN)");
                                    callback()
                                  }else if(parseInt(inputEl.value)!=inputEl.value){
                                    //log("fixing input (neq)");
                                    inputEl.value=defaultVal;
                                    callback()
                                  }},
                                
                                dragEnded:function(){
                                  var cdims=this.pp.getDims();
                                  var pdims=this.getDims();
                                  var t=pdims[0];
                                  var l=pdims[1];
                                  var h=pdims[2];
                                  var w=pdims[3];
                                  var ct=cdims[0];
                                  var cl=cdims[1];
                                  var ch=cdims[2];
                                  var cw=cdims[3];
                                  var inside=true;
                                  if((t>ct+ch)||(t+h<ct)){inside=false}else if((l>cl+cw)||(l+w<cl)){inside=false}
                                  if(!inside){this.del()}
                                  else if(this.isMoving){
                                    //log("Fixing drop..:" + this.isMoving);
                                    pp.drop(this.el)
                                  }},
                                
                                rollover:function(){
                                  if(!this.selected){
                                    this.setRolloverStyle();
                                    this.managePane.className="managepanehightlight"
                                  }},
                                
                                setRolloverStyle:function(){
                                  if((BrowserDetect.browser=="Explorer")||(BrowserDetect.browser=="Opera")){
                                    this.el.style.borderStyle="dotted";
                                    this.el.style.borderWidth="1px";
                                    this.el.style.borderColor="black"
                                  }else{
                                    this.el.style.outlineStyle="dotted";
                                    this.el.style.outlineWidth="1px";
                                    this.el.style.outlineColor="invert"
                                  }},
                                
                                getDims:function(){
                                  return[ parseFloat(this.el.style.top),
                                          parseFloat(this.el.style.left),
                                          parseFloat(this.el.style.height),
                                          parseFloat(this.el.style.width)]
                                  },
                                
                                leave:function(){
                                  if(!this.selected){
                                    this.setLeaveStyle();
                                    this.managePane.className="managepaneoff"
                                  }},
                                
                                setLeaveStyle:function(){
                                  if((BrowserDetect.browser=="Explorer")||(BrowserDetect.browser=="Opera")){
                                    this.el.style.borderStyle="none";
                                    this.el.style.borderWidth="0px"
                                  }else{
                                    this.el.style.outlineWidth="0px"
                                  }},
                                // Selectionne le bling
                                select:function(){
                                  log("selection "+this.id);
                                  if(!this.selected){
                                    pp.selectBling(this);
                                    this.selected=true;
                                    this.setSelectStyle();
                                    this.el.style.zIndex=1000;
                                    this.addHandles();
                                    if(this.thumbContainer!=null){
                                      this.thumbContainer.className="inner"
                                    }
                                    if(this.managePane!=null){
                                      this.managePane.className="managepaneselected";
                                      // ajout fl
                                      this.displayRotation(parseInt(this.rotation_input.value),true,true);
                                      //this.displayRotationBezierL(parseInt(this.bezierL_input.value),true,true);
                                      //this.displayRotationBezierR(parseInt(this.bezierR_input.value),true,true);
                                      // fin ajout fl
                                      this.pp.setBlingEffectsDialog();
                                    }
                                  }},
                                // Dessine le carre autour du bling
                                setSelectStyle:function(){
                                  if((BrowserDetect.browser=="Explorer")||(BrowserDetect.browser=="Opera")){
                                    this.el.style.borderStyle="solid";
                                    this.el.style.borderWidth="1px";
                                    this.el.style.borderColor="black"
                                  }else{
                                    this.el.style.outlineStyle="solid";
                                    this.el.style.outlineWidth="1px";
                                    this.el.style.outlineColor="invert"
                                  }},
                                  
                                deselect:function(){
                                  log("deselect "+this.id);
                                  this.setLeaveStyle();
                                  this.el.style.zIndex=this.z;
                                  this.selected=false;
                                  this.removeHandles();
                                  if(this.thumbContainer!=null){
                                    this.thumbContainer.className="inneroff"
                                  }
                                  if(this.managePane!=null){
                                    log ("managePane!=null");
                                    // ajout fl
                                    if(this.jg!=null){
                                      this.jg.clear();
                                    }
                                    //if(this.jgBli!=null){
                                    //  this.jgBli.clear();
                                    //}
                                    //if(this.jgBri!=null){
                                    //  this.jgBri.clear();
                                    //}
                                    // fin ajout fl
                                    this.managePane.className="managepaneoff"
                                  }},
                                moving:function(dragable){
                                  if(!this.selected){
                                    this.select()
                                  }
                                  if(!this.isMoving){
                                    this.moveStarted();
                                    this.isMoving=true
                                  }
                                  if(this.top_input!=null){
                                    var t=parseFloat(this.el.style.top);
                                    this.top_input.value=this.pp.from_y(t)
                                  }
                                  if(this.left_input!=null){
                                    var l=parseFloat(this.el.style.left);
                                    this.left_input.value=this.pp.from_x(l)
                                  }},
                                
                                moveStarted:function(){
                                  this.removeHandles()},
                                
                                moveFinished:function(){
                                  //log("moveFinished "+this.id);
                                  this.addHandles();
                                  this.isMoving=false},
                                
                                buildSizer:function(cursor,position){
                                  if(this.sizers==null){
                                    this.sizers={}
                                  }
                                  var sizer=this.pp.sizer.cloneNode(true);
                                  sizer.id=this.pp.nextId();
                                  sizer.style.cursor=cursor;
                                  sizer.style.zIndex=1010;
                                  sizer.positioning_mode=position;
                                  document.body.appendChild(sizer);
                                  this.sizers[position]=sizer;
                                  Event.observe(sizer,"mousedown",this.eventResizeStart);
                                  return sizer},
                                
                                setSize:function(){
                                  var t=parseInt(this.top_input.value);
                                  var l=parseInt(this.left_input.value);
                                  var h=parseInt(this.height_input.value);
                                  var w=parseInt(this.width_input.value);
                                  if(!this.setHeight(h)){
                                    h=this.getDims()[2];
                                    this.height_input.value=h
                                  }
                                  if(!this.setWidth(w)){
                                    w=this.getDims()[3];
                                    this.width_input.value=w
                                  }
                                  l=this.pp.to_x(l);
                                  t=this.pp.to_y(t);
                                  this.el.style.left=l+"px";
                                  this.el.style.top=t+"px";
                                  if(this.selected){
                                    this.repositionHandles("",t,l,h,w)
                                  }
                                  this.sizedFromPane()},
                                
                                sizedFromPane:function(){},
                                
                                resizeStart:function(event){
                                  this.isResizing=true;
                                  if(this.handleResizeStart(event)){
                                  }else{
                                    this.currentSizer=Event.element(event);
                                    //log("resizeStart for "+this.currentSizer.positioning_mode);
                                    Event.observe(document,"mouseup",this.eventResizeMouseUp);
                                    Event.observe(document,"mousemove",this.eventResizeMouseMove);
                                    Event.stop(event)
                                  }return false},
                                
                                handleResizeStart:function(event){return false},
                                
                                resizeMove:function(event){
                                  var pointer=[Event.pointerX(event),Event.pointerY(event)];
                                  if(this._lastPointer&&(this._lastPointer.inspect()==pointer.inspect())){return false}
                                  this._lastPointer=pointer;
                                  var pl=pointer[0]-PPSizerHalf;
                                  var pt=pointer[1]-PPSizerHalf;
                                  var pm=this.currentSizer.positioning_mode;
                                  var dims=this.getDims();
                                  var t=dims[0];
                                  var l=dims[1];
                                  var h=dims[2];
                                  var w=dims[3];
                                  var ot=t;
                                  var ol=l;
                                  var oh=h;
                                  var ow=w;
                                  if(pm=="BR"){
                                    h=pointer[1]-t;
                                    w=pointer[0]-l;
                                    if(!this.setHeight(h)){
                                      h=this.getDims()[2];
                                      pt=t+h-PPSizerHalf
                                    }
                                    if(!this.setWidth(w)){
                                      w=this.getDims()[3];
                                      pl=l+w-PPSizerHalf
                                    }
                                    this.repositionHandles("BR",t,l,h,w)
                                  }else if(pm=="BL"){
                                    h=pointer[1]-t;
                                    w=w+(l-pointer[0]);
                                    l=pointer[0];
                                    if(!this.setHeight(h)){
                                      h=this.getDims()[2];
                                      pt=t+h-PPSizerHalf
                                    }
                                    if(!this.setWidth(w)){
                                      w=this.getDims()[3];
                                      l=(ol+ow)-w;
                                      pl=l-PPSizerHalf;
                                      this.el.style.left=l+"px"
                                    }else{
                                      this.el.style.left=l+"px"
                                    }
                                    this.repositionHandles("BL",t,l,h,w)
                                  }else if(pm=="TL"){
                                    h=h+(t-pointer[1]);
                                    w=w+(l-pointer[0]);
                                    t=pointer[1];
                                    l=pointer[0];
                                    if(!this.setHeight(h)){
                                      h=this.getDims()[2];
                                      t=(ot+oh)-h;
                                      pt=t-PPSizerHalf;
                                      this.el.style.top=t+"px"
                                    }else{
                                      this.el.style.top=t+"px"
                                    }
                                    if(!this.setWidth(w)){
                                      w=this.getDims()[3];
                                      l=(ol+ow)-w;
                                      pl=l-PPSizerHalf;
                                      this.el.style.left=l+"px"
                                    }else{
                                      this.el.style.left=l+"px"
                                    }
                                    this.repositionHandles("TL",t,l,h,w)
                                  }else if(pm=="TR"){
                                    h=h+(t-pointer[1]);
                                    w=pointer[0]-l;
                                    t=pointer[1];
                                    if(!this.setHeight(h)){
                                      h=this.getDims()[2];
                                      t=(ot+oh)-h;
                                      pt=t-PPSizerHalf;
                                      this.el.style.top=t+"px"
                                    }else{
                                      this.el.style.top=t+"px"
                                    }
                                    if(!this.setWidth(w)){
                                      w=this.getDims()[3];
                                      pl=l+w-PPSizerHalf
                                    }
                                    this.repositionHandles("TR",t,l,h,w)
                                  }
                                  this.updateManagePaneDims(t,l,w,h);
                                  this.currentSizer.style.left=pl+"px";
                                  this.currentSizer.style.top=pt+"px";
                                  return false},
                                
                                updateManagePaneDims:function(t,l,w,h){
                                  this.top_input.value=this.pp.from_y(t);
                                  this.left_input.value=this.pp.from_x(l);
                                  if(this.width_input!=null){
                                    this.width_input.value=w
                                  }
                                  if(this.height_input!=null){
                                    this.height_input.value=h}
                                  },
                                
                                resizeFinished:function(event){
                                  //log("resizeFinished");
                                  this.isResizing=false;
                                  this._lastPointer=null;
                                  this.currentSizer=null;
                                  Event.stopObserving(document,"mouseup",this.eventResizeMouseUp);
                                  Event.stopObserving(document,"mousemove",this.eventResizeMouseMove)},
                                
                                addHandles:function(){
                                  var dims=this.getDims();
                                  var t=dims[0];
                                  var l=dims[1];
                                  var h=dims[2];
                                  var w=dims[3];
                                  var sizer=this.buildSizer("nw-resize","BR");
                                  this.positionHandle(sizer,"BR",t,l,h,w);
                                  sizer.style.display="";
                                  sizer=this.buildSizer("ne-resize","BL");
                                  this.positionHandle(sizer,"BL",t,l,h,w);
                                  sizer.style.display="";
                                  sizer=this.buildSizer("nw-resize","TL");
                                  this.positionHandle(sizer,"TL",t,l,h,w);
                                  sizer.style.display="";
                                  sizer=this.buildSizer("ne-resize","TR");
                                  this.positionHandle(sizer,"TR",t,l,h,w);
                                  sizer.style.display=""},
                                
                                removeHandles:function(){
                                  if(this.sizers!=null){
                                    for(key in this.sizers){
                                      if(this.sizers[key]!=null){
                                        Event.stopObserving(this.sizers[key],"mousedown",this.eventResizeStart);
                                        document.body.removeChild(this.sizers[key])
                                      }
                                    }
                                    this.sizers=null
                                  }},
                                
                                positionHandle:function(sizer,pos,t,l,h,w){
                                  if(pos=="BR"){
                                    sizer.style.left=(l+w-PPSizerHalf)+"px";
                                    sizer.style.top=(t+h-PPSizerHalf)+"px"
                                  }else if(pos=="TL"){
                                    sizer.style.left=(l-PPSizerHalf)+"px";
                                    sizer.style.top=(t-PPSizerHalf)+"px"
                                  }else if(pos=="TR"){
                                    sizer.style.left=(l+w-PPSizerHalf)+"px";
                                    sizer.style.top=(t-PPSizerHalf)+"px"
                                  }else if(pos=="BL"){
                                    sizer.style.left=(l-PPSizerHalf)+"px";
                                    sizer.style.top=(t+h-PPSizerHalf)+"px"
                                  }else{log("Unknown position:"+pos)}},
                                
                                repositionHandles:function(exclude,t,l,h,w){
                                  for(key in this.sizers){
                                    if(key!=exclude){
                                      this.positionHandle(this.sizers[key],key,t,l,h,w)
                                    }
                                  }},
                                
                                setHeight:function(height){
                                  this.el.style.height=height+"px";return true},
                                
                                setWidth:function(width){
                                  this.el.style.width=width+"px";return true},
                                
                                swapZOrder:function(otherBling, idOrigine, idNextOuPrev){
                                  var oldZ=this.z;
                                  // maj du bling en cours avec le z de l'autre bling
                                  log("swapZOrder this : " + this.z);
                                  log("swapZOrder otherBling : " + otherBling.z);
                                  this.setZOrder(otherBling.z, idOrigine);
                                  // maj de l'autre bling avec le z du bling en cours
                                  otherBling.setZOrder(oldZ, idNextOuPrev);
                                  log("zOrderSet : ------------------------");
                                  var elements = new Array();
                                  for(var i=0;i<(this.managePane.parentNode.childNodes.length - 1);i++){
                                    var mp = this.managePane.parentNode.childNodes[i].id;
                                    var obj=$(mp+"_zvalue");
                                    var element = new Array();
                                    log("zOrderSet : " + mp + " " + obj.value);
                                    element.push(obj.value);
                                    element.push(mp);
                                    log("zOrderSet : " + element.join(" "));
                                    elements.push(element);
                                  }
                                  elements.sort();
                                  //var v = this.values.sortBy(obj.value);
                                  log("zOrderSet trie: ------------------------");
                                  for(var i=0;i<elements.length;i++){
                                    log("zOrderSet : " + elements[i][0] + " " + elements[i][1]);
                                    var obj=$(elements[i][1]+"_order");
                                    log ("obj:" + obj.name);
                                    obj.value = eval(i + 1);//eval(i + 1);
                                  }
                                },
                                
                                setZOrder:function(z, id){
                                  this.z=z;
                                  this.el.style.zIndex=z;
                                  var obj=$(id+"_zvalue");
                                  obj.value = this.el.style.zIndex;
                                  log("zOrderSet .length : " + this.managePane.parentNode.childNodes.length);
                                },
                                
                                zUp:function(){
                                  //log("zUp : this :" + this.z);
                                  if(this.managePane.previousSibling!=null){
                                    if(this.pp.sortable[this.managePane.previousSibling.id]!=null){
                                      //log("zUp : previousSibling :" + this.pp.sortable[this.managePane.previousSibling.id].z);
                                      this.swapZOrder(this.pp.sortable[this.managePane.previousSibling.id], this.managePane.id, this.managePane.previousSibling.id);
                                      var par=this.managePane.parentNode;
                                      var sib=this.managePane.previousSibling;
                                      par.removeChild(sib);
                                      par.insertBefore(sib,this.managePane.nextSibling);
                                      this.pp.repositionManagePanel()
                                    }
                                  }else
                                  if(this.managePane.nextSibling!=null){
                                    if(this.pp.sortable[this.managePane.nextSibling.id]!=null){
                                      //log("zUp : nextSibling :" + this.pp.sortable[this.managePane.nextSibling.id].z);
                                    }
                                  }},
                                
                                zDown:function(){
                                  //log("zDown : " + this.z);
                                  if(this.managePane.nextSibling!=null){
                                    if(this.pp.sortable[this.managePane.nextSibling.id]!=null){
                                      //log("zDown : nextSibling :" + this.pp.sortable[this.managePane.nextSibling.id].z);
                                      this.swapZOrder(this.pp.sortable[this.managePane.nextSibling.id], this.managePane.id, this.managePane.nextSibling.id);
                                      if((this.managePane.nextSibling!=null)&&(this.managePane.nextSibling.nextSibling!=null)){
                                        var par=this.managePane.parentNode;
                                        var sib=this.managePane.nextSibling;//.nextSibling;
                                        par.removeChild(sib);
                                        par.insertBefore(sib,this.managePane)
                                      }else{
                                        var par=this.managePane.parentNode;
                                        par.removeChild(this.managePane);
                                        par.appendChild(this.managePane)
                                      }
                                      this.pp.repositionManagePanel()
                                    }
                                  }else
                                  if(this.managePane.previousSibling!=null){
                                    if(this.pp.sortable[this.managePane.previousSibling.id]!=null){
                                      //log("zDown : previousSibling :" + this.pp.sortable[this.managePane.previousSibling.id].z);
                                    }
                                  }},
                                
                                del:function(){
                                  log("del :" + this.el.id);
                                  if(this.el==null){return}
                                  this.removeHandles();
                                  var _this=this;
                                  if(useAlphaHack){
                                    this.el.parentNode.removeChild(_this.el)
                                  }else{
                                    // Effet donné ŕ la suppression du bling
                                    Effect.Fade(this.el.id,{afterFinish:function(el){_this.removeHandles();_this.el.parentNode.removeChild(_this.el)}})
                                  }
                                  if(this.managePane!=null){
                                    Position.absolutize(this.managePane);
                                    // Effet donné ŕ la suppression du panel
                                    //log("zOrderSet managePane.id : " + this.managePane.id);
                                    Effect.Fade(this.managePane.id,{afterFinish:function(el){_this.managePane.parentNode.removeChild(_this.managePane)}})
                                  }
                                  this.pp.delBling(this)
                                  /*
                                  var elements = new Array();
                                  for(var i=0;i<(this.managePane.parentNode.childNodes.length - 1);i++){
                                    var mp = this.managePane.parentNode.childNodes[i].id;
                                    var obj=$(mp+"_zvalue");
                                    var element = new Array();
                                    //log("zOrderSet : " + mp + " " + obj.value);
                                    if (this.managePane.id != mp){
                                      element.push(obj.value);
                                      element.push(mp);
                                      //log("zOrderSet : " + element.join(" "));
                                      elements.push(element);
                                    }
                                  }
                                  elements.sort();
                                  //var v = this.values.sortBy(obj.value);
                                  //log("zOrderSet trie: ------------------------");
                                  for(var i=0;i<elements.length;i++){
                                    //log("zOrderSet : " + elements[i][0] + " " + elements[i][1]);
                                    var obj=$(elements[i][1]+"_order");
                                    obj.value = eval(i + 1);//eval(i + 1);
                                  }*/
                                },
                                  
                                hide:function(){this.hidden=true;
                                  this.removeHandles();
                                  this.el.style.display="none";
                                  if(this.managePane!=null){
                                    this.managePane.onmousemove=null;
                                    this.managePane.onmouseout=null;
                                    this.managePane.onclick=null;
                                    var t1=new Effect.Opacity(this.managePane,{duration:0.3,to:0.1});
                                    this.top_input.disabled=true;
                                    this.left_input.disabled=true;
                                    if(this.width_input!=null){this.width_input.disabled=true}
                                    if(this.height_input!=null){this.height_input.disabled=true}
                                    this.hideAbsPanelElements()
                                  }},
                                                          
                                restore:function(){this.hidden=false;
                                  this.el.style.display="";
                                  var _this=this;
                                  if(this.managePane!=null){
                                    this.managePane.onmousemove=function(ev){_this.rollover()};
                                    this.managePane.onmouseout=function(ev){_this.leave()};
                                    this.managePane.onclick=function(ev){_this.select()};
                                    var t1=new Effect.Opacity(this.managePane,{duration:0.3,to:1.0});
                                    this.top_input.disabled=false;
                                    this.left_input.disabled=false;
                                    if(this.width_input!=null){this.width_input.disabled=false}
                                    if(this.height_input!=null){this.height_input.disabled=false}
                                    this.showAbsPanelElements()
                                  }},
                                                          
                                translate:function(delta_x,delta_y){var dims=this.getDims();
                                  var t=dims[0];
                                  var l=dims[1];
                                  var h=dims[2];
                                  var w=dims[3];
                                  t=t-delta_y;
                                  l=l-delta_x;
                                  this.el.style.top=t+"px";
                                  this.el.style.left=l+"px";
                                  this.updateManagePaneDims(t,l,w,h)},
            
                                serialize:function(queryComponents,prefix){if(prefix==null){prefix="bling"}
                                  log ("serialize");
                                  if(queryComponents==null){queryComponents=new Array()}
                                  var dims=this.getDims();
                                  var t=dims[0];
                                  var l=dims[1];
                                  var h=dims[2];
                                  var w=dims[3];
                                  queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][type]")+"="+encodeURIComponent(this.bling_id));
                                  queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][y]")+"="+encodeURIComponent(this.pp.from_y(t)));
                                  queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][x]")+"="+encodeURIComponent(this.pp.from_x(l)));
                                  queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][h]")+"="+encodeURIComponent(h));
                                  queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][w]")+"="+encodeURIComponent(w));
                                  queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][z]")+"="+encodeURIComponent(this.z));
                                  queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][btype]")+"="+encodeURIComponent(this.bling_type));
                                  queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][it]")+"="+encodeURIComponent(this.getApplyType()));
                                  this.serializeBlingEffects(queryComponents,prefix)},
            
                                hideAbsPanelElements:function(){},
                                                          
                                showAbsPanelElements:function(){},
                                                          
                                serializeBlingEffects:function(queryComponents,prefix){
                                  if(queryComponents==null){queryComponents=new Array()}
                                  if(prefix==null){prefix="bling"}
                                  for(k in this.effectProperties){
                                    if(this.effectProperties[k]!=null){
                                      queryComponents.push(encodeURIComponent(prefix+"["+this.id+"]["+k+"]")+"="+encodeURIComponent(this.effectProperties[k]))
                                    }
                                  }
                                  return queryComponents.join('&')},
                                   
                                initBlingEffects:function(opts){for(k in opts){
                                  if(k.substr(0,2)=="e_"){
                                    this.effectProperties[k]=opts[k]
                                  }
                                }},
                                                                                          
                                getBlingEffectProperty:function(name,defaultValue){
                                  if(this.effectProperties[name]==null){return defaultValue}
                                  return this.effectProperties[name]},
                                                                                                              
                                setBlingEffectProperty:function(name,value){
                                  this.effectProperties[name]=value;
                                  if(name!="e_apply_bling_mode"){
                                    this.effectProperties["e_apply_bling_mode"]="1";
                                    $('e_odb_apply_bling_or').checked=true
                                  }},
                                                          
                                updateBling:function(){},
                                                          
                                usesEffects:function(){
                                  var do_effects=this.effectProperties["e_apply_bling_mode"];
                                  if(do_effects==1){return true}return false}
                                });


// L'image du bling...
var ImgBling=Class.create({ CLASSDEF:{name:'ImgBling',parent:Bling},
                            initialize:function(element,pp,opts,bling_id,bling_type,thumb_factor){
                                        //log("class ImgBling");
                                        log(pp);

                                        if(opts["use_gif"]!=null){
                                          this.usingGIF=opts["use_gif"]
                                        }else{
                                          this.usingGIF=false
                                        }
                                        ImgBling.parentClass.constructor().call(this,element,pp,opts,bling_id,bling_type,thumb_factor);
                                        if(!useAlphaHack||this.usingGIF){
                                          if(this.el.style.height!=""){
                                            this.el.height=parseFloat(this.el.style.height)
                                          }
                                          if(this.el.style.width!=""){
                                            this.el.width=parseFloat(this.el.style.width)
                                          }
                                          this.el.style.height="";
                                          this.el.style.width=""
                                        }
                                        this.flipState=opts["flip"];
                                        if(this.flipState==null){
                                          this.flipState=""
                                        }
                                        if(opts["on_image"]){
                                          if(this.thumb_factor!=1){
                                            var w=0;
                                            var h=0;
                                            if(!useAlphaHack||this.usingGIF){
                                              w=this.el.width;
                                              h=this.el.height
                                            }else{
                                              w=(parseInt(this.el.style.width)*this.thumb_factor);
                                              h=(parseInt(this.el.style.height)*this.thumb_factor);
                                              this.el.style.height=h+"px";
                                              this.el.width=w+"px"
                                            }
                                            if(this.width_input!=null){
                                              this.width_input.value=w
                                            }
                                            if(this.height_input!=null){
                                              this.height_input.value=h}
                                            }
                                            var doUpdateBlingSrc=false;
                                            // ajout FL
                                            /*if(opts["rot"]!=null){
                                              this.rotation_input.value=opts["rot"];
                                              if(parseInt(this.rotation_input.value)!=0){
                                                var _this=this;
                                                log ("opts");
                                                window.setTimeout(function(){_this.parseInt(_this.rotation_input.value),true,true)},1500);
                                                doUpdateBlingSrc=true
                                              }
                                            }
                                            // ajout FL
                                            if(opts["bli"]!=null){
                                              this.bezierL_input.value=opts["bli"];
                                              if(parseInt(this.bezierL_input.value)!=0){
                                                var _this=this;
                                                window.setTimeout(function(){_this.displayRotationBezierL(parseInt(_this.bezierL_input.value),true,true)},1500);
                                                doUpdateBlingSrc=true
                                              }
                                            }
                                            if(opts["bri"]!=null){
                                              this.bezierR_input.value=opts["bri"];
                                              if(parseInt(this.bezierR_input.value)!=0){
                                                var _this=this;
                                                window.setTimeout(function(){_this.displayRotationBezierR(parseInt(_this.bezierR_input.value),true,true)},1500);
                                                doUpdateBlingSrc=true
                                              }
                                            }
                                            // fin ajout FL
                                            if(opts["trans"]!=null){
                                              this.transparency_input.value=opts["trans"];
                                              if(parseInt(this.transparency_input.value)!=0){
                                                doUpdateBlingSrc=true}
                                              }
                                              if((doUpdateBlingSrc)||(this.usesEffects())){
                                                this.updateBlingSrc()
                                              }
                                            */}},

                            copy:function(extraOpts){
                              //log("making copy ImgBling");
                              
                              if((useAlphaHack)&&(!this.usingGIF)){
                                var el=document.createElement("IMG");
                                el.id=this.pp.nextId();
                                el.src="/images/sb/trans.gif";
                                if(extraOpts!=null){
                                  el.style.left=this.pp.to_x(parseInt(extraOpts["x"]))+"px";
                                  el.style.top=this.pp.to_y(parseInt(extraOpts["y"]))+"px";
                                  el.style.width=extraOpts["w"]+"px";el.style.height=extraOpts["h"]+"px"
                                }else{
                                  var pos=Position.cumulativeOffset(this.el);
                                  el.style.left=pos[0]+"px";
                                  el.style.top=pos[1]+"px";
                                  el.style.width=this.el.style.width;
                                  el.style.height=this.el.style.height
                                }
                                el.style.position="absolute";
                                el.style.opacity="";
                                el.style.filter=this.el.style.filter;
                                log(el.style.filter)
                              }else{
                                var el=document.createElement("IMG");
                                el.src=this.el.src;
                                el.id=this.pp.nextId();
                                if(extraOpts!=null){
                                  el.style.left=this.pp.to_x(parseInt(extraOpts["x"]))+"px";
                                  el.style.top=this.pp.to_y(parseInt(extraOpts["y"]))+"px";
                                  el.width=extraOpts["w"];
                                  el.height=extraOpts["h"]
                                }else{
                                  var pos=Position.cumulativeOffset(this.el);
                                  el.style.left=pos[0]+"px";
                                  el.style.top=pos[1]+"px"
                                }
                                el.style.position="absolute";
                                el.style.opacity="";
                                el.style.filter=""
                              }
                              log ("el.style.left" + el.style.left);
                              log ("el.style.top" + el.style.top);
                              document.body.appendChild(el);
                              if(extraOpts==null){
                                extraOpts={on_image:true,tn_image:this.tn_image}
                              }else{
                                extraOpts["on_image"]=true;
                                extraOpts["tn_image"]=this.tn_image
                              }
                              extraOpts["use_gif"]=this.usingGIF;
                              return new ImgBling(el,this.pp,extraOpts,this.bling_id,this.bling_type,this.thumb_factor)},
                          
                            isAnimated:function(){return this.usingGIF},
                           
                            getDims:function(){
                             if((useAlphaHack)&&(!this.usingGIF)){
                               return[parseFloat(this.el.style.top),parseFloat(this.el.style.left),parseFloat(this.el.style.height),parseFloat(this.el.style.width)]
                             }
                             return[parseFloat(this.el.style.top),parseFloat(this.el.style.left),this.el.height,this.el.width]
                             },
                           
                            setHeight:function(height){
                             this.el.height=height;
                             if((useAlphaHack)&&(!this.usingGIF)){
                               this.el.style.height=height+"px"
                             }return true},
                             
                            setWidth:function(width){
                             this.el.width=width;
                             if((useAlphaHack)&&(!this.usingGIF)){
                               this.el.style.width=width+"px"
                             }return true},
                           
                            bindPanel:function(panel,id){
                             log ("bindPanel");
                             ImgBling.parentClass.method("bindPanel").call(this,panel,id);
/*                             var obj=$("mp_"+id+"_img");
                             var tnWidth=this.tn_image.width;
                             var tnHeight=this.tn_image.height;
                             if((useAlphaHack)&&(!this.usingGIF)){
                               tnWidth=parseInt(this.tn_image.style.width);
                               tnHeight=parseInt(this.tn_image.style.height)
                             }
                             if((tnWidth>iconWidth)||(tnHeight>iconWidth)){
                               var ratio=tnWidth/tnHeight;
                               if(tnWidth>tnHeight){
                                 tnWidth=iconWidth;tnHeight=iconWidth/ratio
                               }else{
                                 tnHeight=iconWidth;tnWidth=iconWidth*ratio
                               }
                             }
                             if((useAlphaHack)&&(!this.usingGIF)){
                               obj.src="/images/sb/trans.gif";
                               obj.style.width=tnWidth;
                               obj.style.height=tnHeight;
                               obj.style.display="inline-block";
                               obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.tn_image.src+"', sizingMethod='scale')";
                               log(obj.outerHTML)
                             }else{
                               obj.src=this.tn_image.src;
                               obj.width=tnWidth;
                               obj.height=tnHeight
                             }*/
                             //log ("_img obj:" + obj.src);
                             var obj=$("mp_"+id+"_srcf0");
                             var tnWidth=this.tn_image.width;
                             var tnHeight=this.tn_image.height;
                             if((useAlphaHack)&&(!this.usingGIF)){
                               tnWidth=parseInt(this.tn_image.style.width);
                               tnHeight=parseInt(this.tn_image.style.height)
                             }
                             if((tnWidth>iconWidth)||(tnHeight>iconWidth)){
                               var ratio=tnWidth/tnHeight;
                               if(tnWidth>tnHeight){
                                 tnWidth=iconWidth;tnHeight=iconWidth/ratio
                               }else{
                                 tnHeight=iconWidth;tnWidth=iconWidth*ratio
                               }
                             }
                             if((useAlphaHack)&&(!this.usingGIF)){
                               obj.src="/images/sb/trans.gif";
                               obj.style.width=tnWidth;
                               obj.style.height=tnHeight;
                               obj.style.display="inline-block";
                               obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.tn_image.src+"', sizingMethod='scale')";
                               log(obj.outerHTML)
                             }else{
                               obj.src=this.tn_image.src;
                               obj.width=tnWidth;
                               obj.height=tnHeight
                             }
                             var obj=$("mp_"+id+"_srcfh");
                             if((useAlphaHack)&&(!this.usingGIF)){
                               obj.src="/images/sb/trans.gif";
                               obj.style.width=tnWidth;
                               obj.style.height=tnHeight;
                               obj.style.display="inline-block";
                               obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='trans.php?img="+this.tn_image.src+"&flip=H', sizingMethod='scale')";
                               log(obj.outerHTML)
                             }else{
                               obj.src = "trans.php?img=" + this.tn_image.src + "&flip=H";
                               obj.width=tnWidth;
                               obj.height=tnHeight
                             } 
                             var obj=$("mp_"+id+"_srct0");
                             if((useAlphaHack)&&(!this.usingGIF)){
                               obj.src="/images/sb/trans.gif";
                               obj.style.width=tnWidth;
                               obj.style.height=tnHeight;
                               obj.style.display="inline-block";
                               obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.tn_image.src+"', sizingMethod='scale')";
                               log(obj.outerHTML)
                             }else{
                               obj.src=this.tn_image.src;
                               obj.width=tnWidth;
                               obj.height=tnHeight
                             }
                             var obj=$("mp_"+id+"_srct100");
                             if((useAlphaHack)&&(!this.usingGIF)){
                               obj.src="/images/sb/trans.gif";
                               obj.style.width=tnWidth;
                               obj.style.height=tnHeight;
                               obj.style.display="inline-block";
                               obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='trans.php?img="+this.tn_image.src+"&trans=50', sizingMethod='scale')";
                               log(obj.outerHTML)
                             }else{
                               obj.src = "trans.php?img=" + this.tn_image.src + "&trans=50";
                               obj.width=tnWidth;
                               obj.height=tnHeight
                             } 
                             //log ("_src obj:" + obj.src);
                             var _this=this;
                             this.rotation_input=$("mp_"+id+"_ro");
                             
                             // ajout fl
                             this.roR_input=$("mp_"+id+"_ror");

                             this.roR_input.onclick=function(el){
                               return false;
                               };
                             this.roR_input.onmousedown=function(el){
                               log ("onmousedown");
                                 _this.setEtatRotation(true);
                                 return _this.setRotation('+');
                               };
                             this.roR_input.onmouseup=function(el){
                                log ("onmouseup");
                                return _this.setEtatRotation(false);
                             }
                             this.roR_input.onmouseout=function(el){
                                log ("onmouseout");
                                return _this.setEtatRotation(false);
                             }

                             this.roL_input=$("mp_"+id+"_rol");
                             this.roL_input.onclick=function(el){
                               log ("onclick");
                               return false;
                            };
                             this.roL_input.onmousedown=function(el){
                               log ("onmousedown");
                                 _this.setEtatRotation(true);
                                 return _this.setRotation('-');
                               };
                             this.roL_input.onmouseup=function(el){
                                log ("onmouseup");
                                return _this.setEtatRotation(false);
                             }
                             this.roL_input.onmouseout=function(el){
                                log ("onmouseout");
                                return _this.setEtatRotation(false);
                             }

                             //this.bezierL_input=$("mp_"+id+"_bl");

                             //this.blL_input=$("mp_"+id+"_bll");
                             //this.blL_input.onclick=function(el){
                             //  return false;
                             //};
                             //this.blL_input.onmousedown=function(el){
                             //  log ("onmousedown");
                             //    _this.setEtatRotationBezierL(true);
                             //    return _this.setRotationBezierL('-');
                             //  };
                             //this.blL_input.onmouseup=function(el){
                             //   log ("onmouseup");
                             //   return _this.setEtatRotationBezierL(false);
                             //}
                             //this.blL_input.onmouseout=function(el){
                             //   log ("onmouseout");
                             //   return _this.setEtatRotationBezierL(false);
                             //}

                             //this.blR_input=$("mp_"+id+"_blr");
                             //this.blR_input.onclick=function(el){
                             //  return false;
                             //};
                             //this.blR_input.onmousedown=function(el){
                             //  log ("onmousedown");
                             //    _this.setEtatRotationBezierL(true);
                             //    return _this.setRotationBezierL('+');
                             //  };
                             //this.blR_input.onmouseup=function(el){
                             //   log ("onmouseup");
                             //   return _this.setEtatRotationBezierL(false);
                             //}
                             //this.blR_input.onmouseout=function(el){
                             //   log ("onmouseout");
                             //   return _this.setEtatRotationBezierL(false);
                             //}

                             //this.bezierR_input=$("mp_"+id+"_br");

                             //this.brL_input=$("mp_"+id+"_brl");
                             //this.brL_input.onclick=function(el){
                             //  return false;
                             //};
                             //this.brL_input.onmousedown=function(el){
                             //  log ("onmousedown");
                             //    _this.setEtatRotationBezierR(true);
                             //    return _this.setRotationBezierR('-');
                             //  };
                             //this.brL_input.onmouseup=function(el){
                             //   log ("onmouseup");
                             //   return _this.setEtatRotationBezierR(false);
                             //}
                             //this.brL_input.onmouseout=function(el){
                             //   log ("onmouseout");
                             //   return _this.setEtatRotationBezierR(false);
                             //}

                             //this.brR_input=$("mp_"+id+"_brr");
                             //  this.brR_input.onclick=function(el){
                             //  return false;
                             //  };
                             //this.brR_input.onmousedown=function(el){
                             //    log ("onmousedown");
                             //    _this.setEtatRotationBezierR(true);
                             //    return _this.setRotationBezierR('+');
                             //  };
                             //this.brR_input.onmouseup=function(el){
                             //   log ("onmouseup");
                             //   return _this.setEtatRotationBezierR(false);
                             //}
                             //this.brR_input.onmouseout=function(el){
                             //   log ("onmouseout");
                             //   return _this.setEtatRotationBezierR(false);
                             //}

                             this.trl_input=$("mp_"+id+"_trl");
                               this.trl_input.onclick=function(el){
                               return false;
                               };
                             this.trl_input.onmousedown=function(el){
                               log ("onmousedown");
                                 _this.setEtatRotationTransparency(true);
                                 return _this.setRotationTransparency('-');
                               };
                             this.trl_input.onmouseup=function(el){
                                log ("onmouseup");
                                return _this.setEtatRotationTransparency(false);
                             }
                             this.trl_input.onmouseout=function(el){
                                log ("onmouseout");
                                return _this.setEtatRotationTransparency(false);
                             }

                             this.trr_input=$("mp_"+id+"_trr");
                               this.trr_input.onclick=function(el){
                               return false;
                               };
                             this.trr_input.onmousedown=function(el){
                               log ("onmousedown");
                                 _this.setEtatRotationTransparency(true);
                                 return _this.setRotationTransparency('+');
                               };
                             this.trr_input.onmouseup=function(el){
                                log ("onmouseup");
                                return _this.setEtatRotationTransparency(false);
                             }
                             this.trr_input.onmouseout=function(el){
                                log ("onmouseout");
                                return _this.setEtatRotationTransparency(false);
                             }

                             this.rotation_widget=$("mp_"+id+"_roi");
                             this.rot_canvas=document.createElement("DIV");
                             this.rot_canvas.id=pp.nextId();
                             document.body.appendChild(this.rot_canvas);
                             this.jg=new jsGraphics(this.rot_canvas);
                             this.zero_rot_image=true;

                             //this.bezierL_widget=$("mp_"+id+"_bli");
                             //this.bli_canvas=document.createElement("DIV");
                             //this.bli_canvas.id=pp.nextId();
                             //document.body.appendChild(this.bli_canvas);
                             //this.jgBli=new jsGraphics(this.bli_canvas);
                             //this.zero_bli_image=true;

                             //this.bezierR_widget=$("mp_"+id+"_bri");
                             //this.bri_canvas=document.createElement("DIV");
                             //this.bri_canvas.id=pp.nextId();
                             //document.body.appendChild(this.bri_canvas);
                             //this.jgBri=new jsGraphics(this.bri_canvas);
                             //this.zero_bri_image=true;

                             this.transparency_input=$("mp_"+id+"_tr");
                             //this.transparency_input.onkeyup=function(el){_this.setTransparency()};
                             //this.transparency_input.onchange=function(el){_this.validateInput(_this.transparency_input,0,function(){_this.setTransparency()})};

                             this.flip_input=$("mp_"+id+"_fh");
                             if(this.flip_input!=null){this.flip_input.onclick=function(el){return _this.flip()}}
                             this.rotation_input.value="0";
                             // ajout fl
                             //this.bezierL_input.value="0";
                             //this.bezierR_input.value="0";
                             // fin ajout fl
                             this.transparency_input.value="0";
                             log("construit le menu pour le bling");
                             log("bound img panel")},
                         
                           // ajout fl
                           displayRotation:function(angle,calc_center,finished){
                             log ("displayRotation");
                             if(this.jg==null){return}
                             if((finished)&&(angle==0)){
                               this.jg.clear();
                               this.rotation_widget.src="/images/circle_with_carre.gif";
                               this.zero_rot_image=true;
                               return
                             }
                             if(calc_center){
                               var pos=Position.cumulativeOffset(this.rotation_widget);
                               this.rot_x_pos=pos[0]+this.rotation_widget.width/2;
                               this.rot_y_pos=pos[1]+this.rotation_widget.height/2
                             }
                             var length=this.rotation_widget.width/2-2;
                             if(this.zero_rot_image){
                               this.zero_rot_image=false;
                               this.rotation_widget.src="/images/circle_spacer.gif"
                             }
                             var rads1=this.degToRad(angle-90-45);
                             var y1=Math.sin(rads1)*length;
                             var x1=Math.cos(rads1)*length;
                             var rads2=this.degToRad(angle-90+45);
                             var y2=Math.sin(rads2)*length;
                             var x2=Math.cos(rads2)*length;
                             var rads3=this.degToRad(angle-90+90+45);
                             var y3=Math.sin(rads3)*length;
                             var x3=Math.cos(rads3)*length;
                             var rads4=this.degToRad(angle-90-90-45);
                             var y4=Math.sin(rads4)*length;
                             var x4=Math.cos(rads4)*length;

                             this.jg.clear();
                             //this.jg.setStroke(1);
                             log("drawline aiguille rotation");
                             //this.jg.setStroke(3);
                             this.jg.setColor("#b4b4b4");
                             var x_top_left = fDomOffset(this.rotation_widget, "offsetLeft");
                             var y_top_left = fDomOffset(this.rotation_widget, "offsetTop");
                             var width = this.rotation_widget.width;
                             var height = this.rotation_widget.height;
                             this.jg.fillEllipse(x_top_left, y_top_left, width, height);
                             this.jg.paint();
                             
                             this.jg.setColor("#618CBE");
                             var Xpoints = new Array(x1+this.rot_x_pos, x2+this.rot_x_pos, x3+this.rot_x_pos, x4+this.rot_x_pos);
                             var Ypoints = new Array(y1+this.rot_y_pos, y2+this.rot_y_pos, y3+this.rot_y_pos, y4+this.rot_y_pos);

                             // 1   2
                             // 4   3
                             this.jg.fillPolygon(Xpoints, Ypoints);
                             this.jg.paint()},
                           // fin ajout fl
                           
                           // ajout fl
                           displayRotationBezierL:function(angle,calc_center,finished){
                             if(this.jgBli==null){return}
                             if((finished)&&(angle==0)){
                               this.jgBli.clear();
                               this.bezierL_widget.src="/images/circle_with_triangle.gif";
                               this.zero_bli_image=true;
                               return
                             }
                             if(calc_center){
                               var pos=Position.cumulativeOffset(this.bezierL_widget);
                               this.bli_x_pos=pos[0]+this.bezierL_widget.width/2;
                               this.bli_y_pos=pos[1]+this.bezierL_widget.height/2
                             }
                             var length=this.bezierL_widget.width/2-2;
                             if(this.zero_bli_image){
                               this.zero_bli_image=false;
                               this.bezierL_widget.src="/images/circle_spacer.gif"
                             }
                             var rads1=this.degToRad(angle-90);
                             var y1=Math.sin(rads1)*length;
                             var x1=Math.cos(rads1)*length;
                             var rads2=this.degToRad(angle-90+90);
                             var y2=Math.sin(rads2)*length/2;
                             var x2=Math.cos(rads2)*length/2;
                             var rads3=this.degToRad(angle-90-90);
                             var y3=Math.sin(rads3)*length/2;
                             var x3=Math.cos(rads3)*length/2;

                             this.jgBli.clear();
                             //this.jgBli.setStroke(3);
                             log("drawline aiguille rotation bezierL");
                             this.jgBli.setColor("#b4b4b4");
                             var x_top_left = fDomOffset(this.bezierL_widget, "offsetLeft");
                             var y_top_left = fDomOffset(this.bezierL_widget, "offsetTop");
                             var width = this.bezierL_widget.width;
                             var height = this.bezierL_widget.height;
                             this.jgBli.fillEllipse(x_top_left, y_top_left, width, height);
                             this.jgBli.paint();
                             
                             // triangle superieur
                             this.jgBli.setColor("#618CBE");
                             //   1
                             // 3   2
                             var X1points = new Array(x1+this.bli_x_pos, x2+this.bli_x_pos, x3+this.bli_x_pos);
                             var Y1points = new Array(y1+this.bli_y_pos, y2+this.bli_y_pos, y3+this.bli_y_pos);
                             this.jgBli.fillPolygon(X1points, Y1points);
                             this.jgBli.paint();
                           },

                           displayRotationBezierR:function(angle,calc_center,finished){
                             if(this.jgBri==null){return}
                             if((finished)&&(angle==0)){
                               this.jgBri.clear();
                               this.bezierR_widget.src="/images/circle_with_triangle.gif";
                               this.zero_bri_image=true;
                               return
                             }
                             if(calc_center){
                               var pos=Position.cumulativeOffset(this.bezierR_widget);
                               this.bri_x_pos=pos[0]+this.bezierR_widget.width/2;
                               this.bri_y_pos=pos[1]+this.bezierR_widget.height/2
                             }
                             var length=this.bezierR_widget.width/2-2;
                             if(this.zero_bri_image){
                               this.zero_bri_image=false;
                               this.bezierR_widget.src="/images/circle_spacer.gif"
                             }
                             var rads1=this.degToRad(angle-90);
                             var y1=Math.sin(rads1)*length;
                             var x1=Math.cos(rads1)*length;
                             var rads2=this.degToRad(angle-90+90);
                             var y2=Math.sin(rads2)*length/2;
                             var x2=Math.cos(rads2)*length/2;
                             var rads3=this.degToRad(angle-90+90+90);
                             var y3=Math.sin(rads3)*length;
                             var x3=Math.cos(rads3)*length;
                             var rads4=this.degToRad(angle-90-90);
                             var y4=Math.sin(rads4)*length/2;
                             var x4=Math.cos(rads4)*length/2;

                             this.jgBri.clear();
                             log("drawline aiguille rotation bezierR");
                             this.jgBri.setColor("#b4b4b4");
                             var x_top_left = fDomOffset(this.bezierR_widget, "offsetLeft");
                             var y_top_left = fDomOffset(this.bezierR_widget, "offsetTop");
                             var width = this.bezierL_widget.width;
                             var height = this.bezierL_widget.height;
                             this.jgBri.fillEllipse(x_top_left, y_top_left, width, height);
                             this.jgBri.paint();

                             // triangle superieur
                             this.jgBri.setColor("#618CBE");
                             //   1
                             // 4   2
                             //   3
                             var X1points = new Array(x1+this.bri_x_pos-1, x2+this.bri_x_pos-1, x4+this.bri_x_pos-1);
                             var Y1points = new Array(y1+this.bri_y_pos-1, y2+this.bri_y_pos-1, y4+this.bri_y_pos-1);
                             this.jgBri.fillPolygon(X1points, Y1points);
                             this.jgBri.paint();
                           },
/*
                           displayRotationTransparency:function(angle,calc_center,finished){
                             if(this.jgTra==null){return}
                             if((finished)&&(angle==0)){
                               this.jgTra.clear();
                               this.transparency_widget.src="/images/circle_with_line.gif";
                               this.zero_tra_image=true;
                               return
                             }
                             if(calc_center){
                               var pos=Position.cumulativeOffset(this.transparency_widget);
                               this.tra_x_pos=pos[0]+this.transparency_widget.width/2;
                               this.tra_y_pos=pos[1]+this.transparency_widget.height/2
                             }
                             var length=this.transparency_widget.width/2-2;
                             if(this.zero_tra_image){
                               this.zero_tra_image=false;
                               this.transparency_widget.src="/images/circle_without_line.gif"
                             }
                             var rads=this.degToRad(angle-90);
                             var y=Math.sin(rads)*length;
                             var x=Math.cos(rads)*length;
                             this.jgTra.clear();
                             this.jgTra.setStroke(1);
                             log("drawline aiguille rotation Transparency angle:" + angle);
                             this.jgTra.setColor("#b4b4b4");
                             this.jgTra.drawLine(this.tra_x_pos+1,this.tra_y_pos+1,x+this.tra_x_pos+1,y+this.tra_y_pos+1);
                             this.jgTra.paint()
                           },
*/
                           degToRad:function(angle){
                             return((angle*Math.PI)/180)},
                             
                           radToDeg:function(angle){
                             return((angle*180)/Math.PI)},
                           
                           hideAbsPanelElements:function(){
                             log ("hideAbsPanelElements");
                             var angle=parseInt(this.rotation_input.value);
                             if(angle!=0){this.jg.clear()}
                             //var angleBezierL=parseInt(this.bezierL_input.value);
                             //if(angleBezierL!=0){this.jgBli.clear()}
                             //var angleBezierR=parseInt(this.bezierR_input.value);
                             //if(angleBezierR!=0){this.jgBri.clear()}
                             /*var angleTransparency=parseInt(this.transparency_input.value);
                             if(angleTransparency!=0){this.jgTra.clear()}*/
                           },

                           showAbsPanelElements:function(){
                             log ("showAbsPanelElements");
                             //alert("showAbsPanelElements this.id:" + this.id);
                             var angle=parseInt(this.rotation_input.value);
                             //var angleBezierL=parseInt(this.bezierL_input.value);
                             //var angleBezierR=parseInt(this.bezierR_input.value);
                             var _this=this;
                             if(_this!=null){
                               //alert("this.managePane.className:"+this.managePane.className);
                               if(this.managePane.className=="managepaneselected"){
                                 if(angle!=0){
                                   window.setTimeout(function(){_this.displayRotation(angle,true,true)},500)
                                 }
                                 //if(angleBezierL!=0){
                                 //  window.setTimeout(function(){_this.displayRotationBezierL(angleBezierL,true,true)},500)
                                 //}
                                 //if(angleBezierR!=0){
                                 //  window.setTimeout(function(){_this.displayRotationBezierR(angleBezierR,true,true)},500)
                                 //}
                               }
                             }
                           },
                           
                           setEtatRotation:function(a_etat){
                             this.etatRotation = a_etat;
                             log("setEtatRotation:" + this.etatRotation);
                           },

                           getEtatRotation:function(){
                             log("getEtatRotation:" + this.etatRotation);
                             return this.etatRotation; 
                           },
                           
                           setRotation:function(sens){
                             log ("setRotation:" + sens);
                             var _this=this;
                             var increment;
                             var valeur;
                             var timer;
                             if (sens == '+'){
                              increment=1;
                             }else{
                              increment=-1;
                             }
                             valeur = parseFloat(_this.rotation_input.value);
                             var somme = eval(valeur + increment);
                             if (somme == 360) somme = 0;
                             if (somme == -1) somme = 359;
                             _this.rotation_input.value = somme;
                             _this.displayRotation(parseInt(_this.rotation_input.value),true,true);

                             if (_this.getEtatRotation() == true){
                                if (sens == '+'){
                                  timer=window.setTimeout(function(){_this.setRotation('+');},200);
                                }else{
                                  timer=window.setTimeout(function(){_this.setRotation('-');},200);
                                }
                             }else{
                                window.clearTimeout(timer);
                                this.updateBlingSrc();
                                return false;
                             }},

                           // ajout fl
                           setEtatRotationBezierL:function(a_etat){
                             this.etatRotationBezierL = a_etat;
                             log("setEtatRotationBezierL:" + this.etatRotationBezierL);
                             //return false; 
                           },

                           getEtatRotationBezierL:function(){
                             log("getEtatRotationBezierL:" + this.etatRotationBezierL);
                             return this.etatRotationBezierL; 
                           },

                           setRotationBezierL:function(sens){
                             log ("setRotationBezierL:" + sens);
                             var _this=this;
                             var increment;
                             var valeur;
                             var timer;
                             if (sens == '+'){
                              increment=1;
                             }else{
                              increment=-1;
                             }
                             valeur = parseFloat(_this.bezierL_input.value);
                             var somme = eval(valeur + increment);
                             if (somme == 360) somme = 0;
                             if (somme == -1) somme = 359;
                             _this.bezierL_input.value = somme;
                             _this.displayRotationBezierL(parseInt(_this.bezierL_input.value),true,true);

                             if (_this.getEtatRotationBezierL() == true){
                                if (sens == '+'){
                                  timer=window.setTimeout(function(){_this.setRotationBezierL('+');},200);
                                }else{
                                  timer=window.setTimeout(function(){_this.setRotationBezierL('-');},200);
                                }
                             }else{
                                window.clearTimeout(timer);
                                this.updateBlingSrc();
                                return false;
                             }},

                           setEtatRotationBezierR:function(a_etat){
                             this.etatRotationBezierR = a_etat;
                             log("setEtatRotationBezierR:" + this.etatRotationBezierR);
                             //return false; 
                           },

                           getEtatRotationBezierR:function(){
                             log("getEtatRotationBezierR:" + this.etatRotationBezierR);
                             return this.etatRotationBezierR; 
                           },

                           setRotationBezierR:function(sens){
                             log ("setRotationBezierR:" + sens);
                             var _this=this;
                             var increment;
                             var valeur;
                             var timer;
                             if (sens == '+'){
                              increment=1;
                             }else{
                              increment=-1;
                             }
                             valeur = parseFloat(_this.bezierR_input.value);
                             var somme = eval(valeur + increment);
                             if (somme == 360) somme = 0;
                             if (somme == -1) somme = 359;
                             _this.bezierR_input.value = somme;
                             _this.displayRotationBezierR(parseInt(_this.bezierR_input.value),true,true);

                             if (_this.getEtatRotationBezierR() == true){
                                if (sens == '+'){
                                  timer=window.setTimeout(function(){_this.setRotationBezierR('+');},200);
                                }else{
                                  timer=window.setTimeout(function(){_this.setRotationBezierR('-');},200);
                                }
                             }else{
                                window.clearTimeout(timer);
                                this.updateBlingSrc();
                                return false;
                             }},

                           setTransparency:function(){
                             if(this.transparency_input.value==""){
                               var trans=0
                             }else{
                               var trans=parseFloat(this.transparency_input.value)
                               log ("trans:" + trans);
                             }
                             if((useAlphaHack)&&(!this.usingGIF)){
                               this.updateBlingSrc();
                               log ("trans updateBlingSrc:" + trans);
                             }else{
                               log ("trans else:" + trans);
                               trans=trans/100;trans=1-trans;
                               var t1=new Effect.Opacity(this.el,{duration:0.2,to:trans});
                               var _this=this;
                               var t2=new Draggable(_this.el.id,{revert:false,change:function(dragable){_this.moving(dragable)},endeffect:function(element){var t1=new Effect.Opacity(element,{duration:0.2,from:0.7,to:trans})}})
                             }},
                           
                           setEtatRotationTransparency:function(a_etat){
                             this.etatRotationTransparency = a_etat;
                             log("setEtatRotationTransparency:" + this.etatRotationTransparency);
                             //return false; 
                           },

                           getEtatRotationTransparency:function(){
                             log("getEtatRotationTransparency:" + this.etatRotationTransparency);
                             return this.etatRotationTransparency; 
                           },

                           setRotationTransparency:function(sens){
                             log ("setRotationTransparency:" + sens);
                             var _this=this;
                             var increment;
                             var valeur;
                             var timer;
                             var rotation;
                             if (sens == '+'){
                              increment=1;
                             }else{
                              increment=-1;
                             }
                             valeur = parseFloat(_this.transparency_input.value);
                             var somme = eval(valeur + increment);
                             if (somme <= 0) somme = 0;
                             if (somme >= 100) somme = 100;
                             log ("somme:"+somme);
                             _this.transparency_input.value = somme;
                             //_this.displayRotationTransparency(parseInt(_this.transparency_input.value),true,true);
                             //_this.displayRotationTransparency(parseInt(somme*3,6+3,6),true,true);

                             if (_this.getEtatRotationTransparency() == true){
                                if (sens == '+'){
                                  timer=window.setTimeout(function(){_this.setRotationTransparency('+');},200);
                                }else{
                                  timer=window.setTimeout(function(){_this.setRotationTransparency('-');},200);
                                }
                             }else{
                                window.clearTimeout(timer);
                                this.setTransparency();
                                return false;
                             }},

                           flip:function(){
                             var rot=parseFloat(this.rotation_input.value);
                             // ajout fl
                             //var bli=parseFloat(this.bezierL_input.value);
                             //var bri=parseFloat(this.bezierR_input.value);
                             // fin ajout fl
                             var trans=0;
                             log("flipState:" + this.flipState);
                             // cas initial
                             if(this.flipState==""){
                               this.flipState="H"}
                             // cas = H retour ŕ l'origine
                             else if(this.flipState=="H"){
                               this.flipState="O"}
                             // cas = O
                             else if(this.flipState=="O"){
                               this.flipState="H"
                             }
                             this.updateBlingSrc();
                             return false},

                           updateBlingSrc:function(){
                             var rot=parseFloat(this.rotation_input.value);
                             // ajout fl
                             //var bli=parseFloat(this.bezierL_input.value);
                             //var bri=parseFloat(this.bezierR_input.value);
                             // fin ajout fl

                             var trans=parseFloat(this.transparency_input.value);
                             log ("trans 2:" + trans);
                             //if(trans!=0){if(useAlphaHack){useFast=false}}
                             var effects="";
                             /*if(this.usesEffects()){
                               effects=this.serializeBlingEffects();
                               if(effects!=""){useFast=false}
                             }*/
                             var url="";
//                             url="/home/rot.php?id="+this.bling_id+"&deg="+rot+"&trans="+trans+"&flip="+this.flipState+"&"+effects
// ajout franck
                             //url="trans.php?id="+this.bling_id+"&deg="+rot+"&trans="+trans+"&flip="+this.flipState+"&bli="+bli+"&bri="+bri
                             url="trans.php?id="+this.bling_id+"&deg="+rot+"&trans="+trans+"&flip="+this.flipState;
// fin ajout franck
                             if((useAlphaHack)&&(!this.usingGIF)){
                               this.el.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+url+"', sizingMethod='scale')"
                             }else{
                               log("url:" + url);
                               startAsyncAction();
                               var _el=this.el;
                               this.el.onload=function(){finishAsyncAction()};
                               this.el.src=url;
                               this.el.height=this.el.height;
                               this.el.width=this.el.width
                             }},
                             
                           serialize:function(queryComponents,prefix){
                             log ("serialize2");
                             if(prefix==null){prefix="bling"}
                             if(queryComponents==null){queryComponents=new Array()}
                             ImgBling.parentClass.method("serialize").call(this,queryComponents,prefix);
                             var rot=parseFloat(this.rotation_input.value);
                             // ajout fl
                             //var bli=parseFloat(this.bezierL_input.value);
                             //var bri=parseFloat(this.bezierR_input.value);
                             // fin ajout fl
                             var trans=parseFloat(this.transparency_input.value);
                             queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][rot]")+"="+encodeURIComponent(rot));
                             queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][trans]")+"="+encodeURIComponent(trans));
                             queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][flip]")+"="+encodeURIComponent(this.flipState));
                             //queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][bli]")+"="+encodeURIComponent(bli));
                             //queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][bri]")+"="+encodeURIComponent(bri));
                             },
                             
                           hide:function(){
                             ImgBling.parentClass.method("hide").call(this);
                             this.rotation_input.disabled=true;
                             // ajout fl
                             //this.bezierL_input.disabled=true;
                             //this.bezierR_input.disabled=true;
                             // fin ajout fl
                             this.transparency_input.disabled=true;
                           },
                             
                           restore:function(){
                             ImgBling.parentClass.method("restore").call(this);
                             this.rotation_input.disabled=false;
                             // ajout fl
                             //this.bezierL_input.disabled=false;
                             //this.bezierR_input.disabled=false;
                             // fin ajout fl
                             this.transparency_input.disabled=false;
                           },
                             
                           del:function(){
                             
                             if(this.jg!=null){
                               this.jg.clear();
                               this.jg=null;
                               if(this.rot_canvas!=null){
                                 try{document.body.removeChild(this.rot_canvas)}catch(ex){}
                               }
                             }
                             if(this.jgBli!=null){
                               this.jgBli.clear();
                               this.jgBli=null;
                               if(this.bli_canvas!=null){
                                 try{document.body.removeChild(this.bli_canvas)}catch(ex){}
                               }
                             }
                             if(this.jgBri!=null){
                               this.jgBri.clear();
                               this.jgBri=null;
                               if(this.bri_canvas!=null){
                                 try{document.body.removeChild(this.bri_canvas)}catch(ex){}
                               }
                             }
                             /*if(this.jgTra!=null){
                               this.jgTra.clear();
                               this.jgTra=null;
                               if(this.transparency_canvas!=null){
                                 try{document.body.removeChild(this.transparency_canvas)}catch(ex){}
                               }
                             }*/
                             ImgBling.parentClass.method("del").call(this);
                           },
                             
                           updateBling:function(){
                             this.updateBlingSrc()}});

// class utilitaire
var SpeechBling=Class.create({CLASSDEF:{name:'SpeechBling',parent:Bling},
                             
                             initialize:function(element,pp,opts,bling_id,bling_type,thumb_factor){
                               log("class SpeechBling");
                               this.original_icon=opts["original_icon"];
                               this.offset_x=parseInt(opts["ox"]);
                               this.offset_y=parseInt(opts["oy"]);
                               this.editor=$(opts["editor"]);
                               this.mode=$(opts["mode"]);
                               if(this.mode==null){this.mode=0}
                               log("mode = "+this.mode);
                               this.parentCall("initialize",element,pp,opts,bling_id,bling_type,thumb_factor);
                               if(this.editor!=null){
                                 if(this.editor.tagName=="IFRAME"){
                                   this.eventKeyUp=this.keyup.bindAsEventListener(this);
                                   this.eventIFrameMouseUp=this.iframeMouseUp.bindAsEventListener(this);
                                   Event.observe(this.editor.contentDocument,"keyup",this.eventKeyUp);
                                   Event.observe(this.editor.contentDocument,"mouseup",this.eventIFrameMouseUp);
                                   this.editDiv=this.editor.contentDocument.getElementById("edit");
                                   this.editBody=this.editor.contentDocument.body;
                                   this.keyup()
                                 }else{
                                   this.eventKeyUp=this.basicKeyup.bindAsEventListener(this);
                                   this.mouseDownInEditorEvt=this.mouseDownInEditor.bindAsEventListener(this);
                                   Event.observe(this.editor,"keyup",this.eventKeyUp);
                                   Event.observe(this.editor,"mousedown",this.mouseDownInEditorEvt)
                                 }
                               }else{
                                 log("NO EDITOR")
                               }
                               if(this.mode==1){
                                 log("building bubbles");
                                 this.bubbles={};
                                 this.bubbles["L"]=this.setupBubble("sb_left");
                                 this.bubbles["R"]=this.setupBubble("sb_right");
                                 this.bubbles["T"]=this.setupBubble("sb_top");
                                 this.bubbles["B"]=this.setupBubble("sb_bottom");
                                 this.bubbles["10"]=this.setupBubble("sb_10");
                                 this.bubbles["20"]=this.setupBubble("sb_20");
                                 log("bubbles built")
                               }
                               this.sbt=opts["sbt"];
                               this.sbl=opts["sbl"];
                               this.sbr=opts["sbr"];
                               this.sbb=opts["sbb"];
                               this.canvas=document.createElement("DIV");
                               this.canvas.id=pp.nextId();
                               this.editor_td=$(opts["editor_td"]);
                               document.body.appendChild(this.canvas);
                               this.jg=new jsGraphics(this.canvas);
                               if(this.editor!=null){
                                 if(opts["font"]!=null){
                                   this.font_input.value=opts["font"]
                                 }
                                 if(opts["text"]!=null){
                                   this.text_input.value=opts["text"]
                                 }
                                 if(opts["fs"]!=null){
                                   this.fs_input.value=opts["fs"]
                                 }
                                 if(opts["b"]!=null){
                                   if(opts["b"]=="true"){
                                     this.b_input.checked=true
                                   }else{
                                     this.b_input.checked=false
                                   }
                                 }
                                 if(opts["i"]!=null){
                                   if(opts["i"]=="true"){
                                     this.i_input.checked=true
                                   }else{
                                     this.i_input.checked=false
                                   }
                                 }
                                 this.setText()
                               }
                               this.positionChanged(true);
                               if(opts["on_image"]==true){
                                 this.setHeight(parseInt(this.el.style.height));
                                 this.setWidth(parseInt(this.el.style.width));
                                 this.fast_draw=false;
                                 log("draw1");
                                 this.draw()
                               }},
                               
                             setupBubble:function(from_id){
                               var srcImg=$(from_id);
                               if((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<7.0)&&(BrowserDetect.version>=5.5)){
                                 var newB=document.createElement("SPAN");
                                 newB.style.position="absolute";
                                 newB.style.display="none";
                                 newB.style.fontSize="1px";
                                 newB.style.width=srcImg.style.width;newB.style.height=srcImg.style.height;
                                 newB.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+srcImg.src+"', sizingMethod='scale')";
                                 newB.id=this.pp.nextId();
                                 document.body.appendChild(newB);
                                 return newB
                               }else{
                                 var newB=document.createElement("IMG");
                                 newB.src=srcImg.src;
                                 newB.width=parseFloat(srcImg.style.width);
                                 newB.height=parseFloat(srcImg.style.height);
                                 newB.style.position="absolute";
                                 newB.style.display="none";
                                 newB.id=this.pp.nextId();
                                 document.body.appendChild(newB);
                                 return newB}
                               },
                               
                             positionChanged:function(update){
                               var dims=this.getDims();
                               var changed=false;
                               if(this.old_t!=dims[0]){
                                 changed=true
                               }else
                                 if(this.old_l!=dims[1]){
                                   changed=true
                                 }else if(this.old_h!=dims[2]){
                                   changed=true
                                 }else if(this.old_w!=dims[3]){
                                   changed=true
                                 }if(update){
                                   this.old_t=dims[0];
                                   this.old_l=dims[1];
                                   this.old_h=dims[2];
                                   this.old_w=dims[3]
                                 }
                                 return changed
                               },
                                 
                             keyup:function(event){
                               if((this.editBody.firstChild!=null)&&(this.editBody.firstChild.nodeType==1)&&(this.editBody.firstChild.tagName=="SPAN")){
                                 this.editDiv.innerHTML=this.editBody.firstChild.innerHTML
                               }
                               var dims=Element.getDimensions(this.editDiv);
                               log(dims);
                               this.editor.width=dims.width;
                               this.editor.height=dims.height;
                               dims=this.getDims();
                               var t=dims[0];
                               var l=dims[1];
                               var h=dims[2];
                               var w=dims[3];
                               log("repositionHandles");
                               this.repositionHandles("",t,l,h,w);
                               log("repositionHandles DONE");
                               if(this.positionChanged(true)){
                                 this.setHeight(h);
                                 this.setWidth(w);
                                 log("draw2");
                                 this.draw()
                               }
                               var span=this.editDiv;
                               if((span!=null)&&(span.nodeType==1)){
                                 var txt=new String(span.innerHTML);
                                 var re=new RegExp("<br[ ]?[/]?>","g");
                                 txt=txt.replace(re,"\n");
                                 txt=txt.unescapeHTML();
                                 this.text_input.value=txt
                               }
                             },
                             
                             basicKeyup:function(event){
                               log("basickeyup");
                               var dims=this.getDims();
                               var t=dims[0];
                               var l=dims[1];
                               var h=dims[2];
                               var w=dims[3];
                               log("repositionHandles");
                               this.repositionHandles("",t,l,h,w);
                               log("repositionHandles DONE");
                               if(this.positionChanged(true)){
                                 this.setHeight(h);
                                 this.setWidth(w);
                                 log("draw3");
                                 this.draw()
                               }
                               this.text_input.value=this.editor.innerText
                             },
                             
                             iframeMouseUp:function(event){
                               log("iframeMouseUp");
                               if(this.isResizing){
                                 this.resizeFinished()
                               }else if(this.isMoving){
                                 Draggables.endDrag(event)
                               }
                             },
                             
                             mouseDownInEditor:function(event){
                               Event.stop(event);
                               return false
                             },
                             
                             copy:function(extraOpts){
                               var re=new RegExp("\\[ID\\]","g");
                               var id=this.pp.nextId();
                               var html=bubble_html;
                               if((this.mode==0)||(this.mode==1)||(this.mode==2)){
                                 if((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<7.0)&&(BrowserDetect.version>=5.5)){
                                   html=bubble_html_ie
                                 }
                               }else if(this.mode==3){html=box_html
                               }else{html=text_html}
                               var html=html.replace(re,id);
                               var t1=new Insertion.Bottom(document.body,html);
                               var el=$("sb_"+id);var editor_td=$(id+"_editor");
                               if(extraOpts!=null){
                                 el.style.left=this.pp.to_x(parseInt(extraOpts["x"]))+"px";el.style.top=this.pp.to_y(parseInt(extraOpts["y"]))+"px";
                                 el.style.width=extraOpts["w"]+"px";
                                 el.style.height=extraOpts["h"]+"px";
                                 el.style.position="absolute"
                               }else{
                                 var pos=Position.cumulativeOffset(this.el);
                                 el.style.left=pos[0]+"px";
                                 el.style.top=pos[1]+"px";
                                 el.style.position="absolute"
                               }
                               el.style.opacity="";
                               el.style.filter="";
                               el.style.display="";
                               var editor=null;
                               if(BrowserDetect.browser=="Explorer"){
                                 editor=document.createElement("DIV");
                                 editor.contentEditable=true;
                                 editor.style.whiteSpace="nowrap";
                                 editor.innerHTML="Bubble Text";
                                 editor.setAttribute("allow-delete","true");
                                 editor_td.appendChild(editor)
                               }else if(BrowserDetect.browser=="Firefox"){
                                 editor=this.buildIFrameEditor(editor_td)
                               }else{
                                 editor=document.createElement("DIV");
                                 editor.style.whiteSpace="nowrap";
                                 editor.innerHTML="Bubble Text";
                                 editor.setAttribute("allow-delete","true");
                                 editor_td.appendChild(editor)
                               }
                               if(extraOpts==null){
                                 extraOpts={ox:this.offset_x,oy:this.offset_y,on_image:true,editor:editor,original_icon:this.el,mode:this.mode,editor_td:editor_td,tn_image:this.tn_image}
                               }else{
                                 extraOpts["on_image"]=true;
                                 extraOpts["editor"]=editor;
                                 extraOpts["original_icon"]=this.el;
                                 extraOpts["editor_td"]=editor_td;extraOpts["tn_image"]=this.tn_image
                               }
                               extraOpts["sbt"]=$("sbt_"+id);extraOpts["sbl"]=$("sbl_"+id);
                               extraOpts["sbr"]=$("sbr_"+id);extraOpts["sbb"]=$("sbb_"+id);
                               return new SpeechBling(el,this.pp,extraOpts,this.bling_id,this.bling_type,this.thumb_factor)
                             },
                             
                             bindPanel:function(panel,id){
                               this.parentCall("bindPanel",panel,id);
                               var obj=$("mp_"+id+"_img");
                               var tnWidth=this.tn_image.width;
                               var tnHeight=this.tn_image.height;
                               if(useAlphaHack){
                                 tnWidth=parseInt(this.tn_image.style.width);
                                 tnHeight=parseInt(this.tn_image.style.height)
                               }
                               if((tnWidth>iconWidth)||(tnHeight>iconWidth)){
                                 var ratio=tnWidth/tnHeight;
                                 if(tnWidth>tnHeight){
                                   tnWidth=iconWidth;
                                   tnHeight=iconWidth/ratio
                                 }else{
                                   tnHeight=iconWidth;
                                   tnWidth=iconWidth*ratio
                                 }
                               }
                               if(useAlphaHack){
                                 obj.src="/images/sb/trans.gif";
                                 obj.style.width=tnWidth;
                                 obj.style.height=tnHeight;
                                 obj.style.display="inline-block";
                                 obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.tn_image.src+"', sizingMethod='scale')"
                               }else{
                                 obj.src=this.tn_image.src;obj.width=tnWidth;
                                 obj.height=tnHeight
                               }
                               var _this=this;
                               this.text_input=$("mp_"+id+"_text");
                               this.text_input.onkeyup=function(el){_this.setText()};
                               this.font_input=$("mp_"+id+"_font");
                               this.font_input.onchange=function(el){_this.setText()};
                               for(var i=0;i<fonts.length;i++){
                                 var opt=document.createElement("OPTION");
                                 opt.text=fonts[i];
                                 opt.value=fonts[i];
                                 if(BrowserDetect.browser=="Explorer"){
                                   this.font_input.options.add(opt)
                                 }else{
                                   this.font_input.appendChild(opt)
                                 }
                               }
                               this.fs_input=$("mp_"+id+"_fs");
                               this.fs_input.onkeyup=function(el){_this.setText()};
                               this.b_input=$("mp_"+id+"_b");
                               this.b_input.onclick=function(el){_this.setText()};
                               this.i_input=$("mp_"+id+"_i");
                               this.i_input.onclick=function(el){_this.setText()}
                             },
                             
                             setText:function(){
                               log("set text");
                               if(this.fs_input.value==""){return}
                               if(this.editor.tagName=="IFRAME"){
                                 if((this.editBody.firstChild!=null)&&(this.editBody.firstChild.nodeType==1)&&(this.editBody.firstChild.tagName=="SPAN")){
                                   this.editBody.removeChild(this.editBody.firstChild)
                                 }
                                 this.editDiv.style.fontFamily=this.font_input.value;
                                 this.editDiv.style.fontSize=this.fs_input.value+"px";
                                 if(this.b_input.checked){
                                   this.editDiv.style.fontWeight="bold"
                                 }else{
                                   this.editDiv.style.fontWeight="normal"
                                 }
                                 if(this.i_input.checked){
                                   this.editDiv.style.fontStyle="italic"
                                 }else{
                                   this.editDiv.style.fontStyle=""
                                 }
                                 var txt=new String(this.text_input.value);
                                 var re=new RegExp("\n","g");
                                 txt=txt.replace(re,"___BR___");
                                 txt=txt.escapeHTML();
                                 var re=new RegExp("___BR___","g");
                                 txt=txt.replace(re,"<br />");
                                 this.editDiv.innerHTML=txt;
                                 var dims=Element.getDimensions(this.editDiv);
                                 this.editor.width=dims.width;
                                 this.editor.height=dims.height
                               }else{
                                 var html='<span style="font-family:'+this.font_input.value+'; font-size:'+this.fs_input.value+'px;">';
                                 if(this.b_input.checked){html+="<b>"}
                                 if(this.i_input.checked){html+="<i>"}
                                 var txt=new String(this.text_input.value);
                                 var re=new RegExp("\n","g");
                                 txt=txt.replace(re,"___BR___");
                                 txt=txt.escapeHTML();
                                 var re=new RegExp("___BR___","g");
                                 txt=txt.replace(re,"<br />");
                                 html+=txt;
                                 if(this.b_input.checked){html+="</b>"}
                                 if(this.i_input.checked){html+="</i>"}
                                 html+="</span>";
                                 this.editor.innerHTML=html
                               }
                               if(this.positionChanged(true)){
                                 var dims=this.getDims();
                                 var t=dims[0];
                                 var l=dims[1];
                                 var h=dims[2];
                                 var w=dims[3];
                                 this.repositionHandles("",t,l,h,w);
                                 log("draw4");
                                 this.draw()
                               }
                             },
                             
                             getDims:function(){
                               var h=parseFloat(this.el.style.top);
                               var l=parseFloat(this.el.style.left);
                               var dims=Element.getDimensions(this.el);
                               return[parseFloat(this.el.style.top),parseFloat(this.el.style.left),dims.height,dims.width]
                             },
                             
                             setHeight:function(height){
                               if(height<=0){height=10}
                               this.el.style.height=height+"px";
                               log("setting sb height="+height);
                               var gap=PPBubbleGap;
                               if(this.mode==4){gap=40}
                               else if(this.mode==3){gap=6}
                               else{gap=12}
                               if(this.editor_td!=null){
                                 if((height-gap)>10){
                                   this.editor_td.style.height=(height-gap)+"px";
                                   log("setting sb td height="+(height-gap))
                                 }else{
                                   this.editor_td.style.height="10px"
                                 }
                               }
                               if(this.sbt!=null){
                                 this.sbl.height=(height-24);
                                 this.sbr.height=(height-24)
                               }
                               var noFixing=true;
                               var dims=Element.getDimensions(this.el);
                               if(height!=dims.height){
                                 log("fixing sb height to "+dims.height);
                                 if(this.editor_td!=null){
                                   if((dims.height-gap)>10){
                                     this.editor_td.style.height=(dims.height-gap)+"px"
                                   }else{
                                     this.editor_td.style.height="10px"
                                   }
                                 }
                                 if(this.sbt!=null){
                                   this.sbl.height=(dims.height-24);
                                   this.sbr.height=(dims.height-24)
                                 }
                                 noFixing=false
                               }
                               return noFixing
                             },
                             
                             setWidth:function(width){
                               if(width<=0){width=10}
                               this.el.style.width=width+"px";
                               var gap=PPBubbleGap;
                               if(this.mode==4){gap=40}
                               else if(this.mode==3){gap=6}
                               if(this.editor_td!=null){
                                 if((width-gap)>10){
                                   this.editor_td.style.width=(width-gap)+"px"
                                 }else{
                                   this.editor_td.style.width="10px"
                                 }
                               }
                               if(this.sbt!=null){
                                 this.sbt.width=(width-24);
                                 this.sbb.width=(width-24)
                               }
                               var dims=Element.getDimensions(this.el);
                               if(width!=dims.width){
                                 if(this.editor_td!=null){
                                   if((dims.width-gap)>10){
                                     this.editor_td.style.width=(dims.width-gap)+"px"
                                   }else{
                                     this.editor_td.style.width="10px"
                                   }
                                   if(this.sbt!=null){
                                     this.sbt.width=(dims.width-24);
                                     this.sbb.width=(dims.width-24)
                                   }
                                 }
                                 return false
                               }
                               return true
                             },
                           
                             buildIFrameEditor:function(parent){
                               var iFrame=document.createElement("IFRAME");
                               parent.appendChild(iFrame);
                               iFrame.setAttribute("border","0");
                               iFrame.setAttribute("frameBorder","0");
                               iFrame.setAttribute("marginWidth","0");
                               iFrame.setAttribute("marginHeight","0");
                               iFrame.setAttribute("leftMargin","0");
                               iFrame.setAttribute("topMargin","0");
                               iFrame.setAttribute("scrolling","no");
                               try{
                                 iFrame.contentWindow.document.open();
                                 iFrame.contentWindow.document.write('<HTML><BODY style="width: 300px;"><table _moz_resizing="false" border="0" cellpadding="0" cellspacing="0"><tr><td align="center"><span id="edit" allow-delete="true">Bubble Text</span></td></tr></table></BODY></HTML>');
                                 iFrame.contentWindow.document.close();
                                 iFrame.contentDocument.designMode="on";
                                 iFrame.contentDocument.execCommand("enableObjectResizing",false,"false");
                                 iFrame.contentDocument.execCommand("enableInlineTableEditing",false,"false")
                               }catch(e){
                                 iFrame.contentWindow.document.location.href="blank.htm"
                               }
                               iFrame.width="50";
                               iFrame.height="50";
                               return iFrame
                             },
                             
                             select:function(){
                               this.parentCall("select");
                               log("draw5");
                               this.draw();
                               if(this.editor.tagName=="IFRAME"){
                                 this.editor.contentDocument.execCommand("enableObjectResizing",false,"false");
                                 this.editor.contentDocument.execCommand("enableInlineTableEditing",false,"false")
                               }
                             },
                             
                             setRolloverStyle:function(){
                               if(this.mode==4){
                                 if((BrowserDetect.browser=="Explorer")||(BrowserDetect.browser=="Opera")){
                                   this.el.style.borderStyle="dotted";
                                   this.el.style.borderWidth="1px";
                                   this.el.style.borderColor="black"
                                 }else{
                                   this.el.style.outlineStyle="dotted";
                                   this.el.style.outlineWidth="1px";
                                   this.el.style.outlineColor="invert"
                                 }
                               }
                             },
                             
                             setLeaveStyle:function(){
                               if(this.mode==4){
                                 if((BrowserDetect.browser=="Explorer")||(BrowserDetect.browser=="Opera")){
                                   this.el.style.borderStyle="none";
                                   this.el.style.borderWidth="0px"
                                 }else{
                                   this.el.style.outlineWidth="0px"
                                 }
                               }
                             },
                             
                             setSelectStyle:function(){
                               if(this.mode==4){
                                 if((BrowserDetect.browser=="Explorer")||(BrowserDetect.browser=="Opera")){
                                   this.el.style.borderStyle="solid";
                                   this.el.style.borderWidth="1px";
                                   this.el.style.borderColor="black"
                                 }else{
                                   this.el.style.outlineStyle="solid";
                                   this.el.style.outlineWidth="1px";
                                   this.el.style.outlineColor="invert"
                                 }
                               }
                             },
                             
                             deselect:function(){
                               this.parentCall("deselect");
                               log("draw6");
                               this.draw()
                             },
                             
                             moveStarted:function(){
                               this.parentCall("moveStarted");
                               this.clear()
                             },
                             
                             moveFinished:function(){
                               this.parentCall("moveFinished");
                               log("draw7");
                               this.draw()
                             },
                             
                             resizeFinished:function(event){
                               this.parentCall("resizeFinished");
                               log("draw8");
                               this.draw()
                             },
                             
                             addHandles:function(){
                               log("ss addHandles");
                               this.parentCall("addHandles");
                               if((this.mode==0)||(this.mode==1)){
                                 var dims=this.getDims();
                                 var t=dims[0];
                                 var l=dims[1];
                                 var h=dims[2];
                                 var w=dims[3];
                                 this.speech_sizer=this.buildSizer("nw-resize","SS");
                                 this.positionHandle(this.speech_sizer,"SS",t,l,h,w);
                                 this.speech_sizer.style.display=""
                               }
                             },
                             
                             positionHandle:function(sizer,pos,t,l,h,w){
                               if(pos=="SS"){
                                 sizer.style.left=(l+w+this.offset_x-PPSizerHalf)+"px";sizer.style.top=(t+h+this.offset_y-PPSizerHalf)+"px"
                               }else{
                                 this.parentCall("positionHandle",sizer,pos,t,l,h,w)
                               }
                             },
                             
                             removeHandles:function(){
                               if(this.speech_sizer!=null){
                                 document.body.removeChild(this.speech_sizer);
                                 this.speech_sizer=null;
                                 this.sizers["SS"]=null
                               }
                               this.parentCall("removeHandles")},
                               
                             handleResizeStart:function(event){
                               var currentSizer=Event.element(event);
                               var pm=currentSizer.positioning_mode;
                               if(pm=="SS"){
                                 this.resizeSSStart(event);
                                 return true
                               }
                               this.clear();
                               return false},
                               
                             resizeSSStart:function(event){
                               log("resizeSSStart");
                               this.eventSSResizeMouseUp=this.resizeSSFinished.bindAsEventListener(this);
                               this.eventSSResizeMouseMove=this.resizeSSMove.bindAsEventListener(this);
                               Event.observe(document,"mouseup",this.eventSSResizeMouseUp);
                               Event.observe(document,"mousemove",this.eventSSResizeMouseMove);
                               Event.stop(event);
                               return false},
                             
                             resizeSSMove:function(event){
                               var pointer=[Event.pointerX(event),Event.pointerY(event)];
                               if(this._lastPointer&&(this._lastPointer.inspect()==pointer.inspect()))return false;
                               this._lastPointer=pointer;
                               this.speech_sizer.style.left=(pointer[0]-PPSizerHalf)+"px";
                               this.speech_sizer.style.top=(pointer[1]-PPSizerHalf)+"px";
                               var dims=this.getDims();
                               var t=dims[0];
                               var l=dims[1];
                               var h=dims[2];
                               var w=dims[3];
                               this.offset_x=pointer[0]-l-w;
                               this.offset_y=pointer[1]-t-h;
                               this.fast_draw=true;
                               log("draw9");
                               this.draw();
                               return false},
                               
                             resizeSSFinished:function(event){
                               log("resizeSSFinished");
                               this._lastPointer=null;
                               Event.stopObserving(document,"mouseup",this.eventSSResizeMouseUp);
                               Event.stopObserving(document,"mousemove",this.eventSSResizeMouseMove);
                               this.fast_draw=false;
                               log("draw10");
                               this.draw();
                               return false},
                               
                             sizedFromPane:function(){
                               log("draw11");
                               this.draw()},
                               
                             draw:function(){
                               if(this.jg==null){return}this.clear();
                               if(this.hidden==true){return}
                               var dims=this.getDims();
                               var t=dims[0];
                               var l=dims[1];
                               var h=dims[2];
                               var w=dims[3];
                               var c_x=l+(w/2);
                               var c_y=t+(h/2);
                               var s_x=l+w+this.offset_x;
                               var s_y=t+h+this.offset_y;
                               if(this.is_inside(s_x,s_y,t,l,w,h)){return}
                               var plane=null;
                               var intersect=null;
                               var direction=0;
                               var delta_x=0;
                               var delta_y=0;
                               var position="";
                               var fix_delta=-2;
                               if(BrowserDetect.browser=="Explorer"){}
                               if(this.inHeight){
                                 if(s_x<l){
                                   plane=[l,t,l,t+h];
                                   position="L"
                                 }else{
                                   plane=[l+w,t,l+w,t+h];delta_x=fix_delta;position="R"
                                 }
                                 direction=1
                               }else if(this.inWidth){
                                 if(s_y<t){
                                   plane=[l,t,l+w,t];
                                   position="T"
                                 }else{
                                   plane=[l,t+h,l+w,t+h];
                                   delta_y=fix_delta;
                                   position="B"
                                 }
                               }else{
                                 if(s_y<t){
                                   plane=[l,t,l+w,t];
                                   intersect=this.get_intersection(c_x,c_y,s_x,s_y,plane[0],plane[1],plane[2],plane[3]);
                                   if(intersect[0]>l&&intersect[0]<(l+w)){
                                     position="T"
                                   }else{
                                     intersect=null;
                                     plane=null
                                   }
                                 }else{
                                   plane=[l,t+h,l+w,t+h];
                                   intersect=this.get_intersection(c_x,c_y,s_x,s_y,plane[0],plane[1],plane[2],plane[3]);
                                   if(intersect[0]>l&&intersect[0]<(l+w)){
                                     delta_y=fix_delta;position="B"
                                   }else{
                                     intersect=null;
                                     plane=null
                                   }
                                 }
                                 if(plane==null){
                                   if(s_x<l){
                                     plane=[l,t,l,t+h];
                                     position="L"
                                   }else{
                                     plane=[l+w,t,l+w,t+h];
                                     delta_x=fix_delta;position="R"
                                   }
                                   direction=1
                                 }
                               }
                               if(intersect==null){
                                 intersect=this.get_intersection(c_x,c_y,s_x,s_y,plane[0],plane[1],plane[2],plane[3])
                               }
                               if(intersect==null){
                                 log("NULL INTERSECT.. SHOULD NEVER HAPPEN!!!!");
                                 return
                               }
                               var points=null;
                               var bwidth=PPBubbleWidthHalf;
                               if(direction==0){
                                 if((plane[2]-plane[0]-PPBubbleGap)<PPBubbleWidth){
                                   bwidth=(plane[2]-plane[0]-PPBubbleGap)/2;intersect[0]=(plane[2]+plane[0])/2
                                 }else{
                                   if(intersect[0]-plane[0]<PPBubbleGap){
                                     intersect[0]=plane[0]+PPBubbleGap
                                   }else if(plane[2]-intersect[0]<PPBubbleGap){
                                     intersect[0]=plane[2]-PPBubbleGap
                                   }
                                 }
                                 points=[intersect[0]-bwidth,intersect[1],intersect[0]+bwidth,intersect[1]]
                               }else{
                                 if((plane[3]-plane[1]-PPBubbleGap)<PPBubbleWidth){
                                   bwidth=(plane[3]-plane[1]-PPBubbleGap)/2;
                                   intersect[1]=(plane[3]+plane[1])/2;
                                   log("shrinking:"+plane[3]+" - "+plane[1]+" - "+PPBubbleGap+" < "+PPBubbleWidth)
                                 }else{
                                   log("fine:"+plane[3]+" - "+plane[1]+" - "+PPBubbleGap+" >= "+PPBubbleWidth);
                                   if(intersect[1]-plane[1]<PPBubbleGap){
                                     intersect[1]=plane[1]+PPBubbleGap
                                   }else if(plane[3]-intersect[1]<PPBubbleGap){
                                     intersect[1]=plane[3]-PPBubbleGap
                                   }
                                 }
                                 points=[intersect[0],intersect[1]-bwidth,intersect[0],intersect[1]+bwidth]
                               }
                               var useZ=this.z+1;
                               if(this.selected){
                                 this.jg.setZIndex(1001);
                                 useZ=1001
                               }else{
                                 this.jg.setZIndex(this.z+1)
                               }
                               points[0]+=delta_x;
                               points[1]+=delta_y;
                               points[2]+=delta_x;
                               points[3]+=delta_y;
                               if(this.mode==0){
                                 this.jg.setStroke(2);
                                 if(!this.fast_draw){
                                   this.jg.setColor("#FFFFFF");
                                   this.jg.fillPolygon([points[0],points[2],s_x],[points[1],points[3],s_y]);
                                   this.jg.setStroke(3);
                                   log("drawline2");
                                   if(direction==0){
                                     this.jg.drawLine(points[0]+2,points[1],points[2]-2,points[3])
                                   }else{
                                     this.jg.drawLine(points[0],points[1]+2,points[2],points[3]-2)
                                   }
                                 }
                                 this.jg.setStroke(2);
                                 this.jg.setColor("#000000");
                                 log("drawline3");
                                 this.jg.drawLine(points[0],points[1],s_x,s_y);
                                 this.jg.drawLine(points[2],points[3],s_x,s_y);
                                 this.jg.paint()
                               }else if(this.mode==1){
                                 log("draw mode==1");
                                 var bubble=this.bubbles[position];
                                 if(position=="B"){
                                   bubble.style.top=parseInt(points[1])+"px";
                                   bubble.style.left=parseInt(points[0])+"px";
                                   bubble.style.width=parseInt(points[2]-points[0])+"px";
                                   bubble.style.height=parseInt((points[2]-points[0])/2)+"px"
                                 }else if(position=="T"){
                                   bubble.style.width=parseInt(points[2]-points[0])+"px";
                                   bubble.style.height=parseInt((points[2]-points[0])/2)+"px";
                                   bubble.style.top=(parseInt(points[1])-parseInt(bubble.style.height)-fix_delta)+"px";
                                   bubble.style.left=parseInt(points[0])+"px"
                                 }else if(position=="L"){
                                   bubble.style.height=parseInt(points[3]-points[1])+"px";
                                   bubble.style.width=parseInt((points[3]-points[1])/2)+"px";
                                   bubble.style.top=parseInt(points[1])+"px";
                                   bubble.style.left=(parseInt(points[0])-parseInt(bubble.style.width)-fix_delta)+"px"
                                 }else if(position=="R"){
                                   bubble.style.top=parseInt(points[1])+"px";
                                   bubble.style.left=parseInt(points[0])+"px";
                                   bubble.style.height=parseInt(points[3]-points[1])+"px";
                                   bubble.style.width=parseInt((points[3]-points[1])/2)+"px"
                                 }
                                 bubble.style.zIndex=useZ;
                                 bubble.style.display="";
                                 var sh_x=(intersect[0]+s_x)/2;
                                 var sh_y=(intersect[1]+s_y)/2;
                                 bubble=this.bubbles["20"];
                                 bubble.style.top=(sh_y-10)+"px";
                                 bubble.style.left=(sh_x-10)+"px";
                                 bubble.style.zIndex=useZ+1;
                                 bubble.style.display="";
                                 bubble=this.bubbles["10"];
                                 bubble.style.top=(s_y-5)+"px";
                                 bubble.style.left=(s_x-5)+"px";
                                 bubble.style.zIndex=useZ+2;
                                 bubble.style.display=""
                               }
                             },
                             
                             clear:function(){
                               if(this.jg!=null){
                                 this.jg.clear()
                               }
                               if(this.mode==1){
                                 for(key in this.bubbles){
                                   if(this.bubbles[key]!=null){
                                     this.bubbles[key].style.display="none"
                                   }
                                 }
                               }
                             },
                             
                             is_inside:function(x,y,t,l,w,h){
                               this.inHeight=false;
                               this.inWidth=false;
                               if(y>=t&&y<=(t+h)){
                                 this.inHeight=true;
                                 if(x>=l&&x<=(l+w)){
                                   this.inWidth=true;
                                   return true
                                 }
                               }else if(x>=l&&x<=(l+w)){
                                 this.inWidth=true
                               }
                               return false
                             },
                             
                             get_intersection:function(x1,y1,x2,y2,x3,y3,x4,y4){
                               var a1=y2-y1;
                               var b1=x1-x2;
                               var c1=x2*y1-x1*y2;
                               var a2=y4-y3;
                               var b2=x3-x4;
                               var c2=x4*y3-x3*y4;
                               var denom=a1*b2-a2*b1;
                               if(denom==0){return null}
                               x=(b1*c2-b2*c1)/denom;
                               y=(a2*c1-a1*c2)/denom;
                               return[x,y]
                             },
                             
                             del:function(){
                               this.clear();
                               this.jg=null;
                               this.canvas.parentNode.removeChild(this.canvas);
                               this.parentCall("del")},
                               
                             hide:function(){
                               this.parentCall("hide");
                               this.clear();
                               this.font_input.disabled=true;
                               this.fs_input.disabled=true;
                               this.b_input.disabled=true;
                               this.i_input.disabled=true;
                               this.text_input.disabled=true
                             },

                             restore:function(){
                               this.parentCall("restore");
                               this.font_input.disabled=false;
                               this.fs_input.disabled=false;
                               this.b_input.disabled=false;
                               this.i_input.disabled=false;
                               this.text_input.disabled=false;
                               this.draw()
                             },
                             
                             getApplyType:function(){return 1},
                             
                             serialize:function(queryComponents,prefix){
                               log ("serialize3");
                               if(prefix==null){prefix="bling"}
                               if(queryComponents==null){
                                 queryComponents=new Array()
                               }
                               this.parentCall("serialize",queryComponents,prefix);
                               queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][ox]")+"="+encodeURIComponent(this.offset_x));
                               queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][oy]")+"="+encodeURIComponent(this.offset_y));
                               queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][font]")+"="+encodeURIComponent(this.font_input.value));
                               queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][fs]")+"="+encodeURIComponent(this.fs_input.value));
                               queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][b]")+"="+encodeURIComponent(this.b_input.checked));
                               queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][i]")+"="+encodeURIComponent(this.i_input.checked));
                               queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][text]")+"="+encodeURIComponent(this.text_input.value));
                               queryComponents.push(encodeURIComponent(prefix+"["+this.id+"][mode]")+"="+encodeURIComponent(this.mode))
                             }
                           });
                           
                           function dopt(opts,name,defaultVal){
                             if(opts==null){return defaultVal}
                             if(opts[name]==null){return defaultVal}
                             return opts[name]
                           }
                           
                           function DependantAction(count,callback){
                             this.dependantCount=count;
                             this.callback=callback;
                             this.dependantsFinished=0;
                             this.dependantFinished=function(){
                               this.dependantsFinished++;
                               if(this.dependantsFinished==this.dependantCount){this.callback()}
                             }
                           }
                           var debug=null;
                           
                           function setDebug(box){debug=box}
                           
                           function log(msg){
                             if(BrowserDetect.browser=="Firefox"){
                               try{
                                 console.debug(msg)
                               }catch(e){}
                             }
                             if((debug!=null)&&(debug.style.display!='none')){
                               debug.value=msg+"\n"+debug.value
                             }
                           }

                           var showing_dropdown=false;
                           var current_dropdown=null;
                           var current_pane=null;
                           var valid_click=false;
                           var accept_actions=true;
                           var UP_URL="/upload-progress/upload.status";
                           
                           function showUploadOption(alwaysAccept){
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             noFileUploadAllowed=true;
                             accept_actions=false;
                             var uo=$("upload_option");
                             if(uo.style.display==""){
                               accept_actions=true;
                               pp.recalibrateCanvas();
                               noFileUploadAllowed=false;
                               return
                             }
                             var curOpt=this.getCurrentOption();
                             Effect.BlindUp(curOpt,{duration:0.3,
                               afterFinish:function(){Effect.BlindDown("upload_option",{duration:0.3,afterFinish:function(){pp.restoreBlings(true);pp.recalibrateCanvas();accept_actions=true;noFileUploadAllowed=false}})}})
                           }
                           
                           function showGalleryOption(alwaysAccept){
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             noFileUploadAllowed=true;
                             accept_actions=false;
                             var uo=$("upload_option");
                             var go=$("gallery_option");
                             if(go.style.display==""){accept_actions=true;return}
                             pp.hideBlings(true);
                             var da=new DependantAction(2,function(){Effect.BlindDown("gallery_option",{duration:0.3,afterFinish:function(request){accept_actions=true}})});
                             var curOpt=this.getCurrentOption();
                             Effect.BlindUp(curOpt,{duration:0.3,afterFinish:function(){da.dependantFinished()}});
                             startAsyncAction();
                             var t1=new Ajax.Updater('gallery_option','/home/get_gallery?page=1',{asynchronous:true,evalScripts:true,onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(request){finishAsyncAction();da.dependantFinished();noFileUploadAllowed=false}})}
                             
                           function showURLOption(alwaysAccept){
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             noFileUploadAllowed=true;
                             accept_actions=false;
                             var uo=$("url_option");
                             if(uo.style.display==""){
                               accept_actions=true;
                               pp.recalibrateCanvas();
                               noFileUploadAllowed=false;
                               return
                             }
                             var curOpt=this.getCurrentOption();
                             Effect.BlindUp(curOpt,{duration:0.3,afterFinish:function(){Effect.BlindDown("url_option",{duration:0.3,afterFinish:function(){pp.restoreBlings(true);pp.recalibrateCanvas();accept_actions=true;noFileUploadAllowed=false}})}})}
                             
                           function showDemoOption(){
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             noFileUploadAllowed=true;
                             accept_actions=false;
                             var uo=$("demo_option");
                             if(uo.style.display==""){
                               accept_actions=true;
                               pp.recalibrateCanvas();
                               noFileUploadAllowed=false;
                               return
                             }
                             var curOpt=this.getCurrentOption();
                             Effect.BlindUp(curOpt,{duration:0.3,afterFinish:function(){Effect.BlindDown("demo_option",{duration:0.3,afterFinish:function(){pp.restoreBlings(true);pp.recalibrateCanvas();accept_actions=true;noFileUploadAllowed=false}})}})}
                             
                           function getCurrentOption(){
                             if($("upload_option").style.display!='none'){return"upload_option"}
                             if($("gallery_option").style.display!='none'){return"gallery_option"}
                             if($("url_option").style.display!='none'){return"url_option"}
                             if($("demo_option").style.display!='none'){return"demo_option"}}
                             
                           function selectGalleryImage(id,alwaysAccept){
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             var laccb=$('load-as-copy');
                             var laac=laccb.checked;
                             accept_actions=false;
                             var da=new DependantAction(2,function(){pp.restoreBlings(true);pp.updateBackground();accept_actions=true});startAsyncAction();noFileUploadAllowed=true;var t1=new Ajax.Request('/home/select_gallery_image?id='+id+"&laac="+laac+"&isnew="+$('pimped_photo_new').value,{asynchronous:true,evalScripts:true,onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(request){da.dependantFinished()}});
                             Effect.BlindUp('gallery_option',{duration:0.3,afterFinish:function(){Effect.BlindDown("upload_option",{duration:0.3,afterFinish:function(){da.dependantFinished();noFileUploadAllowed=false}})}})}
                             
                           function selectURLImage(){
                             var url=$('url').value;
                             if((url==null)||(url=='http://')||(url.length==0)){
                               alert("Invalid Image URL");
                               return
                             }
                             startAsyncAction();
                             var t1=new Ajax.Request('/home/use_image_url?url='+encodeURIComponent(url)+"&isnew="+$('pimped_photo_new').value,{asynchronous:true,evalScripts:true,onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(request){finishAsyncAction()}})
                           }
                           
                           function selectDemoImage(id,alwaysAccept){
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             accept_actions=false;
                             var da=new DependantAction(1,function(){pp.restoreBlings(true);pp.updateBackground();accept_actions=true;noFileUploadAllowed=false});
                             startAsyncAction();
                             noFileUploadAllowed=true;
                             var t1=new Ajax.Request('/home/select_demo_image?id='+id+"&isnew="+$('pimped_photo_new').value,{asynchronous:true,evalScripts:true,onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(request){da.dependantFinished()}})
                           }
                             
                           function showLoginOptions(alwaysAccept){
                             valid_click=true;
                             log("showLoginOptions");
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return true
                             }
                             accept_actions=false;
                             if(current_dropdown=="login"){
                               log("current_dropdown == login");
                               hideDropDown(null,true);
                               return true
                             }
                             if(showing_dropdown){
                               swapDropdown(current_dropdown,"login");
                               return true
                             }
                             current_pane="no_user_options_pane";
                             var oh_node=$("options_pane_holder");
                             var o_node=$(current_pane);
                             Position.clone(o_node,oh_node);
                             Position.absolutize(o_node);
                             oh_node.style.display='';
                             var l_node=$('login');
                             l_node.onmousedown=validClick;
                             Effect.BlindDown("login",{duration:0.3,afterFinish:function(){accept_actions=true}});
                             showing_dropdown=true;
                             current_dropdown="login";
                             return true
                           }
                           
                           function showRegisterOptions(alwaysAccept){
                             valid_click=true;
                             log("showRegisterOptions");
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return true
                             }
                             accept_actions=false;
                             if(current_dropdown=="register"){
                               hideDropDown();
                               return true
                             }
                             if(showing_dropdown){
                               swapDropdown(current_dropdown,"register");
                               return true
                             }
                             current_pane="no_user_options_pane";
                             var oh_node=$("options_pane_holder");
                             var o_node=$(current_pane);
                             Position.clone(o_node,oh_node);
                             Position.absolutize(o_node);
                             oh_node.style.display='';
                             var l_node=$('register');
                             l_node.onmousedown=validClick;
                             Effect.BlindDown("register",{duration:0.3,afterFinish:function(request){accept_actions=true}});
                             showing_dropdown=true;
                             current_dropdown="register";
                             return true
                           }
                           
                           function swapDropdown(oldDD,newDD){
                             log("swapDropdown");
                             current_dropdown=newDD;
                             var l_node=$(newDD);
                             l_node.onmousedown=validClick;
                             Effect.BlindUp(oldDD,{duration:0.3,afterFinish:function(){Effect.BlindDown(newDD,{duration:0.3,afterFinish:function(request){accept_actions=true}})}})
                           }
                           
                           function prepareBody(logged_in){
                             log ("prepareBody");
                             Event.observe(document.body,"mousedown",backgroundClicked);
                             pp.pageLoadedCallback();
                             if((BrowserDetect.browser=="Opera")||(BrowserDetect.browser=="Safari")){
                               $('user_options_pane').style.top="-65px";
                               $('no_user_options_pane').style.top="-65px"
                             }
                             isLoggedIn=logged_in;
                             Ajax.Responders.register({onException:function(aj,ex){
                               try{
                                 alert("Exception Occured\nError name: "+ex.name+"\nError message: "+ex.message)
                               }catch(e){}
                             }})
                           }
                           
                           function validClick(event){
                             valid_click=true;
                             log("reset valid_click to true")
                           }
                           
                           function backgroundClicked(event){
                             log ("backgroundClicked");
                             var stopClickEvent=false;
                             var doDeselect=true;
                             var el=Event.element(event);
                             while(el!=null){
                               if(el.nodeType==1){
                                 if(el.getAttribute("stopclickevent")=="true"){
                                   stopClickEvent=true;
                                   log("found stopclickevent")
                                 }
                                 if(el.getAttribute("stopdeselect")=="true"){
                                   doDeselect=false;
                                   log("found stopdeselect")
                                 }
                               }
                               el=el.parentNode
                             }
                             if(doDeselect){pp.selectBling(null)}
                             if(stopClickEvent){return false}
                             hideDropDown();
                             return true
                           }
                           
                           function hideDropDown(){
                             if(showing_dropdown){
                               showing_dropdown=false;
                               Effect.BlindUp(current_dropdown,{duration:0.6,afterFinish:function(){var oh_node=$("options_pane_holder");var o_node=$(current_pane);Position.relativize(o_node);oh_node.style.display='none';current_dropdown=null;accept_actions=true}})
                             }
                           }
                           
                           function login(alwaysAccept){
                             log("login");
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             accept_actions=false;
                             startAsyncAction();
                             var t1=new Ajax.Request('/home/login',{asynchronous:true,evalScripts:true,parameters:Form.serialize("login"),onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(request){finishAsyncAction()}})
                           }
                           
                           function logout(alwaysAccept){
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             accept_actions=false;
                             var t1=new Ajax.Request('/home/logout',{asynchronous:true,evalScripts:true})
                           }
                           
                           function register(alwaysAccept){
                             if((!accept_actions)&&(alwaysAccept!=true)){
                               log("!accept_actions");
                               return
                             }
                             accept_actions=false;
                             startAsyncAction();
                             var t1=new Ajax.Request('/home/register',{asynchronous:true,evalScripts:true,parameters:Form.serialize("register"),onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(request){finishAsyncAction()}})
                           }
                           
                           function showAsLoggedIn(){
                             isLoggedIn=true;
                             if($("no_user_options_pane").style.display=="none"){
                               hideDropDown();
                               return
                             }
                             var swapOptions=function(){
                               current_dropdown=null;
                               Effect.BlindUpFromRight("no_user_options_pane",{afterFinish:function(){var o_node=$("no_user_options_pane");var oh_node=$("options_pane_holder");oh_node.style.display="none";Position.relativize(o_node);
                               Effect.BlindDownFromRight("user_options_pane",{afterFinish:function(){$("                               ").style.display='';$("user_option_2").style.display='';$("user_option_3").style.display='none';$("user_option_4").style.display='';showUploadOption(true)}})}})
                             };
                             if(showing_dropdown){
                               showing_dropdown=false;
                               Effect.BlindUp(current_dropdown,{duration:0.3,afterFinish:swapOptions})
                             }else{
                               swapOptions()
                             }
                           }
                           
                           function showAsLoggedOut(){
                             isLoggedIn=false;
                             if($("user_options_pane").style.display=="none"){return}
                             var swapOptions=function(){
                               Effect.BlindUpFromRight("user_options_pane",{afterFinish:function(){Effect.BlindDownFromRight("no_user_options_pane",{afterFinish:function(){$("user_option_1").style.display='none';$("user_option_2").style.display='none';$("user_option_3").style.display='';$("user_option_4").style.display='none';showUploadOption(true)}})}})
                             };
                             if(showing_dropdown){
                               showing_dropdown=false;
                               Effect.BlindUp(current_dropdown,{duration:0.3,afterFinish:swapOptions})
                             }else{
                               swapOptions()
                             }
                           }
                           
                           function saveShowEmbed(){
                             $('save-embed').style.display='';
                             $('save-tab-download').className='tabon';
                             $('save-email').style.display='none';
                             $('save-tab-email').className='taboff';
                             var isPubEl=$('is-public');
                             var isPriv=false;
                             if(!isPubEl.checked){isPriv=true}
                             if((!isPriv)||(isLoggedIn)){
                               $('td_pd1').style.display='';
                               $('td_pd2').style.display='';
                               $('td_pd3').colSpan=5
                             }else{
                               $('td_pd1').style.display='none';
                               $('td_pd2').style.display='none';
                               $('td_pd3').colSpan=4
                             }
                           }
                           
                           function saveShowEmail(){
                             $('save-embed').style.display='none';
                             $('save-tab-download').className='taboff';
                             $('save-email').style.display='';
                             $('save-tab-email').className='tabon';
                             $('td_pd1').style.display='none';
                             $('td_pd2').style.display='none';
                             $('td_pd3').colSpan=4
                           }
                           
                           function f_clientWidth(){
                             return f_filterResults(window.innerWidth?window.innerWidth:0,document.documentElement?document.documentElement.clientWidth:0,document.body?document.body.clientWidth:0)
                           }
                           
                           function f_clientHeight(){
                             return f_filterResults(window.innerHeight?window.innerHeight:0,document.documentElement?document.documentElement.clientHeight:0,document.body?document.body.clientHeight:0)
                           }
                           
                           function f_scrollLeft(){
                             return f_filterResults(window.pageXOffset?window.pageXOffset:0,document.documentElement?document.documentElement.scrollLeft:0,document.body?document.body.scrollLeft:0)
                           }
                           
                           function f_scrollTop(){
                             return f_filterResults(window.pageYOffset?window.pageYOffset:0,document.documentElement?document.documentElement.scrollTop:0,document.body?document.body.scrollTop:0)
                           }
                           
                           function f_filterResults(n_win,n_docel,n_body){
                             var n_result=n_win?n_win:0;
                             if(n_docel&&(!n_result||(n_result>n_docel)))n_result=n_docel;
                             return n_body&&(!n_result||(n_result>n_body))?n_body:n_result
                           }
                           
                           function popup(divId){
                             var div=$(divId);
                             if(div==null){alert("unable to get element:"+divId);return}
                             var bgdiv=$('popupbackground');
                             if(bgdiv==null){alert("unable to get element:popupbackground");return}
                             var height=f_clientHeight();
                             var width=f_clientWidth();
                             if(width<document.body.clientWidth){width=document.body.clientWidth}
                             var bimg=$('body-bottom');
                             var pos=Position.cumulativeOffset(bimg);
                             body_height=pos[1]+2;
                             if(height<body_height){
                               height=body_height;bgdiv.style.top="0px"
                             }else{
                               bgdiv.style.top=f_scrollTop()+"px"
                             }
                             bgdiv.style.height=height+"px";
                             bgdiv.style.width=width+"px";
                             bgdiv.style.left=f_scrollLeft()+"px";
                             bgdiv.style.zIndex=3000;
                             bgdiv.style.visibility="visible";
                             bgdiv.style.display="";
                             div.style.zIndex=3001;
                             div.style.visibility="hidden";
                             div.style.display="";
                             if(((((f_clientHeight()/2)-(div.clientHeight/2)))+f_scrollTop())<10){
                               div.style.top="10px"
                             }else{
                               div.style.top=(((f_clientHeight()/2)-(div.clientHeight/2)))+f_scrollTop()+"px"
                             }
                             div.style.left=(((f_clientWidth()/2)-(div.clientWidth/2)))+f_scrollLeft()+"px";
                             div.style.visibility="visible"
                           }
                           
                           function closePopup(divId){
                             var div=$(divId);
                             if(div==null){alert("unable to get popup element");return}
                             var bgdiv=$('popupbackground');
                             if(bgdiv==null){alert("unable to get background element");return}
                             bgdiv.style.visibility="hidden";
                             bgdiv.style.display="none";
                             div.style.visibility="hidden";
                             div.style.display="none"
                           }
                           
                           function repositionPopup(divId){
                             var div=$(divId);
                             if(div==null){alert("unable to get popup element");return}
                             if(((((f_clientHeight()/2)-(div.clientHeight/2)))+f_scrollTop())<10){
                               div.style.top="10px"
                             }else{
                               div.style.top=(((f_clientHeight()/2)-(div.clientHeight/2)))+f_scrollTop()+"px"
                             }
                             div.style.left=(((f_clientWidth()/2)-(div.clientWidth/2)))+f_scrollLeft()+"px"
                           }
                           
                           function startAsyncAction(){
//                             $('status-bar').style.display=''
                           }
                        
                           function finishAsyncAction(){
                               log ("finishAsyncAction");
//                             $('status-bar').style.display='none'
                           }
// ajout fl
/*

                           var up_started=false;
                           var up_stop=false;
                           var up_errorCount=0;
                           
                           function startTrackingUpload(){
                             up_started=false;
                             up_stop=false;
                             up_errorCount=0;
                             window.setTimeout(function(){if(!up_stop){$('upload_box').style.display='none';$('upload_status').style.display='';$('upload_progress_indicator').style.width="0px";$('upload_status_message').innerHTML="";var t1=new Ajax.Request(UP_URL+"?nc="+new Date().getTime(),{asynchronous:true,evalScripts:true,method:'get'})}},500)
                           }
                           
                           function stopTrackingUpload(){
                             up_stop=true;
                             $('upload_box').style.display='';
                             $('upload_status').style.display='none'
                           }
                           
                           function up_set_status(status,status_msg,size,uploaded,speed,eta_mins_frac,eta_secs){
                             if(status==0){
                               up_errorCount=0;
                               up_started=true;
                               var percent=(uploaded*100)/size;
                               var ind=$('upload_progress_indicator');
                               var bar=$('upload_status_bar');
                               var sm=$('upload_status_message');
                               var bar_width=parseInt(bar.style.width)-2;
                               ind.style.width=((bar_width*percent)/100)+"px";
                               var eta_mins=parseInt(eta_secs/60);
                               var eta_secs_left=eta_secs-(eta_mins*60);
                               var eta_str=eta_mins+":"+eta_secs_left+" minutes";
                               if(eta_mins==0){eta_str=eta_secs_left+" seconds"}
                               var size_str="";
                               var size_kb=parseInt(size/1000);
                               if(size_kb>1000){
                                 size_mb=parseFloat(parseInt(size_kb/10))/100;
                                 size_str=size_mb+"MB"
                               }else{
                                 size_str=size_kb+"KB"
                               }
                               var perc_str=parseFloat(parseInt(percent*100))/100;
                               if(uploaded==0){
                                 sm.innerHTML="Upload starting..."
                               }else{
                                 sm.innerHTML="Uploaded "+perc_str+"% of "+size_str+" at "+speed+"KBs. "
                               }
                             }else{
                               if(status==4){
                                 up_errorCount++;
                                 if(up_errorCount>5){stopTrackingUpload()}
                               }else{
                                 if(up_started){stopTrackingUpload()}
                               }
                             }
                             if(!up_stop){
                               window.setTimeout(function(){var t1=new Ajax.Request(UP_URL+"?nc="+new Date().getTime(),{asynchronous:true,evalScripts:true,method:'get'})},500)
                             }
                           }
*/
// fin ajout fl                           
                           function send_email_to_friends(){
                             var subjectEl=$('save-email-subject');
                             var toEl=$('save-email-to');
                             var textEl=$('save-email-message');
                             if((subjectEl.value=="")||(subjectEl.value==null)){
                               alert("You must specify the subject of the email");
                               return
                             }
                             if((toEl.value=="")||(toEl.value==null)){
                               alert("You must specify the recipients of the email");
                               return
                             }
                             startAsyncAction();
                             var t1=new Ajax.Request("/home/email?nc="+new Date().getTime()+"&id="+pp.compiled_image_id,{asynchronous:true,evalScripts:true,parameters:Form.serialize("save-email"),onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText)},onComplete:function(request){finishAsyncAction()}})
                           }
                           
                           function fileOk(){
                             if(noFileUploadAllowed){return false}
                             var fname=$('pimped_photo_image').value;
                             var ext=fname.substring(fname.length-4,fname.length);
                             ext=ext.toLowerCase();
                             if((ext=='.jpg')||(ext=='.gif')){return true}
                             ext=fname.substring(fname.length-5,fname.length);
                             ext=ext.toLowerCase();
                             if(ext=='.jpeg'){return true}alert("Only jpg, jpeg or gif files are allowed");return false
                           }
                           
                           Ajax.Request.prototype.respondToReadyState=function(readyState){
                             var event=Ajax.Request.Events[readyState];
                             var transport=this.transport,json=this.evalJSON();
                             var status="";
                             try{
                               status=this.transport.status
                             }catch(e){return}
                             log("Ajax.Request.respondToReadyState ("+readyState+") = "+status);
                             if(event=='Complete'){
                               try{
                                 (this.options['on'+this.transport.status]||this.options['on'+(this.responseIsSuccess()?'Success':'Failure')]||Prototype.emptyFunction)(transport,json)
                               }catch(e){
                                 this.dispatchException(e)
                               }
                               if((this.header('Content-type')||'').match(/^text\/javascript/i)){this.evalResponse()}
                             }
                             try{
                               (this.options['on'+event]||Prototype.emptyFunction)(transport,json);
                               Ajax.Responders.dispatch('on'+event,this,transport,json)
                             }catch(e){
                               this.dispatchException(e)
                             }
                             if(event=='Complete'){
                               this.transport.onreadystatechange=Prototype.emptyFunction
                             }
                           };
                           
                           Ajax.currentRequests={};
                           Ajax.Responders.register({onCreate:function(request){
                             if(request.options.onlyLatestOfClass&&Ajax.currentRequests[request.options.onlyLatestOfClass]){
                               log("aborting previous ajax call");
                               try{
                                 Ajax.currentRequests[request.options.onlyLatestOfClass].transport.abort()
                               }catch(e){
                                 log("exception aborting previous ajax call")
                               }
                               log("aborted previous ajax call")
                             }
                             Ajax.currentRequests[request.options.onlyLatestOfClass]=request}
                             ,onComplete:function(request){
                               if(request.options.onlyLatestOfClass){
                                 Ajax.currentRequests[request.options.onlyLatestOfClass]=null
                               }
                             }
                           });

