
pbx.crop={debug:false,image:null,frame:null,apature:null,crop_rotation:null,photo_oriantation:null,oldRotation:null,oldProduct:null,submit_mode:null,page:null,on_save:null,crop_disable_changeproduct:0,photo:null,itemObject:null,product_id:0,product:null,currCrop:null,oldCrop:null,cropFrame:function(){x=null;y=null,w=null,h=null,ro=null,ra=null},curr_quality:false,action_running:function(status)
{var inputs=$('#pbx_product_id, #pbx_save_crop, #pbx_preview_crop, input#pbx_crop_landscape, input#pbx_crop_portrait, input#pbx_crop_shrink');var style_input=$('#pbx_style_id');var tags=$('td#pbx_crop_tools label, div.pbx_crop_rotate_container');if(status)
{inputs.attr('disabled','disabled').parent().addClass('pbx_disabled');style_input.attr('disabled','disabled').parent().addClass('pbx_disabled');tags.addClass('pbx_disabled');}
else
{if(style_input.length>0&&style_input[0].value!='')
{style_input.removeAttr('disabled').parent().removeClass('pbx_disabled');}
inputs.removeAttr('disabled').parent().removeClass('pbx_disabled');tags.removeClass('pbx_disabled')}},init:function(params)
{pbx.crop._this=params._this;pbx.crop.action_running(true);eval($('#pbx_crop_scripttag').html());pbx.crop.apature=$('#pbx_crop_container');pbx.crop.image=$('#pbx_crop_image');pbx.crop.frame=$('#pbx_crop_frame');pbx.crop.frame.img=$('#pbx_crop_frame img');pbx.crop.page=params.page;pbx.crop.product_id=params.product_id;pbx.crop.submit_mode=params.submit_mode;pbx.crop.price_plan_id=params.price_plan_id;pbx.crop.crop_disable_changeproduct=params.crop_disable_changeproduct||0;if(pbx_crop_objects.item)
{var itemObject=pbx.crop.itemObject=pbx_crop_objects.item;itemObject.callBabel=pbx.babel._callBabelInstance;itemid=itemObject.id}
if(pbx_crop_objects.product)
{var productObject=pbx.crop.product=pbx_crop_objects.product;productObject.callBabel=pbx.babel._callBabelInstance;pbx.crop.product=productObject.id;}
var photo=pbx.crop.photo=pbx_crop_objects.photo;var photo_id=photo.id;pbx.crop.photo.callBabel=pbx.babel._callBabelInstance;if(pbx.crop.oldRotation==null)
{pbx.crop.oldRotation=pbx.photo.getAttributes(photo).rotation;}
$("input[name='pbx_crop_type']").bind('click',function()
{pbx.crop.changeCropType(params);});$('#pbx_save_crop').unbind().bind('click',function()
{if(!pbx.crop.save(params))
{pbx.popup.remove();}
pbx.crop.oldRotation=null;return false;});if(params.on_save)
{if(typeof(params.do_save)=='String')
{params.on_save=eval(params.on_save);}
if(typeof(params.on_save)=='function')
{pbx.crop.on_save=params.on_save}}
$('#pbx_preview_crop').unbind().bind('click',function()
{pbx.crop.preview(params);return false;});$('div#pbx_popup_window input.pbx_submit_cancel').bind('click',function()
{var crop_properties=pbx.crop.get_crop_properties();if(crop_properties.rotation!=pbx.crop.oldRotation)
{var photo_id=$('#pbx_crop_photo_id').val();$.ajax({type:"POST",url:"/includes/ajax/my/album/rotate",data:{'photo_id':photo_id,'rotation':pbx.crop.oldRotation,'session_code':pbx.babel.session.code},success:function(photo_id){pbx.popup.remove();pbx.babel.invalidatePhoto(photo_id);pbx.crop.oldRotation=null;}});}
else
{pbx.crop.oldRotation=null;}
pbx.crop.oldCrop=null;return false;});pbx.crop.photo_oriantation=pbx_crop_values.maxWidth>pbx_crop_values.maxHeight?'landscape':'portrait';if(params.old_crop_attributes)
{pbx.crop.oldCrop=params.old_crop_attributes;}
if(pbx.is_ie6)
{pbx_crop_values.maxHeight-=2;pbx_crop_values.maxBottom-=2;}
var fit=params.fit=pbx.crop.get_shrink_to_fit();if(fit!=1)
{pbx.crop.frame.Resizable(pbx_crop_values);pbx.crop.crop_rotation=(pbx_crop_values.ratio<1)?'landscape':'portrait';}
else
{pbx.crop.crop_rotation='shrink';}
pbx.crop.currCrop=new pbx.crop.cropFrame();pbx.crop.curr_quality=$('#pbx_crop_quality_display').find('.pbx_crop_current').attr('id').replace('pbx_crop_quality_','');calctop=parseFloat(pbx.crop.frame.css('top'))-parseFloat(pbx.crop.image.css('top'))+parseFloat(pbx.crop.frame.css('border-top-width'));calcleft=parseFloat(pbx.crop.frame.css('left'))-parseFloat(pbx.crop.image.css('left'))+parseFloat(pbx.crop.frame.css('border-left-width'));calcright=calcleft+parseFloat(pbx.crop.frame.css('width'));calcbottom=calctop+parseFloat(pbx.crop.frame.css('height'));pbx.crop.frame.img.css({clip:"rect("+calctop+"px "+calcright+"px "+calcbottom+"px "+calcleft+"px)",top:-calctop+"px",left:-calcleft+"px"});$('a.pbx_rotate').bind('click',function()
{if($(this).parent().is('.pbx_disabled'))
{return false;}
pbx.crop.show_loading();pbx.crop.action_running(true);var photo_id=$('#pbx_crop_photo_id').val();if(pbx.babel.photos[photo_id])
{pbx.babel.photos[photo_id]=null;}
var photo=pbx.babel.getPhoto(photo_id);var class_names=$(this).attr('class');var rotation=pbx.photo.getAttributes(photo).rotation;if(class_names.indexOf('right')>-1)
{rotation=(rotation+90)%360;var wise='clockwise';}
else if(class_names.indexOf('left')>-1)
{rotation=(rotation!=0)?rotation-90:270;var wise='anticlockwise';}
else
{pbx.crop.show_loading(false);pbx.crop.action_running(false);return false;}
pbx.babel.invalidatePhoto(photo_id);var rotate_params={fit:pbx.crop.get_shrink_to_fit(),oldCrop:(pbx.crop.get_shrink_to_fit()==1?pbx.crop.oldCrop:pbx.crop.getCropAttr())}
$.ajax({type:"POST",url:"/includes/ajax/my/album/rotate",data:"photo_id="+photo_id+"&rotation="+rotation+"&session_code="+pbx.babel.session.code,success:function(photo_id){pbx.crop.refresh_window(rotate_params,function(){if(rotate_params.fit==1)
{pbx.crop.oldCrop=rotate_params.oldCrop;}
else
{if(rotate_params.oldCrop)
{var new_ratio=pbx_crop_values.ratio;var old_ratio=rotate_params.oldCrop.ra;if((new_ratio>1&&old_ratio<1)||(new_ratio<1&&old_ratio>1))
{var oldw=rotate_params.oldCrop.w;rotate_params.oldCrop.w=rotate_params.oldCrop.h;rotate_params.oldCrop.h=oldw;}
var oldx=rotate_params.oldCrop.x;var oldy=rotate_params.oldCrop.y;if(wise=='anticlockwise')
{rotate_params.oldCrop.x=oldy;apt_height=pbx.crop.apature.height().replace('px','');rotate_params.oldCrop.y=apt_height-rotate_params.oldCrop.h-oldx;}
else
{apt_width=pbx.crop.apature.width().replace('px','');rotate_params.oldCrop.x=apt_width-rotate_params.oldCrop.w-oldy;rotate_params.oldCrop.y=oldx;}
pbx.crop.frame.Resizable(pbx_crop_values);pbx.crop.setCrop(rotate_params.oldCrop);}}});}});return false;});if($("select#pbx_product_id").length>0)
{var style_selector=$("select#pbx_style_id")
var style_count=pbx.popup.orderprint.getStyle(true,itemObject.style_id.toString());if(style_count<=0)
{$("select#pbx_style_id").attr('disabled','disabled');}
else
{style_selector.attr('disabled','');var option_value=style_selector.children("option[value="+pbx.crop.itemObject.style_id.toString()+"]");if(option_value.length)
{style_selector[0].value=pbx.crop.itemObject.style_id.toString();}
else
{style_selector.children("option:first").attr("selected","selected");}}
$("select#pbx_product_id").bind('change',function()
{pbx.crop.show_loading();pbx.crop.action_running(true);var new_product_id=this.options[this.selectedIndex].value;params.oldCrop=null;var crop_html=$.ajax({type:"POST",url:"/includes/ajax/crop_item",data:"fit="+fit+"&item_id="+itemid+"&product_id="+new_product_id+"&submit_mode="+pbx.crop.submit_mode+"&price_plan_id="+pbx.crop.price_plan_id+"&crop_disable_changeproduct="+pbx.crop.crop_disable_changeproduct+"&page="+pbx.crop.page+"&clear_crop=1",success:function()
{$('div#pbx_popup_content').html(crop_html.responseText);pbx.crop.init(params);pbx.popup.bind_ajax_events(params);pbx.crop.oldProduct=true;pbx.crop.action_running(false);}});});$("select#pbx_style_id").bind('change',function()
{pbx.crop.action_running(true);var selected=$('#pbx_style_id')[0]
var style_id=this.options[this.selectedIndex].value;var new_product_id=$("select#pbx_product_id option:selected").val();pbx.crop.oldProduct=true;pbx.babel.ChangeBasketItems([$('#pbx_crop_item_id').val()],{product_id:new_product_id,style_id:style_id},function()
{pbx.crop.action_running(false);});});}
pbx.crop.init_debug();pbx.crop.action_running(false);},refresh_window:function(params,callback)
{var ajax_data={fit:pbx.crop.get_shrink_to_fit(),submit_mode:pbx.crop.submit_mode,page:pbx.crop.page,price_plan_id:pbx.crop.price_plan_id,crop_disable_changeproduct:pbx.crop.crop_disable_changeproduct,photo_id:pbx.crop.photo.id};if(pbx.crop.itemObject!==null){ajax_data.item_id=pbx.crop.itemObject.id;}
if(pbx.crop.product_id!==null){ajax_data.product_id=pbx.crop.product_id;}
params.oldCrop=pbx.crop.getCropAttr();$.ajax({type:"POST",url:"/includes/ajax/crop_item",data:ajax_data,success:function(response){$('div#pbx_popup_content').html(response);ajax_data._this=pbx.crop._this;pbx.crop.init(ajax_data);pbx.popup.bind_ajax_events(params);typeof(callback)=='function'?callback():0;pbx.crop.action_running(false);}});},get_item_properties:function(params)
{var saveAsNewItem=$('input#pbx_save_as_new_product').attr('checked');if($("select#pbx_product_id").length>0)
{var new_product_id=$("select#pbx_product_id").val();var new_style_id=$("select#pbx_style_id").val();}
if(!params)
{item_id=$('#pbx_crop_item_id').val();}
else
{item_id=params.item_id;}
var properties={product_id:new_product_id||pbx.crop.product_id,style_id:new_style_id||"",photo_id:$('#pbx_crop_photo_id').val(),type:$('input[name=type]').val(),asnew:saveAsNewItem?1:0,item_id:item_id};if(saveAsNewItem)
{properties.quantity=1;}
return properties;},get_crop_properties:function()
{var properties=new Object;properties.rotation=$('input#pbx_rotated').val();properties.type=$('input[name=type]').val();var imageW=parseFloat(pbx.crop.image.css('width'));var imageH=parseFloat(pbx.crop.image.css('height'));var imageX=parseFloat(pbx.crop.image.css('left'));var imageY=parseFloat(pbx.crop.image.css('top'));var frameX=parseFloat(pbx.crop.frame.css('left'));var frameY=parseFloat(pbx.crop.frame.css('top'));var frameW=parseFloat(pbx.crop.frame.css('width'))+3.5;var frameH=parseFloat(pbx.crop.frame.css('height'))+3.5;var fit=pbx.crop.get_shrink_to_fit();if(fit!=1)
{properties.cropx=(frameX-imageX)/imageW;properties.cropy=(frameY-imageY)/imageH;properties.cropw=frameW/imageW;properties.croph=frameH/imageH;properties.fit=0;properties=pbx.crop.validate_crop_properties(properties);}
else
{properties.fit=1;}
return properties;},validate_crop_properties:function(properties)
{var ratio=properties.cropw/properties.croph;if(properties.cropw>1)
{properties.cropw=1;properties.croph=properties.cropw/ratio;}
if(properties.croph>1)
{properties.croph=1;properties.cropw=properties.croph*ratio;}
if(properties.cropx+properties.cropw>1)
{properties.cropx=Math.max(1-properties.cropw,0);}
if(properties.cropy+properties.croph>1)
{properties.cropy=Math.max(1-properties.croph,0);}
return properties;},save:function(params)
{if(typeof(pbx.crop.on_save)==='function')
{var crop_properties=pbx.crop.get_crop_properties();return pbx.crop.on_save(crop_properties,params);}
else
{var item_properties=pbx.crop.get_item_properties(params);var crop_properties=pbx.crop.get_crop_properties();if(item_properties.asnew)
{pbx.babel.ChangeBasketItems([params.item_id],item_properties,function(new_item)
{pbx.crop.itemObject=new_item[0];pbx.babel.setAttributes(pbx.crop.itemObject,crop_properties);document.pbx_crop_form.submit();});}
else
{var response=pbx.babel.changeAttributes(pbx.crop.itemObject,crop_properties);if(pbx.crop.oldProduct&&$("select#pbx_product_id").length>0)
{pbx.popup.orderprint.fillValues(params);pbx.popup.remove(params);pbx.show_overlay(true);pbx.show_loading(true);pbx.order.changeItem(params);}
else if(crop_properties.rotation!=pbx.crop.oldRotation&&$('td.pbx_photo_'+item_properties.photo_id).length>1)
{document.pbx_crop_form.submit();}
else
{pbx.order.updateThumnail(params._this,{new_item_id:response.id});return false;}}
pbx.crop.oldCrop=null;return true;}},preview:function(params)
{pbx.crop.action_running(true);var default_properties={submit_mode:pbx.crop.submit_mode,page:pbx.crop.page,crop_disable_changeproduct:pbx.crop.crop_disable_changeproduct,photo_id:pbx.crop.photo_id}
var item_properties=pbx.crop.get_item_properties(params);var crop_properties=pbx.crop.get_crop_properties();var properties=$.extend({},default_properties,item_properties,crop_properties);try
{var preview_html=$.ajax({type:"POST",url:"/includes/ajax/preview_item",data:properties,success:function()
{$('div#pbx_crop_preview').html(preview_html.responseText);$('div#pbx_crop_preview .pbx_action').bind('click',pbx.crop.preview_to_crop);pbx.crop.old_popup_close=pbx.popup.on_close;pbx.popup.on_close=pbx.crop.preview_to_crop;$('div#pbx_crop').hide();$('div#pbx_crop_preview').show();pbx.crop.action_running(false);},error:function(event,XMLHttpRequest,ajaxOptions,thrownError)
{alert(thrownError);}});}
catch(e)
{alert(e);}
return false;},preview_to_crop:function()
{$('div#pbx_crop_preview').hide();$('div#pbx_crop').show();pbx.popup.on_close=pbx.crop.old_popup_close;},changeView:function(params)
{pbx.crop.show_loading();$('#pbx_save_crop, #pbx_preview_crop').unbind();$('#pbx_save_crop, #pbx_preview_crop').bind('click',function()
{return false;});var itemid=0;if(params&&params.item_id)
{itemid=params.item_id;}
else if(pbx.crop.itemObject&&pbx.crop.itemObject.id)
{itemid=pbx.crop.itemObject.id;}
var fit=params.fit=pbx.crop.get_shrink_to_fit();if($("select#pbx_product_id").length>0)
{var product_selected=$("select#pbx_product_id")[0];var new_product_id=product_selected.options[product_selected.selectedIndex].value;}
else if(params.product_id)
{var new_product_id=params.product_id;}
else
{var new_product_id=0;}
var url_data={fit:fit,product_id:new_product_id,item_id:itemid,photo_id:pbx.crop.photo.id,submit_mode:pbx.crop.submit_mode,page:pbx.crop.page,crop_disable_changeproduct:pbx.crop.crop_disable_changeproduct};var crop_html=$.ajax({type:"POST",url:"/includes/ajax/crop_item",data:url_data,success:function()
{$('div#pbx_popup_content').html(crop_html.responseText);pbx.crop.init(params);pbx.crop.doPostShrink(params);pbx.popup.bind_ajax_events(params);}});},doPostShrink:function(params)
{pbx.crop.curr_quality=pbx.crop.get_crop_quality();if(params.fit==1)
{pbx.crop.oldCrop=params.oldCrop;}
else
{if(params.oldCrop)
{pbx_crop_values=pbx.copyObject(params.oldCrop.pbx_crop_values);pbx.crop.crop_rotation=params.oldCrop.ro;pbx.crop.frame.Resizable(pbx_crop_values);pbx.crop.setCrop(params.oldCrop);}
if(params.doCropRotate)
{if(pbx.crop.crop_rotation=='landscape')
{$('#pbx_crop_landscape').attr('checked','');$('#pbx_crop_portrait').attr('checked','checked').click();}
else if(pbx.crop.crop_rotation=='portrait')
{$('#pbx_crop_portrait').attr('checked','');$('#pbx_crop_landscape').attr('checked','checked').click();}}
else
{if(pbx.crop.crop_rotation=='landscape')
{$('#pbx_crop_landscape').attr('checked','checked');}
else if(pbx.crop.crop_rotation=='portrait')
{$('#pbx_crop_portrait').attr('checked','checked');}}
pbx.crop.displayCropSize();}
pbx.crop.update_fake_image();},changeCropType:function(params)
{var new_crop_rotation=pbx.getRadioValue('pbx_crop_form','pbx_crop_type');if(new_crop_rotation==pbx.crop.crop_rotation)
{return;}
if(new_crop_rotation=='shrink')
{params.oldCrop=pbx.crop.getCropAttr();pbx.crop.changeView(params);}
else if(pbx.crop.crop_rotation=='shrink')
{if(params.oldCrop)
{params.doCropRotate=(new_crop_rotation==params.oldCrop.ro?false:true);}
else
{var savedCrop=(pbx_crop_values.ratio<1)?'landscape':'portrait';params.doCropRotate=(new_crop_rotation==savedCrop?false:true);}
pbx.crop.changeView(params);}
else
{var imageX=parseFloat(pbx.crop.image.css('left'));var imageY=parseFloat(pbx.crop.image.css('top'));var imageW=parseFloat(pbx.crop.image.css('width'));var imageH=parseFloat(pbx.crop.image.css('height'));var the_frame=pbx.crop.frame;var newCrop=new pbx.crop.cropFrame();newCrop.x=parseFloat(pbx.crop.frame.css('left'));newCrop.y=parseFloat(pbx.crop.frame.css('top'));newCrop.w=parseFloat(pbx.crop.frame.css('width'))+4;newCrop.h=parseFloat(pbx.crop.frame.css('height'))+4;if(pbx.crop.photo_oriantation=='portrait')
{if(pbx.crop.crop_rotation=='portrait'&&new_crop_rotation=='landscape')
{pbx_crop_values.minWidth=pbx_crop_values.minHeight;pbx_crop_values.minHeight=0;var tmpw=newCrop.w;newCrop.w=newCrop.h;newCrop.h=newCrop.w/pbx_crop_values.ratio;pbx_crop_values.ratio=1/pbx_crop_values.ratio;}
if(pbx.crop.crop_rotation=='landscape'&&new_crop_rotation=='portrait')
{pbx_crop_values.minHeight=pbx_crop_values.minWidth;pbx_crop_values.minWidth=0;var tmpw=newCrop.w;newCrop.w=newCrop.h;newCrop.h=newCrop.w/pbx_crop_values.ratio;pbx_crop_values.ratio=1/pbx_crop_values.ratio;}}
if(pbx.crop.photo_oriantation=='landscape')
{if(pbx.crop.crop_rotation=='portrait'&&new_crop_rotation=='landscape')
{pbx_crop_values.minWidth=pbx_crop_values.minHeight;pbx_crop_values.minHeight=0;var tmpw=newCrop.w;newCrop.h=newCrop.w;newCrop.w=newCrop.h*pbx_crop_values.ratio;pbx_crop_values.ratio=1/pbx_crop_values.ratio;}
if(pbx.crop.crop_rotation=='landscape'&&new_crop_rotation=='portrait')
{pbx_crop_values.minHeight=pbx_crop_values.minWidth;pbx_crop_values.minWidth=0;var tmpw=newCrop.w;newCrop.h=newCrop.w;newCrop.w=newCrop.h*pbx_crop_values.ratio;pbx_crop_values.ratio=1/pbx_crop_values.ratio;}}
pbx.crop.setCrop(newCrop);}
pbx.crop.crop_rotation=new_crop_rotation;pbx.crop.update_fake_image();},setCrop:function(newCropFrame)
{var the_img=pbx.crop.image;var imageX=parseFloat(the_img.css('left'));var imageY=parseFloat(the_img.css('top'));var imageW=parseFloat(the_img.css('width'));var imageH=parseFloat(the_img.css('height'));if(pbx.is_ie6)
{imageH-=2;}
var the_frame=pbx.crop.frame;var frameX=newCropFrame.x;var frameY=newCropFrame.y;var frameW=newCropFrame.w;var frameH=newCropFrame.h;var ratio=frameW/frameH;if(frameW<=pbx_crop_values.minWidth){frameW=pbx_crop_values.minWidth;frameH=frameW/ratio;}
if(frameW>imageW)
{frameW=imageW;frameH=frameW/ratio;}
if(frameH<=pbx_crop_values.minHeight){frameH=pbx_crop_values.minHeight;frameW=frameH*ratio;}
if(frameH>imageH)
{frameH=imageH;frameW=frameH*ratio;}
if(frameX<imageX)
{frameX=imageX;}
if(frameY<imageY)
{frameY=imageY;}
var imageRight=imageX+imageW;var imageBottom=imageY+imageH;var frameRight=frameX+frameW;var frameBottom=frameY+frameH;if(frameRight>imageRight)
{frameX-=(frameRight-imageRight)}
if(frameBottom>imageBottom)
{frameY-=(frameBottom-imageBottom)}
pbx.crop.currCrop.x=frameX;pbx.crop.currCrop.y=frameY;pbx.crop.currCrop.w=frameW;pbx.crop.currCrop.h=frameH;the_frame.css('left',frameX);the_frame.css('top',frameY);the_frame.css('width',frameW-4);the_frame.css('height',frameH-4);pbx.crop.update_fake_image();var currCrop={width:frameW,height:frameH};pbx.crop.setCropQuality(currCrop);pbx.crop.displayCropSize();},update_fake_image:function()
{calctop=parseFloat(pbx.crop.frame.css('top'))-parseFloat(pbx.crop.image.css('top'))+parseFloat(pbx.crop.frame.css('border-top-width'));calcleft=parseFloat(pbx.crop.frame.css('left'))-parseFloat(pbx.crop.image.css('left'))+parseFloat(pbx.crop.frame.css('border-left-width'));calcright=calcleft+parseFloat(pbx.crop.frame.css('width'));calcbottom=calctop+parseFloat(pbx.crop.frame.css('height'));pbx.crop.frame.img.css({clip:"rect("+calctop+"px "+calcright+"px "+calcbottom+"px "+calcleft+"px)",top:-calctop+"px",left:-calcleft+"px"});},getCropAttr:function()
{var the_frame=pbx.crop.frame;var curr_attr={x:parseFloat(the_frame.css('left')),y:parseFloat(the_frame.css('top')),w:parseFloat(the_frame.css('width'))+4,h:parseFloat(the_frame.css('height'))+4,ro:pbx.crop.crop_rotation,pbx_crop_values:pbx.copyObject(pbx_crop_values)};curr_attr.ra=curr_attr.h/curr_attr.w;return curr_attr;},get_shrink_to_fit:function()
{return $('#pbx_crop_shrink')[0].checked?1:'false';},get_crop_quality:function()
{var curr_quality=$('#pbx_crop_quality_display').children('.pbx_crop_current');if(curr_quality.length==1)
{var quality=curr_quality[0].id.replace('pbx_crop_quality_','');}
return quality;},setCropQuality:function(dim)
{var newQuality=false;var oldQuality=pbx.crop.curr_quality;var longestLength=Math.round(Math.max(dim.height,dim.width));if(longestLength<pbx_crop_values.quality_limits.lower)
{newQuality='bad';}
else if(longestLength<pbx_crop_values.quality_limits.upper)
{newQuality='low';}
else
{newQuality='good';}
if(newQuality&&newQuality!=oldQuality)
{$('#pbx_crop_quality_'+pbx.crop.curr_quality).addClass('pbx_hidden');$('#pbx_crop_quality_'+newQuality).removeClass('pbx_hidden');pbx.crop.curr_quality=newQuality;}
if(pbx.crop.debug)
{$('#pbx_crop_debugging_quality').html(longestLength.toString()+','+oldQuality.toString()+','+newQuality.toString());}},show_loading:function()
{$('#pbx_crop_overlay').css('display','block');},onDrag:function(posleft,postop)
{calctop=postop-parseFloat(pbx.crop.image.css('top'))+parseFloat(pbx.crop.frame.css('border-top-width'));calcleft=posleft-parseFloat(pbx.crop.image.css('left'))+parseFloat(pbx.crop.frame.css('border-left-width'));calcright=calcleft+parseFloat(pbx.crop.frame.css('width'));calcbottom=calctop+parseFloat(pbx.crop.frame.css('height'));pbx.crop.frame.img.css({clip:"rect("+calctop+"px "+calcright+"px "+calcbottom+"px "+calcleft+"px)",top:-calctop+"px",left:-calcleft+"px"});},onResize:function(dim,pos)
{pbx.crop.setCropQuality(dim);calctop=pos.top-parseFloat(pbx.crop.image.css('top'))+parseFloat(pbx.crop.frame.css('border-top-width'));calcleft=pos.left-parseFloat(pbx.crop.image.css('left'))+parseFloat(pbx.crop.frame.css('border-left-width'));calcright=calcleft+parseFloat(pbx.crop.frame.css('width'));calcbottom=calctop+parseFloat(pbx.crop.frame.css('height'));pbx.crop.frame.img.css({clip:"rect("+calctop+"px "+calcright+"px "+calcbottom+"px "+calcleft+"px)",top:-calctop+"px",left:-calcleft+"px"});pbx.crop.displayCropSize();},displayCropSize:function()
{$('#pbx_crop_new_size').text(Math.round(pbx_crop_values.resize_Mult*parseFloat(pbx.crop.frame.css('width')))+" x "+Math.round(pbx_crop_values.resize_Mult*parseFloat(pbx.crop.frame.css('height')))+" px");},init_debug:function()
{if(!pbx.crop.debug)
{return;}
var debug_html='<div id="pbx_crop_debugging">';debug_html+='quality: <span id="pbx_crop_debugging_quality" />';debug_html+='</div>';$('#pbx_crop_tools').append(debug_html);}};