
Fx.Scroll=new Class({Extends:Fx,options:{offset:{'x':0,'y':0},wheelStops:true},initialize:function(element,options){this.element=this.subject=$(element);this.parent(options);var cancel=this.cancel.bind(this,false);if($type(this.element)!='element')this.element=$(this.element.getDocument().body);var stopper=this.element;if(this.options.wheelStops){this.addEvent('start',function(){stopper.addEvent('mousewheel',cancel);},true);this.addEvent('complete',function(){stopper.removeEvent('mousewheel',cancel);},true);}},set:function(){var now=Array.flatten(arguments);this.element.scrollTo(now[0],now[1]);},compute:function(from,to,delta){var now=[];var x=2;x.times(function(i){now.push(Fx.compute(from[i],to[i],delta));});return now;},start:function(x,y){if(!this.check(arguments.callee,x,y))return this;var offsetSize=this.element.getSize(),scrollSize=this.element.getScrollSize();var scroll=this.element.getScroll(),values={x:x,y:y};for(var z in values){var max=scrollSize[z]-offsetSize[z];if($chk(values[z]))values[z]=($type(values[z])=='number')?values[z].limit(0,max):max;else values[z]=scroll[z];values[z]+=this.options.offset[z];}
return this.parent([scroll.x,scroll.y],[values.x,values.y]);},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start('right',false);},toBottom:function(){return this.start(false,'bottom');},toElement:function(el){var position=$(el).getPosition(this.element);return this.start(position.x,position.y);}});


Fx.Slide=new Class({Extends:Fx,options:{mode:'vertical'},initialize:function(element,options){this.addEvent('complete',function(){this.open=(this.wrapper['offset'+this.layout.capitalize()]!=0);if(this.open&&Browser.Engine.webkit419)this.element.dispose().inject(this.wrapper);},true);this.element=this.subject=$(element);this.parent(options);var wrapper=this.element.retrieve('wrapper');this.wrapper=wrapper||new Element('div',{styles:$extend(this.element.getStyles('margin','position'),{'overflow':'hidden'})}).wraps(this.element);this.element.store('wrapper',this.wrapper).setStyle('margin',0);this.now=[];this.open=true;},vertical:function(){this.margin='margin-top';this.layout='height';this.offset=this.element.offsetHeight;},horizontal:function(){this.margin='margin-left';this.layout='width';this.offset=this.element.offsetWidth;},set:function(now){this.element.setStyle(this.margin,now[0]);this.wrapper.setStyle(this.layout,now[1]);return this;},compute:function(from,to,delta){var now=[];var x=2;x.times(function(i){now[i]=Fx.compute(from[i],to[i],delta);});return now;},start:function(how,mode){if(!this.check(arguments.callee,how,mode))return this;this[mode||this.options.mode]();var margin=this.element.getStyle(this.margin).toInt();var layout=this.wrapper.getStyle(this.layout).toInt();var caseIn=[[margin,layout],[0,this.offset]];var caseOut=[[margin,layout],[-this.offset,0]];var start;switch(how){case'in':start=caseIn;break;case'out':start=caseOut;break;case'toggle':start=(this.wrapper['offset'+this.layout.capitalize()]==0)?caseIn:caseOut;}
return this.parent(start[0],start[1]);},slideIn:function(mode){return this.start('in',mode);},slideOut:function(mode){return this.start('out',mode);},hide:function(mode){this[mode||this.options.mode]();this.open=false;return this.set([-this.offset,0]);},show:function(mode){this[mode||this.options.mode]();this.open=true;return this.set([0,this.offset]);},toggle:function(mode){return this.start('toggle',mode);}});Element.Properties.slide={set:function(options){var slide=this.retrieve('slide');if(slide)slide.cancel();return this.eliminate('slide').store('slide:options',$extend({link:'cancel'},options));},get:function(options){if(options||!this.retrieve('slide')){if(options||!this.retrieve('slide:options'))this.set('slide',options);this.store('slide',new Fx.Slide(this,this.retrieve('slide:options')));}
return this.retrieve('slide');}};Element.implement({slide:function(how,mode){how=how||'toggle';var slide=this.get('slide'),toggle;switch(how){case'hide':slide.hide(mode);break;case'show':slide.show(mode);break;case'toggle':var flag=this.retrieve('slide:flag',slide.open);slide[(flag)?'slideOut':'slideIn'](mode);this.store('slide:flag',!flag);toggle=true;break;default:slide.start(how,mode);}
if(!toggle)this.eliminate('slide:flag');return this;}});


