var FormImageCrop=function(){var demo1=function(){$('#demo1').Jcrop();}
var demo2=function(){var jcrop_api;$('#demo2').Jcrop({onChange:showCoords,onSelect:showCoords,onRelease:clearCoords},function(){jcrop_api=this;});$('#coords').on('change','input',function(e){var x1=$('#x1').val(),x2=$('#x2').val(),y1=$('#y1').val(),y2=$('#y2').val();jcrop_api.setSelect([x1,y1,x2,y2]);});function showCoords(c)
{$('#x1').val(c.x);$('#y1').val(c.y);$('#x2').val(c.x2);$('#y2').val(c.y2);$('#w').val(c.w);$('#h').val(c.h);};function clearCoords()
{$('#coords input').val('');};}
var demo3=function(){var jcrop_api,boundx,boundy,$preview=$('#preview-pane'),$pcnt=$('#preview-pane .preview-container'),$pimg=$('#preview-pane .preview-container img'),xsize=$pcnt.width(),ysize=$pcnt.height();console.log('init',[xsize,ysize]);$('#demo3').Jcrop({onChange:updatePreview,onSelect:updatePreview,aspectRatio:xsize/ysize},function(){var bounds=this.getBounds();boundx=bounds[0];boundy=bounds[1];jcrop_api=this;
$preview.appendTo(jcrop_api.ui.holder);});function updatePreview(c)
{if(parseInt(c.w)>0)
{var rx=xsize/c.w;var ry=ysize/c.h;$pimg.css({width:Math.round(rx*boundx)+'px',height:Math.round(ry*boundy)+'px',marginLeft:'-'+Math.round(rx*c.x)+'px',marginTop:'-'+Math.round(ry*c.y)+'px'});}};}
var demo4=function(){var jcrop_api;$('#demo4').Jcrop({bgFade:true,bgOpacity:.2,setSelect:[60,70,540,330]},function(){jcrop_api=this;});$('#fadetog').change(function(){jcrop_api.setOptions({bgFade:this.checked});}).attr('checked',true);Metronic.updateUniform('#fadetog');$('#shadetog').change(function(){if(this.checked)$('#shadetxt').slideDown();else $('#shadetxt').slideUp();jcrop_api.setOptions({shade:this.checked});}).attr('checked',false);var sections={bgc_buttons:'Change bgColor',bgo_buttons:'Change bgOpacity',anim_buttons:'Animate Selection'};var ac={anim1:[217,122,382,284],anim2:[20,20,580,380],anim3:[24,24,176,376],anim4:[347,165,550,355],anim5:[136,55,472,183]};var bgo={Low:.2,Mid:.5,High:.8,Full:1};var bgc={R:'#900',B:'#4BB6F0',Y: '#F0B207',G:'#46B81C',W:'white',K:'black'};for(i in sections)
insertSection(i,sections[i]);function create_btn(c){var $o=$('<button />').addClass('btn small');if(c)$o.append(c);return $o;}
var a_count=1;for(i in ac){$('#anim_buttons .btn-group')
.append(create_btn(a_count++).click(animHandler(ac[i])),' ');}
$('#anim_buttons .btn-group').append(create_btn('Bye!').click(function(e){$(e.target).addClass('active');jcrop_api.animateTo([300,200,300,200],function(){this.release();$(e.target).closest('.btn-group').find('.active').removeClass('active');});return false;}));for(i in bgo){$('#bgo_buttons .btn-group').append(create_btn(i).click(setoptHandler('bgOpacity',bgo[i])),' ');}
for(i in bgc){$('#bgc_buttons .btn-group').append(create_btn(i).css({background:bgc[i],color:((i=='K')||(i=='R'))?'white':'black'}).click(setoptHandler('bgColor',bgc[i])),' ');}
function insertSection(k,v){$('#interface').prepend($('<fieldset></fieldset>').attr('id',k).append($('<h4></h4>').append(v),'<div class="btn-toolbar"><div class="btn-group"></div></div>'));};function setoptHandler(k,v){return function(e){$(e.target).closest('.btn-group').find('.active').removeClass('active');$(e.target).addClass('active');var opt={};opt[k]=v;jcrop_api.setOptions(opt);return false;};};function animHandler(v){return function(e){$(e.target).addClass('active');jcrop_api.animateTo(v,function(){$(e.target).closest('.btn-group').find('.active').removeClass('active');});return false;};};$('#bgo_buttons .btn:first,#bgc_buttons .btn:last').addClass('active');$('#interface').show();}
var demo5=function(){var jcrop_api;initJcrop();function initJcrop()
{$('.requiresjcrop').hide();$('#demo5').Jcrop({onRelease:releaseCheck},function(){jcrop_api=this;jcrop_api.animateTo([100,100,400,300]);$('#can_click,#can_move,#can_size').attr('checked','checked');Metronic.updateUniform('#can_click,#can_move,#can_size');$('#ar_lock,#size_lock,#bg_swap').attr('checked',false);Metronic.updateUniform('#ar_lock,#size_lock,#bg_swap');$('.requiresjcrop').show();});};function getRandom(){var dim=jcrop_api.getBounds();return[Math.round(Math.random()*dim[0]),Math.round(Math.random()*dim[1]),Math.round(Math.random()*dim[0]),Math.round(Math.random()*dim[1])];};function releaseCheck()
{jcrop_api.setOptions({allowSelect:true});$('#can_click').attr('checked',false);Metronic.updateUniform('#can_click');};$('#setSelect').click(function(e){jcrop_api.setSelect(getRandom());});$('#animateTo').click(function(e){jcrop_api.animateTo(getRandom());});$('#release').click(function(e){jcrop_api.release();});$('#disable').click(function(e){jcrop_api.disable();$('#enable').show();$('.requiresjcrop').hide();});$('#enable').click(function(e){jcrop_api.enable();$('#enable').hide();$('.requiresjcrop').show();});$('#rehook').click(function(e){$('#rehook,#enable').hide();initJcrop();$('#unhook,.requiresjcrop').show();return false;});$('#unhook').click(function(e){jcrop_api.destroy();$('#unhook,#enable,.requiresjcrop').hide();$('#rehook').show();return false;});$('#img1').click(function(e){$(this).addClass('active').closest('.btn-group')
.find('button.active').not(this).removeClass('active');jcrop_api.setImage('../../assets/global/plugins/jcrop/demos/demo_files/sago.jpg');jcrop_api.setOptions({bgOpacity:.6});return false;});$('#img2').click(function(e){$(this).addClass('active').closest('.btn-group')
.find('button.active').not(this).removeClass('active');jcrop_api.setImage('../../assets/global/plugins/jcrop/demos/demo_files/pool.jpg');jcrop_api.setOptions({bgOpacity:.6});return false;});$('#img3').click(function(e){$(this).addClass('active').closest('.btn-group')
.find('button.active').not(this).removeClass('active');jcrop_api.setImage('../../assets/global/plugins/jcrop/demos/demo_files/sago.jpg',function(){this.setOptions({bgOpacity:1,outerImage:'../../assets/global/plugins/jcrop/demos/demo_files/sagomod.jpg'});this.animateTo(getRandom());});return false;});$('#can_click').change(function(e){jcrop_api.setOptions({allowSelect:!!this.checked});jcrop_api.focus();});$('#can_move').change(function(e){jcrop_api.setOptions({allowMove:!!this.checked});jcrop_api.focus();});$('#can_size').change(function(e){jcrop_api.setOptions({allowResize:!!this.checked});jcrop_api.focus();});$('#ar_lock').change(function(e){jcrop_api.setOptions(this.checked?{aspectRatio:4/3}:{aspectRatio:0});jcrop_api.focus();});$('#size_lock').change(function(e){jcrop_api.setOptions(this.checked?{minSize:[80,80],maxSize:[350,350]}:{minSize:[0,0],maxSize:[0,0]});jcrop_api.focus();});}
var demo6=function(){var api;$('#demo6').Jcrop({bgOpacity:0.5,bgColor:'white',addClass:'jcrop-light'},function(){api=this;api.setSelect([130,65,130+350,65+285]);api.setOptions({bgFade:true});api.ui.selection.addClass('jcrop-selection');});$('#buttonbar').on('click','button',function(e){var $t=$(this),$g=$t.closest('.btn-group');$g.find('button.active').removeClass('active');$t.addClass('active');$g.find('[data-setclass]').each(function(){var $th=$(this),c=$th.data('setclass'),a=$th.hasClass('active');if(a){api.ui.holder.addClass(c);switch(c){case 'jcrop-light':api.setOptions({bgColor:'white',bgOpacity:0.5});break;case 'jcrop-dark':api.setOptions({bgColor:'black',bgOpacity:0.4});break;case 'jcrop-normal':api.setOptions({bgColor:$.Jcrop.defaults.bgColor,bgOpacity:$.Jcrop.defaults.bgOpacity});break;}}
else api.ui.holder.removeClass(c);});});}
var demo7=function(){var c={"x":13,"y":7,"x2":487,"y2":107,"w":474,"h":100};
$('#demo7').Jcrop({bgFade:true,setSelect:[c.x,c.y,c.x2,c.y2]});}
var demo8=function(){$('#demo8').Jcrop({aspectRatio:1,onSelect:updateCoords});function updateCoords(c)
{$('#crop_x').val(c.x);$('#crop_y').val(c.y);$('#crop_w').val(c.w);$('#crop_h').val(c.h);};$('#demo8_form').submit(function(){if(parseInt($('#crop_w').val()))return true;alert('Please select a crop region then press submit.');return false;});}
var handleResponsive=function(){if($(window).width()<=1024&&$(window).width()>=678){$('.responsive-1024').each(function(){$(this).attr("data-class",$(this).attr("class"));$(this).attr("class",'responsive-1024 col-md-12');});}else{$('.responsive-1024').each(function(){if($(this).attr("data-class")){$(this).attr("class",$(this).attr("data-class"));$(this).removeAttr("data-class");}});}}
return{init:function(){if(!jQuery().Jcrop){;return;}
Metronic.addResizeHandler(handleResponsive);handleResponsive();demo1();demo2();demo3();demo4();demo5();demo6();demo7();demo8();}};}();