(function($){jQuery.facets=function(data,options){return jQuery.facets.impl.init(data,options)};jQuery.facets.resetClips=function(animated){jQuery.facets.impl.resetClipValues(animated)};jQuery.facets.open=function(index){jQuery.facets.impl.maximize(index)};jQuery.facets.close=function(index){jQuery.facets.impl.minimize(index)};jQuery.facets.lock=function(index){jQuery.facets.impl.theOpenKeeper('true');jQuery.facets.impl.maximize(index)};jQuery.facets.unlock=function(index){jQuery.facets.impl.theOpenKeeper('false');jQuery.facets.impl.minimizeAll()};jQuery.facets.restore=function(){jQuery.facets.impl.theOpenKeeper('restore');jQuery.facets.impl.minimizeAll()};jQuery.fn.facets=function(options){return jQuery.facets.impl.init(this,options)};jQuery.facets.defaults={control:'',autoStart:null,autoCliping:false,debug:false,clipSpacing:0,animationSpeed:500,keepItOpened:false,minimizeTimeout:0,contentRelations:false,sense:false,activePanel:false,autoOpenControl:true,minWidth:0,beforeMax:null,afterMax:null,beforeMin:null,afterMin:null};jQuery.facets.impl={d:{},init:function(elObj,options){var t=this;if(t.d.cv){t.debug('multiple calls init()');return false}t.o=jQuery.extend({},jQuery.facets.defaults,options);t.d.elObj=elObj;t.d.minimizetimeouts=[];t.d.minBmax=false;t.d.minBmax_reset=true;t.d.cv=t.o.autoCliping===true?t.resetClipValues():t.getClipValues();t.debug('autoCliping: '+(t.o.autoCliping===true?'on':'off'));t.d.keepItOpened=false;t.d.minimizeTimeout=typeof t.o.minimizeTimeout=='number'&&t.o.minimizeTimeout>50?t.o.minimizeTimeout:50;t.d.minWidth=typeof t.o.minWidth=='number'&&t.o.minWidth<=(t.d.elObj.width()/t.d.elObj.children().length)?t.o.minWidth:0;t.bindEvents();if(typeof t.o.autoStart=='number'&&t.o.autoStart<t.d.elObj.children().length){t.d.minBmax=true;t.maximize(t.o.autoStart);t.debug('autoStart: '+t.o.autoStart)}if(t.o.keepItOpened===true||(typeof t.d.minimizeTimeout=='number'&&t.d.minimizeTimeout>0)){if(t.o.keepItOpened===true){t.debug('keepItOpened: true');t.d.keepItOpened=true}t.d.minBmax=true;t.d.minBmax_reset=false}return t},bindEvents:function(){var t=this,c=jQuery(t.o.control).children().length>0?t.o.control:t.d.elObj,elObjChildElems=jQuery(c).children(),index=null;t.d.c=c;elObjChildElems.hover(function(event){index=elObjChildElems.index(this);t.debug('hover: '+index);t.maximize(index);jQuery(this).mouseleave(function(event){t.debug('mouseleave: '+index);t.delayedMinimize(index);if(t.isControl(t.o.control)&&t.o.activePanel!==true&&t.o.keepItOpened!==true){t.bindPanel(index)}jQuery(this).unbind('mouseleave')})});t.sense();if(t.o.activePanel!==true||t.isControl(t.d.elObj))return;t.bindPanel()},theOpenKeeper:function(status){var t=this;if(typeof t.d.kfo=='undefined'){t.d.kfo={keepItOpened:t.d.keepItOpened,minBmax:t.d.minBmax,minBmax_reset:t.d.minBmax_reset}}switch(status){case'true':t.debug('keepItOpened: true');t.d.keepItOpened=true;t.d.minBmax=true;t.d.minBmax_reset=false;break;case'false':t.debug('keepItOpened: false');t.d.keepItOpened=false;t.d.minBmax=false;t.d.minBmax_reset=false;break;case'restore':t.debug('keepItOpened: restore');t.d.keepItOpened=t.d.kfo.keepItOpened;t.d.minBmax=t.d.kfo.minBmax;t.d.minBmax_reset=t.d.kfo.minBmax_reset;break}},sense:function(){var t=this,senseObj=null;if(t.o.sense!==true)return;t.debug('sense: on');t.d.elObj.children().each(function(i,el){senseObj=jQuery(this);if(senseObj.attr('id')!==''){jQuery('a[rel='+senseObj.attr('id')+']').hover(function(){t.maximize(i)},function(){t.delayedMinimize(i)})}})},bindPanel:function(index){var t=this,elem=null,elObjChildElems=t.d.elObj.children();t.debug('bind panel');elem=typeof index=='number'?elObjChildElems.eq(index):elObjChildElems;elem.mouseenter(function(event){var i=elObjChildElems.index(this);t.maximize(i);jQuery(this).mouseleave(function(event){t.delayedMinimize(i)})})},unbindPanel:function(index){var t=this,i=index;if(t.isControl(t.d.elObj)||t.o.activePanel===true)return;if(typeof i=='number'){t.debug('minimize unbind "'+index+'"');t.d.elObj.children().eq(i).unbind('mouseenter hover mouseout mouseleave')}else{t.debug('minimize unbind all');t.d.elObj.children().unbind('mouseenter hover mouseout mouseleave')}},delayedMinimize:function(index){var t=this,i=index;if(t.d.keepItOpened===true)return;t.clearTimeout(i);t.d.minimizetimeouts[i]=setTimeout(function(){t.minimize(i)},t.d.minimizeTimeout)},clearTimeout:function(index){var t=this,i=index;if(t.d.minimizetimeouts[i]){clearTimeout(t.d.minimizetimeouts[i])}},minimizeAll:function(){var t=this,elObjChildElems=t.d.elObj.children();t.debug('minimizeAll');t.d.elObj.children().each(function(i,elm){t.minimize(i)})},minimize:function(index){var t=this,elObjChildElems=t.d.elObj.children(),i=index;t.debug('minimize');t.clearTimeout(i);t.hideControl(i);t.unbindPanel();t.trigger(t.o.beforeMin,i,function(){if(t.d.minWidth>0){t.resetClipValues(true,function(){t.trigger(t.o.afterMin,i)})}else{t.setClip(i,t.d.cv[i],true,function(){t.trigger(t.o.afterMin,i)})}if(t.o.contentRelations===true){jQuery('a[rel='+t.d.elObj.children().eq(i).attr('id')+']').removeClass('on')}})},minBeforeMax:function(index){var t=this;if(t.d.minBmax==false||typeof index=='undefined')return;t.minimize(index);if(t.d.minBmax_reset==true){t.d.minBmax=false}},maximize:function(index){var t=this,i=index,lastIndex=t.d.index;t.debug('maximize');t.d.index=i;t.minBeforeMax((typeof lastIndex=='undefined'?i:lastIndex));t.showControl(i);t.d.elObj.children().css('z-index','1').eq(i).css('z-index','10');t.trigger(t.o.beforeMax,i,function(){if(t.o.contentRelations===true){jQuery('a[rel='+t.d.elObj.children().eq(i).attr('id')+']').addClass('on')}if(t.d.minWidth>0){t.devideClips(i,function(){t.trigger(t.o.afterMax,i)})}else{t.setClip(i,[0,t.d.elObj.width(),t.d.elObj.height(),0],true,function(){t.trigger(t.o.afterMax,i)})}})},devideClips:function(index,callback){var t=this,el={obj:t.d.elObj,dim:{w:t.d.elObj.width(),h:t.d.elObj.height()}},ce=el.obj.children(),indexWidth=el.dim.w,widths=[];indexWidth=el.dim.w-((ce.length-1)*t.d.minWidth);ce.each(function(i,elm){widths[i]=i===index?indexWidth:parseInt(t.d.minWidth)});t.setEachChildren(widths,true,callback)},resetClipValues:function(animated,callback,resetCallback){var t=this,ret=null;ret=t.setEachChildren((t.d.elObj.width()/t.d.elObj.children().length),animated,callback,true);if(jQuery.isFunction(resetCallback)){resetCallback()}return ret},setEachChildren:function(width,animated,callback,ret){var t=this;var el={obj:t.d.elObj,dim:{w:t.d.elObj.width(),h:t.d.elObj.height()}},ce=el.obj.children(),z=0,x=z,d=typeof t.o.clipSpacing=='number'?t.o.clipSpacing:0,values=[];ce.each(function(i,elm){var nLastItem=(i+1)<ce.length?true:false,distance=nLastItem?true:false,s=typeof width=='object'?width[i]:width,rx=x+(d>0&&distance?s-d:s),rx_rnd=nLastItem?Math.floor(rx):Math.round(rx);values[i]=[0,rx_rnd,el.dim.h,x];t.setClip(i,values[i],animated,callback);x=x+s});if(ret===true){return values}},setClip:function(index,c,animated,callback){var t=this;if(typeof animated=='undefined'||animated!==false){t.animateClip(index,c,callback)}else{t.cssClip(index,c,callback)}},animateClip:function(index,c,callback){var t=this,rect=typeof c=='string'?c:t.rect([c]);t.d.elObj.children().eq(index).stop().animate({clip:rect},t.o.animationSpeed,function(){if(jQuery.isFunction(callback)){callback()}})},cssClip:function(index,c,callback){var t=this,rect=typeof c=='string'?c:t.rect([c]);t.d.elObj.children().eq(index).stop().css('clip',rect);if(jQuery.isFunction(callback)){callback()}},showControl:function(index){var t=this;if(t.o.autoOpenControl!==true)return;jQuery(t.d.c).children().eq(index).children('ul').show().css('visibility','visible')},hideControl:function(index){var t=this;if(t.o.autoOpenControl!==true||!t.isControl(t.o.control))return;if(jQuery(t.d.c).find('ul').length<=0)return;if(typeof index=='undefined'){jQuery(t.d.c).find('ul').hide().css('visibility','hidden')}else{jQuery(t.d.c).children().eq(index).children('ul').hide().css('visibility','hidden')}},getClipValues:function(){var t=this,values=[];t.debug(t.d.elObj.children().first().css('clip'));if(t.o.autoCliping===true){values=t.setEachChildren((t.d.elObj.width()/t.d.elObj.children().length),animated,callback)}else{t.d.elObj.children().each(function(){values[jQuery(this).index()]=jQuery(this).css('clip')})}return values},rect:function(c){var t=this;if(typeof c==='undefined'){t.debug('undefined coordinates in rect()');return t.rect([0,0,0,0])}return'rect('+c[0]+'px '+c[1]+'px '+c[2]+'px '+c[3]+'px)'},isControl:function(selector){var t=this;if(jQuery(t.d.c)[0]==jQuery(selector)[0]){return true}return false},trigger:function(trigger,index,callback){var t=this,i=index;if(jQuery.isFunction(trigger)){trigger.apply(t,[i])}if(jQuery.isFunction(callback)){callback()}},debug:function(msg){if(this.o.debug!==true)return;if(window.console){window.console.log(msg)}else{if(jQuery('#facetsDebug').length==0){jQuery('<div id="facetsDebug"><div><b>Facets-debugger:</b></div></div>').appendTo(document.body)}jQuery('#facetsDebug').prepend('<div>'+msg+'</div>')}}}})(jQuery);