var Tips=new Class({Implements:[Events,Options],options:{onShow:function(tip){tip.setStyle('visibility','visible');},onHide:function(tip){tip.setStyle('visibility','hidden');},showDelay:100,hideDelay:100,className:null,offsets:{x:16,y:16},fixed:false},initialize:function(){var params=Array.link(arguments,{options:Object.type,elements:$defined});this.setOptions(params.options||null);this.tip=new Element('div').inject(document.body);if(this.options.className)this.tip.addClass(this.options.className);var top=new Element('div',{'class':'tip-top'}).inject(this.tip);this.container=new Element('div',{'class':'tip'}).inject(this.tip);var bottom=new Element('div',{'class':'tip-bottom'}).inject(this.tip);this.tip.setStyles({position:'absolute',top:0,left:0,visibility:'hidden'});if(params.elements)this.attach(params.elements);},attach:function(elements){$$(elements).each(function(element){var title=element.retrieve('tip:title',element.get('title'));var text=element.retrieve('tip:text',element.get('rel')||element.get('href'));var enter=element.retrieve('tip:enter',this.elementEnter.bindWithEvent(this,element));var leave=element.retrieve('tip:leave',this.elementLeave.bindWithEvent(this,element));element.addEvents({mouseenter:enter,mouseleave:leave});if(!this.options.fixed){var move=element.retrieve('tip:move',this.elementMove.bindWithEvent(this,element));element.addEvent('mousemove',move);}
element.store('tip:native',element.get('title'));element.erase('title');},this);return this;},detach:function(elements){$$(elements).each(function(element){element.removeEvent('mouseenter',element.retrieve('tip:enter')||$empty);element.removeEvent('mouseleave',element.retrieve('tip:leave')||$empty);element.removeEvent('mousemove',element.retrieve('tip:move')||$empty);element.eliminate('tip:enter').eliminate('tip:leave').eliminate('tip:move');var original=element.retrieve('tip:native');if(original)element.set('title',original);});return this;},elementEnter:function(event,element){$A(this.container.childNodes).each(Element.dispose);var title=element.retrieve('tip:title');if(title){this.titleElement=new Element('div',{'class':'tip-title'}).inject(this.container);this.fill(this.titleElement,title);}
var text=element.retrieve('tip:text');if(text){this.textElement=new Element('div',{'class':'tip-text'}).inject(this.container);this.fill(this.textElement,text);}
this.timer=$clear(this.timer);this.timer=this.show.delay(this.options.showDelay,this);this.position((!this.options.fixed)?event:{page:element.getPosition()});},elementLeave:function(event){$clear(this.timer);this.timer=this.hide.delay(this.options.hideDelay,this);},elementMove:function(event){this.position(event);},position:function(event){var size=window.getSize(),scroll=window.getScroll();var tip={x:this.tip.offsetWidth,y:this.tip.offsetHeight};var props={x:'left',y:'top'};for(var z in props){var pos=event.page[z]+this.options.offsets[z];if((pos+tip[z]-scroll[z])>size[z])pos=event.page[z]-this.options.offsets[z]-tip[z];this.tip.setStyle(props[z],pos);}},fill:function(element,contents){(typeof contents=='string')?element.set('html',contents):element.adopt(contents);},show:function(){this.fireEvent('show',this.tip);},hide:function(){this.fireEvent('hide',this.tip);}});


