////////////////////////////////////////////// 
//        SoundOutTheBox contentFlow        // 
//  Copyright © SoundOutTheBox 2012-2013    // 
//           License-CC-BY-NC-ND            // 
////////////////////////////////////////////// 
(function(e){e.widget("mui.contentFlow",{options:{publicVariables:{Name:{value:"no name",type:"StringData",dynamic:!1},Left:{value:0,type:"IntegerData",dynamic:!1},Top:{value:0,type:"IntegerData",dynamic:!1},Width:{value:400,type:"IntegerData",dynamic:!1},Height:{value:200,type:"IntegerData",dynamic:!1},SelectedItem:{value:0,type:"IntegerData",dynamic:!0},CurrentItem:{value:0,type:"IntegerData",write:!0,dynamic:!0},Items:{value:'[ "./img/ACDC.jpg", "./img/BlackEyedPeas.jpeg", "./img/DaftPunk.jpg", "./img/Muse.jpg", "./img/Nirvana.jpg", "./img/RedHotChiliPeppers.jpg" ]',
type:"StringData",write:!0,dynamic:!0},CircularFlow:{value:["no","yes"],type:"EnumData",defaultvalue:"yes",dynamic:!1},MaxItemHeight:{value:100,type:"IntegerData",dynamic:!1},ReflectionHeight:{value:0.5,type:"RealData",dynamic:!1},Visible:{value:["no","yes"],type:"EnumData",defaultvalue:"yes",write:!0,dynamic:!0}},privateVariables:{pageNumber:0,motifType:0,userScreen:0,lastClick:0,myContentFlow:null},config:{main:"contentFlow.js",description:"contentFlow is a image selector.",author:"SoundOutTheBox",
version:"1.0.0.0.Final",dependencies:["./js/contentflow.css","./js/contentflow.min.js"],widgetID:"92946899969762696b9c3767659d679796616c6c6e3594926d9c966b666c686b",widgetPackages:["666a6c6e956a63986f6c6692659e68676d62676a6f3163977098976996676e6c"]}},_create:function(){},_init:function(){},_destroy:function(){},_setOption:function(){e.Widget.prototype._setOption.apply(this,arguments)},_render:function(){var b=this,a=b.options.publicVariables,c=b.element,f=a.Top.value,d=a.Height.value,k=a.Left.value,i=a.Width.value,j=eval(a.Items.value),h=a.CircularFlow.value,g=
a.ReflectionHeight.value,m=a.MaxItemHeight.value,l=b.options.privateVariables;console.log("_render()  object="+a.Name.value);c.disableSelection();c.css({left:k+"px",top:f+"px",width:i+"px",height:d+"px"});c.addClass("dynamicObject");e("<div id='contentFlow3' class='ContentFlow' style='height: 120px;'><div class='loadIndicator'><div class='indicator'></div></div><div id='testFlow' class='flow'></div></div>").appendTo(c);l.myContentFlow=new ContentFlow("contentFlow3",{reflectionHeight:g,circularFlow:h!==
"no"?1:0,onclickActiveItem:b.notifyActiveItemClicked,onMakeActive:b.notifyMakeActiveEvent,maxItemHeight:m});l.myContentFlow.init();f=UTIL.getDirectoryByScriptFileName("contentFlow.js");d=j.length;k=document.getElementById("testFlow");for(i=0;i<d;i++)h=document.createElement("div"),h.setAttribute("class","item"),g=document.createElement("img"),g.setAttribute("class","content"),g.setAttribute("src",f+j[i]),e(g).appendTo(h),e(h).appendTo(e(k)),l.myContentFlow.addItem(g,"last"),e(c).bind("onNotifyActiveItemClicked",
function(a,c){b.setStatus(c,!1)}),e(c).bind("onNotifyMakeActiveEvent",function(a,c){b.setActiveItem(c,!1)});b.setVisible(a.Visible.value)},readFromXML:function(b){var a=this.options.publicVariables,b=e(b);a.Name.value=UTIL.getStringAttr(b,"Name",a.Name.value);a.SelectedItem.value=UTIL.getIntAttr(b,"SelectedItem",a.SelectedItem.value);a.CurrentItem.value=UTIL.getIntAttr(b,"CurrentItem",a.CurrentItem.value);a.Items.value=UTIL.getStringAttr(b,"Items",a.Items.value);a.CircularFlow.value=UTIL.getStringAttr(b,
"CircularFlow",a.CircularFlow.value);a.MaxItemHeight.value=UTIL.getIntAttr(b,"MaxItemHeight",a.MaxItemHeight.value);a.ReflectionHeight.value=UTIL.getRealAttr(b,"ReflectionHeight",a.ReflectionHeight.value);a.Visible.value=UTIL.getStringAttr(b,"Visible",a.Visible.value);UTIL.readPositionFromXML(b,a)},notifyActiveItemClicked:function(){for(var b=this.getActiveItem(),a=this.getNumberOfItems(),c=0,f=document.getElementById(this.Container.id),f=e(f).parent(),d=0;d<a;d++)if(b===this.getItem(d)){c=d+1;break}c!=
-1&&e(f).trigger("onNotifyActiveItemClicked",[c])},notifyMakeActiveEvent:function(){for(var b=this.getActiveItem(),a=this.getNumberOfItems(),c=0,f=document.getElementById(this.Container.id),f=e(f).parent(),d=0;d<a;d++)if(b===this.getItem(d)){c=d+1;break}c!=-1&&e(f).trigger("onNotifyMakeActiveEvent",[c])},internalSetStatus:function(b,a){var c=this.options.publicVariables;if(b!==c.SelectedItem.value)c.SelectedItem.value=b,a&&this._trigger("propertyChange",null,Object({name:this.options.publicVariables.Name.value+
".SelectedItem",property:"SelectedItem",value:c.SelectedItem.value}))},internalSetActiveItem:function(b,a){var c=this.options.publicVariables,e=this.options.privateVariables;if(b!==c.CurrentItem.value)c.CurrentItem.value=b,a?this._trigger("propertyChange",null,Object({name:this.options.publicVariables.Name.value+".CurrentItem",property:"CurrentItem",value:c.CurrentItem.value})):e.myContentFlow.moveTo(c.CurrentItem.value-1)},setStatus:function(b,a){var c=this.options.publicVariables;privateVariables=
this.options.privateVariables;currentDate=new Date;iCurrentTimeMs=currentDate.getTime();iDeltaMs=iCurrentTimeMs-privateVariables.lastClick;sendToClient=a===!1||a===void 0;if(a){if(console.log("setStatus object="+c.Name.value+" value="+b+" delta="+iDeltaMs+" BEFORE"),iDeltaMs<250){console.log("setStatus object="+c.Name.value+" value="+b+" delta="+iDeltaMs+" IGNORED");return}}else privateVariables.lastClick=iCurrentTimeMs;this.internalSetStatus(b,sendToClient)},setActiveItem:function(b,a){var c=this.options.publicVariables;
privateVariables=this.options.privateVariables;currentDate=new Date;iCurrentTimeMs=currentDate.getTime();iDeltaMs=iCurrentTimeMs-privateVariables.lastClick;sendToClient=a===!1||a===void 0;if(a){if(console.log("setActiveItem object="+c.Name.value+" value="+b+" delta="+iDeltaMs+" BEFORE"),iDeltaMs<250){console.log("setActiveItem object="+c.Name.value+" value="+b+" delta="+iDeltaMs+" IGNORED");return}}else privateVariables.lastClick=iCurrentTimeMs;this.internalSetActiveItem(b,sendToClient)},setItems:function(b){for(var a=
this.options.publicVariables,c=this.options.privateVariables,f=eval(b),d=c.myContentFlow.getNumberOfItems();d!=0;)d--,c.myContentFlow.rmItem(d);c.myContentFlow.init();for(var d=UTIL.getDirectoryByScriptFileName("contentFlow.js"),k=f.length,i=document.getElementById("testFlow"),j=0;j<k;j++){var h=document.createElement("div");h.setAttribute("class","item");var g=document.createElement("img");g.setAttribute("class","content");g.setAttribute("src",d+f[j]);e(g).appendTo(h);e(h).appendTo(e(i));c.myContentFlow.addItem(g,
"last")}a.Items.value=b},setVisible:function(b){var a=this.options.publicVariables,c=this.element;if(b!==a.Visible.value)a.Visible.value=b;a.Visible.value!=="no"?UTIL.setOpacity(c,1):UTIL.setOpacity(c,0)},onPropertyChange:function(b,a){switch(b){case "Items":this.setItems(a);break;case "CurrentItem":this.setActiveItem(a,!0);break;case "Visible":this.setVisible(a)}},onReleaseCapture:function(){}})})(jQuery);