SK.UI.Progress=function(options){this.ie6=document.all&&navigator.appVersion.indexOf("MSIE 6")!=-1?true:false;this.ie7=document.all&&navigator.appVersion.indexOf("MSIE 7")!=-1?true:false;this.ff2=navigator.userAgent.toLowerCase().indexOf("firefox/2")!=-1?true:false;this.ff1=navigator.userAgent.toLowerCase().indexOf("firefox/1")!=-1?true:false;this.mac=navigator.userAgent.toLowerCase().indexOf("macintosh")!=-1?true:false;this.ff2mac=this.ff2&&this.mac;this.ff1mac=this.ff1&&this.mac;this.safari=navigator.appVersion.indexOf("Safari")!=-1?true:false;this.ANIMATION_INTERVAL=60;this.ANIMATION_STEPS=24;this.FRAME_HEIGHT=60;this.WRAPPER_OPACITY=1.0;this.BG_OPACITY=0.7;this.options={};if(typeof options!='undefined')this.options=options;if(typeof this.options.callbacks=='undefined'){this.options.callbacks={};}
if(typeof this.options.placeholder=='undefined'){this.options.placeholder=$(document);}
this.disturbing_elements=[];this.init=function(message){this.create();this.reset();this.message=message;var self=this;window.addEvent('scroll',function(){self.center();});window.addEvent('resize',function(){self.center();});}
this.create=function(){if(this.options.zindex){$('progress_ui_wrapper').setStyles({'z-index':this.options.zindex});}}
this.destroy=function(){if(this.options.zindex)
$('progress_ui_wrapper').setStyles({'z-index':''});}
this.reset=function(){this.disturbing_elements=[];}
this.display=function(){this.collectDisturbingElements();this.hideDisturbingElements();this.center();this.displayContents();}
this.hide=function(){this.hideContents();this.displayDisturbingElements();this.destroy();}
this.displayContents=function(){$('progress_ui_message').innerHTML=this.message;$('progress_ui_wrapper').setStyles({'opacity':'0.0','display':'block'});var self=this;var complete_f=function(){if(self.options.callbacks.onafterdisplay){self.options.callbacks.onafterdisplay();}};var wrapper_opacity=this.WRAPPER_OPACITY;var bg_opacity=this.BG_OPACITY;if(this.options.duration==0){$('progress_ui_wrapper').setStyle('opacity',wrapper_opacity);$('progress_ui_background').setStyle('opacity',bg_opacity);complete_f();}else{var anim=new Fx.Morph('progress_ui_wrapper',{duration:this.options.duration?this.options.duration:200,transition:Fx.Transitions.Sine.easeOut,onComplete:complete_f});anim.start({opacity:wrapper_opacity});$('progress_ui_background').setStyles({'opacity':'0.0','display':'block'});var self=this;var anim=new Fx.Morph('progress_ui_background',{duration:this.options.duration?this.options.duration:200,transition:Fx.Transitions.Sine.easeOut});anim.start({opacity:bg_opacity});}
this.startImagesAnimation();}
this.startImagesAnimation=function(){var self=this;$('skwaiting_stripe').setStyle('display','block');var frame_id=1;this.images_animation_timer=window.setInterval(function(){self.displayImagesAnimationFrame(frame_id++);if(frame_id>self.ANIMATION_STEPS){frame_id=1;}},this.ANIMATION_INTERVAL);}
this.displayImagesAnimationFrame=function(frame_id){var top=-(frame_id-1)*this.FRAME_HEIGHT;$('skwaiting_stripe').setStyle('top',top);}
this.stopImagesAnimation=function(){window.clearTimeout(this.images_animation_timer);}
this.hideContents=function(){$('progress_ui_wrapper').setStyle('display','none');this.stopImagesAnimation();}
this.isFullOfBugsIE=function(){return((document.compatMode=='BackCompat'&&Browser.Engine.trident)||(document.compatMode!='BackCompat'&&Browser.Engine.trident4==true));}
this.center=function(){var p=$(this.options.placeholder);var size=p.getSize();var scroll=p.getScroll();var pos=p.getCoordinates();if(this.isFullOfBugsIE()){$('progress_ui_wrapper').setStyles({'left':scroll.x+pos.left,'top':scroll.y+pos.top});}else{var position=!p.get||p.get('tag').toLowerCase()=='body'?'fixed':p.getStyle('position')=='fixed'?'fixed':'absolute';$('progress_ui_wrapper').setStyles({'position':position,'left':0+pos.left,'top':0+pos.top});}
var objs=['progress_ui_wrapper','progress_ui_background','progress_ui_foreground','progress_ui_content'];for(var i=0;i<objs.length;i++){$(objs[i]).setStyle('width',size.x);$(objs[i]).setStyle('height',size.y);}}
this.hideDisturbingElements=function(){for(var i=0;i<this.disturbing_elements.length;i++){if($(this.disturbing_elements[i])&&$(this.disturbing_elements[i]).setStyle){$(this.disturbing_elements[i]).setStyle('display','none');}}}
this.displayDisturbingElements=function(){for(var i=0;i<this.disturbing_elements.length;i++){if($(this.disturbing_elements[i])&&$(this.disturbing_elements[i]).setStyle){$(this.disturbing_elements[i]).setStyle('display','');}
if(this.safari){this.patchSafariFlashElements(this.disturbing_elements[i],false);}}}
this.collectDisturbingElements=function(){var target_tags=['object','embed','param'];if(this.ie6)target_tags.push('select');for(var j=0;j<target_tags.length;j++){var objs=document.getElementsByTagName(target_tags[j]);for(var i=0;i<objs.length;i++){this.disturbing_elements.push(objs[i]);if(this.safari){this.patchSafariFlashElements(objs[i],false);}}}}
this.patchSafariFlashElements=function(e,undo){if(undo){var old_wmode=e.getAttribute('old_wmode');if(old_wmode)e.setAttribute('wmode',old_wmode);else e.removeAttribute('wmode');}else{var old_wmode=e.getAttribute('wmode');e.setAttribute('wmode','opaque');if(old_wmode)e.setAttribute('old_wmode',old_wmode);}}};


SK.UI.DesignSelectorThumbnailsUI=function(_options){var design_filter_effect;var large_view_effect;var selected_design_id=0;var zoom_design_id=0;var current_num_designs;var large_design_box=0;var large_view_y;var large_view_x;var design_config=null;var large_view_img_width=600;var large_view_img_height=450;var progress_zindex=6;var DESIGN_ID_PREFIX='design_';var ZOOM_ICON_ID_PREFIX='zoom_icon_';var THUMB_ID_PREFIX='thumb_';var COLOR_ID_PREFIX='color_';var designs=new Array();var options=!$defined(_options)?{}:_options;var user_filter=function(d){return true;}
var dropdowns_by_filter={'name':$(options.placeholders.filter_design),'color':$(options.placeholders.filter_color),'business':$(options.placeholders.filter_business),'year':$(options.placeholders.filter_year)};var fdropdown=$(options.placeholders.filter_type);var progress_ui=null;this.init=function(_design_config){var self=this;design_config=_design_config;this.preloadImages();this.initLargeView();this.initEffects();this.initDesigns();this.setInitiallySelectedDesign();}
this.getSelectedDesignID=function(){var objs=$$('.thumbselect');if(objs.length==0){return"";}
return objs[0].get('design_id');}
this.isSelectedDesignSupported=function(){var selected_design_id=this.getSelectedDesignID();if(selected_design_id==""){return false;}
if(design_config.some(function(d){return(d.id==selected_design_id&&(d.label==null||d.label==""));})){return true;}
return false;}
this.getDesignConfig=function(design_id){var designs=design_config.filter(function(d,index){if(d.id==design_id){d.index=index;return true;}return false;});if(designs.length>0)return designs[0];return null;}
this.initEffects=function(){design_filter_effect=new Fx.Morph(options.placeholders.info,{duration:1000,link:'cancel'});large_view_effect=new Fx.Morph('largeviewimg',{duration:800,link:'cancel'});var self=this;large_view_effect.addEvent('complete',function(){self.closeLargeViewComplete();});}
this.initDesigns=function(){design_config.each(function(item,index){designs.include(item.name)});this.initFilters();current_num_designs=this.fillUpDesigns();var self=this;this.display_visible_designs_handle=null;$(options.placeholders.scroll_wrapper).addEvent('scroll',function(){$clear(self.display_visible_designs_handle);self.display_visible_designs_handle=self.displayVisibleDesigns.delay(500,self);});this.initialDisplayVisibleDesigns();}
this.refresh=function(){this.displayVisibleDesigns();}
this.setInitiallySelectedDesign=function(){if(options.selected_design_id){var design_id=null;var matching_designs=$$('.thumbdiv').filter(function(e){if(e.get('design_id').toLowerCase()==options.selected_design_id.toLowerCase()){design_id=e.get('id');return true;}
return false;},this);design_id=matching_designs.length>0?matching_designs[0].get('design_id'):null;if(design_id){var self=this;this.tryToScrollToDesign(this.generateDesignID(design_id),function(){$(self.generateDesignID(design_id)).fireEvent('click');});}}}
this.tryToScrollToDesign=function(design_id,callback){if(!$(design_id))return
this.scrollToDesign(design_id);this.markAsSelected(design_id,callback);}
this.markAsSelected=function(design_id,callback){if($(design_id).hasClass('dummy')){this.tryToScrollToDesign.delay(100,this,[design_id,callback]);return;}
if(callback)callback();}
this.applyUserFilter=function(f){user_filter=f;var new_design_config=[];for(var i=0;i<design_config.length;i++){if(user_filter(design_config[i])){new_design_config.push(design_config[i]);}}
design_config=new_design_config;this.initFilters();this.setDesignFilter();this.displayVisibleDesigns();}
this.initFilters=function(){var filters=[{id:'name',text:'By Design'},{id:'color',text:'By Color'},{id:'business',text:'By Industry'},{id:'year',text:'By Year'}];var sort_f=function(a,b){return a<b?-1:(a>b?1:0);};fdropdown.empty();(new Element('option',{value:'all',html:'Show All'})).inject(fdropdown);filters.each(function(f){var items=this.extractDesignFilterValues(f.id);items.sort(sort_f);var dropdown=this.getDropdownByFilter(f.id);if(!dropdown)return;dropdown.empty();items.each(function(item,index){(new Element('option',{value:item,html:item})).inject(dropdown);});if(items.length>0){(new Element('option',{value:f.id,html:f.text})).inject(fdropdown);}
dropdown.store('cdh',this);dropdown.addEvent('change',function(){var h=this.retrieve('cdh');h.setDesignFilter(f.id,this.value);if(Browser.Engine.trident){this.focus();}},this);},this);fdropdown.store('cdh',this);fdropdown.set("value","all");fdropdown.addEvent('change',function(){var h=this.retrieve('cdh');if(this.value=="all"){h.setDesignFilter();}else{var dropdown=h.getDropdownByFilter(this.value);h.setDesignFilter(this.value,dropdown.get("value"));}},this);}
this.extractDesignFilterValues=function(type){var values={};design_config.each(function(item){if($type(item[type])=='array'){item[type].each(function(v){values[v]=true;});}else if($type(item[type])=='string'){values[item[type]]=true;}});var values_arr=[];for(var i in values)values_arr.push(i);return values_arr;}
this.toggleVisibility=function(element){$(element).toggleClass("custom_hideme");}
this.getDropdownByFilter=function(type){return dropdowns_by_filter[type];}
this.showDesign=function(el){el.setStyle('visibility','visible');}
this.matchesDesignFilter=function(design,type,value){if(type=="all")return true;if(!$type(design[type]))return false;if(value=="")return true;if($type(design[type])=='string'){return design[type].toLowerCase()==value.toLowerCase();}
if($type(design[type])=='array'){return design[type].indexOf(value)!=-1?true:false;}
return false;}
this.initialDisplayVisibleDesigns=function(){var placeholders=this.getDesignsPlaceholders();var visible_placeholders=this.getVisiblePlaceholders(placeholders);if(visible_placeholders.length==0){this.initialDisplayVisibleDesigns.delay(1000,this);return;}
this.displayVisibleDesigns();}
this.displayVisibleDesigns=function(){var placeholders=this.getDesignsPlaceholders();var visible_placeholders=this.getVisiblePlaceholders(placeholders);this.loadVisiblePlaceholders(visible_placeholders);}
this.getDesignsPlaceholders=function(){return this.placeholders;}
this.setDesignsPlaceholders=function(){this.placeholders=$$('.thumbdiv');}
this.getVisiblePlaceholders=function(placeholders){var top=$(options.placeholders.designs_wrapper).getPosition().y;var width=$(options.placeholders.designs_wrapper).getSize().x;var window_size=$(options.placeholders.scroll_wrapper).getSize();var window_scroll=$(options.placeholders.scroll_wrapper).getScroll();window_size.x=width;window_scroll.y=$(options.placeholders.designs_wrapper)==$(options.placeholders.scroll_wrapper)?window_scroll.y:window_scroll.y-top;return placeholders.filter(function(placeholder,index){return this.isVisiblePlaceholder(placeholder,index,window_size,window_scroll);},this);}
this.isVisiblePlaceholder=function(placeholder,index,window_size,window_scroll){var sz=placeholder.getSize();var pos=this.smartCalculatePlaceholderPosition(sz,index,window_size);var result=this.isVisiblePoint(pos,window_size,window_scroll)||this.isVisiblePoint({x:pos.x+sz.x,y:pos.y+sz.y},window_size,window_scroll);return result;}
this.smartCalculatePlaceholderPosition=function(size,index,window_size){var avg_cols=Math.floor(window_size.x/size.x);var col=index%avg_cols;var row=Math.floor(index/avg_cols);var col=col*size.x;var row=row*size.y;return{x:col,y:row};}
this.isVisiblePoint=function(pos,window_size,window_scroll){return(pos.x>=window_scroll.x&&pos.x<=window_scroll.x+window_size.x&&pos.y>=window_scroll.y&&pos.y<=window_scroll.y+window_size.y);}
this.loadVisiblePlaceholders=function(placeholders){placeholders.filter(function(placeholder){return placeholder.hasClass('dummy');},this).each(function(placeholder,index){this.loadDesignInPlaceholder(placeholder,placeholder.retrieve('config'),index);},this);}
this.loadDesignInPlaceholder=function(placeholder,design,index){var self=this;var t1=placeholder;t1.empty();t1.set('id',this.generateDesignID(design.id));t1.set('design_id',design.id);t1.setStyles({'display':'block'});t1.addEvents({'click':function(){$$('.thumbselect').removeClass('thumbselect');this.addClass('thumbselect');selected_design_id=this.get('id').substring(DESIGN_ID_PREFIX.length);}});t1.removeClass('dummy');if(selected_design_id&&design.id.toLowerCase()==selected_design_id.toLowerCase()){t1.addClass('thumbselect');}
var t2=new Element('div',{'id':ZOOM_ICON_ID_PREFIX+design.id,'class':'icons','title':'Click for Large view','events':{'click':function(e){zoom_design_id=this.get('id').substring(ZOOM_ICON_ID_PREFIX.length);self.setLargeView();self.openLargeView();e=e||event;e.stopPropagation?e.stopPropagation():e.cancelBubble=true;}}});var t3=new Element('div',{'class':'thumbimg waiting','id':THUMB_ID_PREFIX+design.id,'title':'Click to select this design'});var t4=new Element('div',{'class':'thumbcaptiondiv'});var t5=new Element('p',{'class':'thumbcaption','html':design.name+" "+design.theme});var t6=(fdropdown.get("value")=='all')?new Element('a',{'class':'thumbseecolors','href':'javascript:void(null)','html':'See all colors for this design','dname':design.name}).addEvent('click',function(){self.setDesignFilter("name",this.get('dname'));},this):new Element('a',{'class':'thumbseecolors','href':'javascript:void(null)','html':'Click to select this design'});var t7=null;if(design.label!=null&&design.label!=""){t7=new Element('div',{'class':'label '+design.label,'style':design.label_style?design.label_style:"",'title':design.label}).appendText(design.label);}
t2.inject(t3);t3.inject(t1);t4.inject(t1);t5.inject(t4);t6.inject(t4);if(t7)t7.inject(t3);var img=new Element('img',{src:design.thumb,styles:{display:Browser.Engine.trident?'block':'none',visibility:'hidden'}});img.addEvent('load',function(){this.setStyle('display','block');});img.inject(t3,'bottom');var showdelay=index*120;this.showDesign.delay(showdelay,this,img);t3.store('zoom_icon_id',ZOOM_ICON_ID_PREFIX+design.id);t3.addEvent('mouseenter',function(){var id=this.retrieve('zoom_icon_id');$(id).setStyle('display','block');});t3.addEvent('mouseleave',function(){var id=this.retrieve('zoom_icon_id');$(id).setStyle('display','none');});t1.addEvent('mouseenter',function(){this.addClass('over');});t1.addEvent('mouseleave',function(){this.removeClass('over');});}
this.fillUpDesigns=function(type,value){var self=this;if(typeof(type)=="undefined")type="all";if(typeof(value)=="undefined")value="";$(options.placeholders.designs).empty();$(options.placeholders.designs_wrapper).scrollTo(0,0);var num_designs=0;for(var i=0;i<design_config.length;i++){if(this.matchesDesignFilter(design_config[i],type,value)){var element=new Element('div',{'id':this.generateDesignID(design_config[i].id),'class':'thumbdiv dummy'});element.store('config',design_config[i]);element.set('design_id',design_config[i].id);element.inject($(options.placeholders.designs));new Element('div',{'class':'thumbimg waiting'}).inject(element);num_designs++;}}
this.setDesignsPlaceholders();this.displayVisibleDesigns();return num_designs;}
this.setDesignFilter=function(type,value){if(typeof(type)=="undefined")type="all";if(typeof(value)=="undefined")filter="";var filter_ddowns=[];for(var i in dropdowns_by_filter){filter_ddowns.push(i);}
filter_ddowns.each(function(id){var dropdown=this.getDropdownByFilter(id);dropdown.setStyle('display','none');},this);var dropdown=this.getDropdownByFilter(type);if(dropdown){dropdown.setStyle('display','block');dropdown.set('value',value);if(Browser.Engine.webkit){dropdown.getParent().setStyle('width',dropdown.getSize().x);}}
fdropdown.set("value",type);current_num_designs=this.fillUpDesigns(type,value);var self=this;var msg="";var back=null;var back_element=new Element('a',{'href':'javascript:void(null)','html':'Back to all designs'}).addEvent('click',function(){self.setDesignFilter()},this);switch(type){case"all":msg=current_num_designs==1?"Showing 1 design":"Showing all {d} designs".substitute({d:current_num_designs});break;case"name":msg=current_num_designs==1?"Showing <b>{s}</b> in 1 color".substitute({s:dropdown.get("value"),d:current_num_designs}):"Showing <b>{s}</b> in {d} colors".substitute({s:dropdown.get("value"),d:current_num_designs});back=back_element;break;default:msg=current_num_designs==1?"Showing <b>{s}</b> in 1 design".substitute({s:dropdown.get("value"),d:current_num_designs}):"Showing <b>{s}</b> in {d} designs".substitute({s:dropdown.get("value"),d:current_num_designs});back=back_element;break;}
msg+=".&nbsp;";$(options.placeholders.info).set('html',msg);if(back)back.inject($(options.placeholders.info));var width=$(options.placeholders.info).getSize().x;$(options.placeholders.info_bg).addClass('num_designs_msg_bg');design_filter_effect.start({'background-position':['-800',0]});design_filter_effect.chain(function(){$(options.placeholders.info_bg).removeClass('num_designs_msg_bg');var f=function(){self.hideProgressBar();if(type=="all"){$(options.placeholders.info).set('html','');}}
f.delay(1500);});}
this.hideProgressBar=function(){$(options.placeholders.info).setStyle('background-position','9999px');}
this.setLargeView=function(){var self=this;var img=$('largeviewimg');var design=this.getDesignConfig(zoom_design_id);if(!this.isLargeViewOpen()){img.setProperty('src',design.thumb);}
if(this.isLargeViewOpen()){this.openLargeViewLoadingProgress();}
img.removeEvents();img.addEvents({'load':function(){self.closeLargeViewLoadingProgress();}});img.setProperty('src',design.large);$('largeviewdesignname').set('html',design.name+" "+design.theme);}
this.openLargeViewLoadingProgress=function(){if(progress_ui)progress_ui.hide();progress_ui=new SK.UI.Progress({placeholder:$('largeviewimg'),duration:0,zindex:progress_zindex});progress_ui.init("Loading...");progress_ui.display();}
this.closeLargeViewLoadingProgress=function(){if(progress_ui)progress_ui.hide();}
this.largeViewChange=function(direction){var design=this.getDesignConfig(zoom_design_id);for(var i=0;i<design_config.length;i++){var id=(parseInt(design.index)+(i*direction)+design_config.length+direction)%design_config.length;if($(this.generateDesignID(design_config[id].id))!=null){zoom_design_id=design_config[id].id;this.setLargeView();return;}}}
this.largeViewNext=function(){this.largeViewChange(1);}
this.largeViewPrev=function(){this.largeViewChange(-1);}
this.handleKeyPressed=function(event){switch(event.key){case'right':case'space':case'down':this.largeViewNext();break;case'left':case'up':case'backspace':this.largeViewPrev()
break;}}
this.initLargeView=function(){var self=this;['largeviewimg'].each(function(e){new Element('img',{"id":e,"class":"largeview"}).inject($(options.placeholders.main));});['largeviewshadow','largeviewclose','largeviewleft','largeviewright'].each(function(e){var el=new Element('div',{"id":e,"class":"largeview"});if(e!='largeviewshadow'){el.addEvent('mouseenter',function(){this.addClass('over');});el.addEvent('mouseleave',function(){this.removeClass('over');});}
el.inject($(options.placeholders.main));});new Element('div',{"id":"largeviewcaption","class":"largeview"}).inject($(options.placeholders.main));new Element('div',{"id":"largeviewdesignname"}).inject($('largeviewcaption'));new Element('div',{"id":"largeviewdesignselect"}).inject($('largeviewcaption'));new Element('a',{html:'Select this design',href:'javascript:void(null)'}).addEvent('click',function(){$(self.getZoomDesignElementID()).fireEvent('click');self.closeLargeView();}).inject($('largeviewdesignselect'));$('largeviewimg').addEvent('click',function(){self.closeLargeView();});$('largeviewshadow').addEvent('click',function(){self.closeLargeView();});$('largeviewclose').addEvent('click',function(){self.closeLargeView();});$('largeviewleft').addEvent('click',function(){self.largeViewPrev();});$('largeviewright').addEvent('click',function(){self.largeViewNext();});$(window).addEvent('keyup',function(evt){if(self.isLargeViewOpen()){self.handleKeyPressed(evt);}});$(window).addEvent('scroll',function(evt){if(self.isLargeViewOpen()){self.handleLargeViewScroll(evt);}});$(window).addEvent('resize',function(evt){if(self.isLargeViewOpen()){self.handleLargeViewScroll(evt);}});}
this.getCenterLargeViewPos=function(){return{x:$(window).getScroll().x+$(options.placeholders.main).getPosition().x+($(options.placeholders.main).getSize().x-large_view_img_width)/2,y:$(window).getScroll().y+($(window).getSize().y-large_view_img_height)/2};}
this.openLargeView=function(){var myid=THUMB_ID_PREFIX+zoom_design_id;var mypos=$(myid).getPosition(options.placeholders.designs_wrapper);var holder=$(options.placeholders.designs_wrapper).getPosition();var scroll=Browser.Engine.trident?$(options.placeholders.designs_wrapper).getScroll():{x:0,y:0};mypos.x+=holder.x+scroll.x;mypos.y+=holder.y+scroll.y;var lv_pos=this.getCenterLargeViewPos();large_view_y=lv_pos.y;large_view_x=lv_pos.x;$('largeviewimg').setStyles({'opacity':'0','background-color':'white'});large_view_effect.start({'opacity':['0','1'],'left':[mypos.x,large_view_x],'top':[mypos.y,large_view_y],'width':['160px','600px'],'height':['120px','450px']});$('largeviewimg').setStyle('display','block');$('largeviewshadow').setStyle('display','none');$('largeviewclose').setStyle('display','none');$('largeviewleft').setStyle('display','none');$('largeviewright').setStyle('display','none');$('largeviewcaption').setStyle('display','none');this.large_view=true;}
this.handleLargeViewScroll=function(event){var lv_pos=this.getCenterLargeViewPos();large_view_x=lv_pos.x;large_view_y=lv_pos.y;this.positionLargeView();}
this.scrollToDesign=function(design_id){if($(design_id)!=null){var mysize=$(design_id).getSize();var mypos=$(design_id).getPosition(options.placeholders.designs_wrapper);var sz=$(options.placeholders.designs_wrapper).getSize();var sc=$(options.placeholders.designs_wrapper).getScroll();if(Browser.Engine.trident){mypos.x+=sc.x;mypos.y+=sc.y;}
if(!this.isVisiblePoint(mypos,sz,sc)&&!this.isVisiblePoint({x:mypos.x+mysize.x,y:mypos.y+mysize.y},sz,sc)){$(options.placeholders.designs_wrapper).scrollTo(mypos.x,mypos.y);}}}
this.closeLargeView=function(){this.closeLargeViewLoadingProgress();this.scrollToDesign(THUMB_ID_PREFIX+zoom_design_id);$('largeviewshadow').setStyle('display','none');$('largeviewclose').setStyle('display','none');$('largeviewleft').setStyle('display','none');$('largeviewright').setStyle('display','none');$('largeviewcaption').setStyle('display','none');var myid=THUMB_ID_PREFIX+zoom_design_id;var mypos={};if($(myid)!=null){mypos=$(myid).getPosition();var sc=$(options.placeholders.designs_wrapper).getScroll();if(Browser.Engine.trident){mypos.x+=sc.x;mypos.y+=sc.y;}}else{mypos.x=large_view_x+(450/2)-120;mypos.y=large_view_y+(600/2)-160;}
large_view_effect.start({'opacity':['1','0'],'left':[large_view_x,mypos.x],'top':[large_view_y,mypos.y],'width':['600px','160px'],'height':['450px','120px']});this.large_view=false;}
this.isLargeViewOpen=function(){return this.large_view==true;}
this.closeLargeViewComplete=function(){if($('largeviewimg').getStyle('opacity')==0){$('largeviewimg').setStyle('display','none');}else{this.positionLargeView();}}
this.positionLargeView=function(){$('largeviewimg').setStyles({'left':large_view_x,'top':large_view_y,'display':'block',border:'none'});$('largeviewshadow').setStyles({'left':large_view_x-50,'top':large_view_y-50,'display':'block'});$('largeviewclose').setStyles({'left':large_view_x+576,'top':large_view_y-25,'display':'block'});$('largeviewleft').setStyles({'left':large_view_x-36,'top':large_view_y+200,'display':'block'});$('largeviewright').setStyles({'left':large_view_x+583,'top':large_view_y+200,'display':'block'});$('largeviewcaption').setStyles({'left':large_view_x,'top':large_view_y+425,'display':'block'});}
this.getZoomDesignElementID=function(){return this.generateDesignID(zoom_design_id);}
this.generateDesignID=function(id){return DESIGN_ID_PREFIX+id;}
this.preloadImages=function(){['largeviewshadow','largeviewclose','largeviewleft','largeviewright','largeviewcaption'].each(function(e){var el=new Element('div',{id:e,styles:{display:'block',position:'absolute',left:-10000,top:-10000}});el.inject($(document.body));});['largeviewshadow','largeviewclose','largeviewleft','largeviewright','largeviewcaption'].each(function(e){$(e).dispose();})}}
SK.UI.DesignSelectorThumbnails=function(options)
{this.options=options||{};this.handle=null;this.init=function(){var self=this;var url_params={"mode":"short"};if(this.options.user_id){url_params.user_id=this.options.user_id;}
if(this.options.tag){url_params.tag=this.options.tag;}
if(!url_params.user_id&&!url_params.tag){var tmp_r=new Request.JSON({url:'/Shared/Html/json_default_pgroup.html',onSuccess:function(json,text){var pgroup=json;url_params.tag='TAG'+pgroup.package_code;self.default_tag=url_params.tag;self.fetchDesigns(url_params);}}).get();}else{this.fetchDesigns(url_params);}}
this.getDefaultTag=function(){return this.default_tag||"";}
this.fetchDesigns=function(url_params){var self=this;var r=new Request.JSON({url:'/Shared/Html/json_designs_collections.html',onSuccess:function(json,text){var design_config=json;self.handle=new SK.UI.DesignSelectorThumbnailsUI({placeholders:{info:"num_designs_msg",info_bg:"num_designs_msg_bg",main:"design_selector_ui",designs:"design_list",designs_wrapper:"design_mask",scroll_wrapper:self.options.scroll_wrapper||"design_mask",filter_type:"filter_type",filter_design:"filter_design",filter_color:"filter_color",filter_business:"filter_business",filter_year:"filter_year"},selected_design_id:self.options.selected_design_id?self.options.selected_design_id:''});self.handle.init(design_config);}}).get(url_params);}
this.applyUserFilter=function(f){this.handle.applyUserFilter(f);}
this.display=function(){var main=$('design_selector_ui');if(main)main.setStyle('display','block');}
this.hide=function(){var main=$('design_selector_ui');if(main)main.setStyle('display','none');}
this.resize=function(width,height){$('design_mask').setStyles({width:width,height:height});this.refresh();}
this.getSelectedDesignID=function(){return this.handle.getSelectedDesignID();}
this.getDesignConfig=function(design_id){return this.handle.getDesignConfig(design_id);}
this.isSelectedDesignSupported=function(){return this.handle.isSelectedDesignSupported();}
this.refresh=function(){if(this.handle)this.handle.refresh();}}


SK.UI.DesignSelectorPreview=new Class({handle:null,initialize:function(options){if(typeof(options)=='undefined'){options={};}
options.scroll_wrapper=window;this.handle=new SK.UI.DesignSelectorThumbnails(options);this.handle.init();},display:function(){this.handle.display();}});

