var DSD;if(!DSD){DSD={};}if(!DSD.Widget){DSD.Widget={};}DSD.Widget.TabbedPanels=function(element,opts){this.element=this.getElement(element);this.defaultTab=0;this.tabSelectedClass="TabbedPanelsTabSelected";this.tabHoverClass="TabbedPanelsTabHover";this.tabFocusedClass="TabbedPanelsTabFocused";this.panelVisibleClass="TabbedPanelsContentVisible";this.focusElement=null;this.hasFocus=false;this.currentTabIndex=0;this.enableKeyboardNavigation=true;this.nextPanelKeyCode=DSD.Widget.TabbedPanels.KEY_RIGHT;this.previousPanelKeyCode=DSD.Widget.TabbedPanels.KEY_LEFT;DSD.Widget.TabbedPanels.setOptions(this,opts);if(typeof(this.defaultTab)=="number"){if(this.defaultTab<0){this.defaultTab=0;}else{var count=this.getTabbedPanelCount();if(this.defaultTab>=count){this.defaultTab=(count>1)?(count-1):0;}}this.defaultTab=this.getTabs()[this.defaultTab];}if(this.defaultTab){this.defaultTab=this.getElement(this.defaultTab);}this.attachBehaviors();};DSD.Widget.TabbedPanels.prototype.getElement=function(ele){if(ele&&typeof ele=="string"){return document.getElementById(ele);}return ele;};DSD.Widget.TabbedPanels.prototype.getElementChildren=function(element){var children=[];var child=element.firstChild;while(child){if(child.nodeType==1){children.push(child);}child=child.nextSibling;}return children;};DSD.Widget.TabbedPanels.prototype.addClassName=function(ele,className){if(!ele||!className||(ele.className&&ele.className.search(new RegExp("\\b"+className+"\\b"))!=-1)){return;}ele.className+=(ele.className?" ":"")+className;};DSD.Widget.TabbedPanels.prototype.removeClassName=function(ele,className){if(!ele||!className||(ele.className&&ele.className.search(new RegExp("\\b"+className+"\\b"))==-1)){return;}ele.className=ele.className.replace(new RegExp("\\s*\\b"+className+"\\b","g"),"");};DSD.Widget.TabbedPanels.setOptions=function(obj,optionsObj,ignoreUndefinedProps){if(!optionsObj){return;}for(var optionName in optionsObj){if(ignoreUndefinedProps&&optionsObj[optionName]==undefined){continue;}obj[optionName]=optionsObj[optionName];}};DSD.Widget.TabbedPanels.prototype.getTabGroup=function(){if(this.element){var children=this.getElementChildren(this.element);if(children.length){return children[0];}}return null;};DSD.Widget.TabbedPanels.prototype.getTabs=function(){var tabs=[];var tg=this.getTabGroup();if(tg){tabs=this.getElementChildren(tg);}return tabs;};DSD.Widget.TabbedPanels.prototype.getContentPanelGroup=function(){if(this.element){var children=this.getElementChildren(this.element);if(children.length>1){return children[1];}}return null;};DSD.Widget.TabbedPanels.prototype.getContentPanels=function(){var panels=[];var pg=this.getContentPanelGroup();if(pg){panels=this.getElementChildren(pg);}return panels;};DSD.Widget.TabbedPanels.prototype.getIndex=function(ele,arr){ele=this.getElement(ele);if(ele&&arr&&arr.length){for(var i=0;i<arr.length;i++){if(ele==arr[i]){return i;}}}return -1;};DSD.Widget.TabbedPanels.prototype.getTabIndex=function(ele){var i=this.getIndex(ele,this.getTabs());if(i<0){i=this.getIndex(ele,this.getContentPanels());}return i;};DSD.Widget.TabbedPanels.prototype.getCurrentTabIndex=function(){return this.currentTabIndex;};DSD.Widget.TabbedPanels.prototype.getTabbedPanelCount=function(ele){return Math.min(this.getTabs().length,this.getContentPanels().length);};DSD.Widget.TabbedPanels.addEventListener=function(element,eventType,handler,capture){try{if(element.addEventListener){element.addEventListener(eventType,handler,capture);}else{if(element.attachEvent){element.attachEvent("on"+eventType,handler);}}}catch(e){}};DSD.Widget.TabbedPanels.prototype.cancelEvent=function(e){return false;};DSD.Widget.TabbedPanels.prototype.onTabClick=function(e,tab){this.showPanel(tab);return this.cancelEvent(e);};DSD.Widget.TabbedPanels.prototype.onTabMouseOver=function(e,tab){this.addClassName(tab,this.tabHoverClass);return false;};DSD.Widget.TabbedPanels.prototype.onTabMouseOut=function(e,tab){this.removeClassName(tab,this.tabHoverClass);return false;};DSD.Widget.TabbedPanels.prototype.onTabFocus=function(e,tab){this.hasFocus=true;this.addClassName(tab,this.tabFocusedClass);return false;};DSD.Widget.TabbedPanels.prototype.onTabBlur=function(e,tab){this.hasFocus=false;this.removeClassName(tab,this.tabFocusedClass);return false;};DSD.Widget.TabbedPanels.KEY_UP=38;DSD.Widget.TabbedPanels.KEY_DOWN=40;DSD.Widget.TabbedPanels.KEY_LEFT=37;DSD.Widget.TabbedPanels.KEY_RIGHT=39;DSD.Widget.TabbedPanels.prototype.onTabKeyDown=function(e,tab){var key=e.keyCode;if(!this.hasFocus||(key!=this.previousPanelKeyCode&&key!=this.nextPanelKeyCode)){return true;}var tabs=this.getTabs();for(var i=0;i<tabs.length;i++){if(tabs[i]==tab){var el=false;if(key==this.previousPanelKeyCode&&i>0){el=tabs[i-1];}else{if(key==this.nextPanelKeyCode&&i<tabs.length-1){el=tabs[i+1];}}if(el){this.showPanel(el);el.focus();break;}}}return this.cancelEvent(e);};DSD.Widget.TabbedPanels.prototype.preorderTraversal=function(root,func){var stopTraversal=false;if(root){stopTraversal=func(root);if(root.hasChildNodes()){var child=root.firstChild;while(!stopTraversal&&child){stopTraversal=this.preorderTraversal(child,func);try{child=child.nextSibling;}catch(e){child=null;}}}}return stopTraversal;};DSD.Widget.TabbedPanels.prototype.addPanelEventListeners=function(tab,panel){var self=this;DSD.Widget.TabbedPanels.addEventListener(tab,"click",function(e){return self.onTabClick(e,tab);},false);DSD.Widget.TabbedPanels.addEventListener(tab,"mouseover",function(e){return self.onTabMouseOver(e,tab);},false);DSD.Widget.TabbedPanels.addEventListener(tab,"mouseout",function(e){return self.onTabMouseOut(e,tab);},false);if(this.enableKeyboardNavigation){var tabIndexEle=null;var tabAnchorEle=null;this.preorderTraversal(tab,function(node){if(node.nodeType==1){var tabIndexAttr=tab.attributes.getNamedItem("tabindex");if(tabIndexAttr){tabIndexEle=node;return true;}if(!tabAnchorEle&&node.nodeName.toLowerCase()=="a"){tabAnchorEle=node;}}return false;});if(tabIndexEle){this.focusElement=tabIndexEle;}else{if(tabAnchorEle){this.focusElement=tabAnchorEle;}}if(this.focusElement){DSD.Widget.TabbedPanels.addEventListener(this.focusElement,"focus",function(e){return self.onTabFocus(e,tab);},false);DSD.Widget.TabbedPanels.addEventListener(this.focusElement,"blur",function(e){return self.onTabBlur(e,tab);},false);DSD.Widget.TabbedPanels.addEventListener(this.focusElement,"keydown",function(e){return self.onTabKeyDown(e,tab);},false);}}};DSD.Widget.TabbedPanels.prototype.showPanel=function(elementOrIndex){var tpIndex=-1;if(typeof elementOrIndex=="number"){tpIndex=elementOrIndex;}else{tpIndex=this.getTabIndex(elementOrIndex);}if(!tpIndex<0||tpIndex>=this.getTabbedPanelCount()){return;}var tabs=this.getTabs();var panels=this.getContentPanels();var numTabbedPanels=Math.max(tabs.length,panels.length);for(var i=0;i<numTabbedPanels;i++){if(i!=tpIndex){if(tabs[i]){this.removeClassName(tabs[i],this.tabSelectedClass);}if(panels[i]){this.removeClassName(panels[i],this.panelVisibleClass);panels[i].style.display="none";}}}this.addClassName(tabs[tpIndex],this.tabSelectedClass);this.addClassName(panels[tpIndex],this.panelVisibleClass);panels[tpIndex].style.display="block";this.currentTabIndex=tpIndex;};DSD.Widget.TabbedPanels.prototype.attachBehaviors=function(element){var tabs=this.getTabs();var panels=this.getContentPanels();var panelCount=this.getTabbedPanelCount();for(var i=0;i<panelCount;i++){this.addPanelEventListeners(tabs[i],panels[i]);}this.showPanel(this.defaultTab);};(function($){$.fn.loopedSlider=function(options){var defaults={container:".container",slides:".slides",pagination:".pagination",containerClick:true,autoStart:0,restart:0,slidespeed:300,fadespeed:300,autoHeight:false};this.each(function(){var obj=$(this);var o=$.extend(defaults,options);var pagination=$(o.pagination+" li a",obj);var m=0;var t=1;var s=$(o.slides,obj).children().size();var w=$(o.slides,obj).children().outerWidth();var p=0;var u=false;var n=0;var interval=300;var restart=0;$(o.slides,obj).css({width:(s*w)});$(o.slides,obj).children().each(function(){$(this).css({position:"absolute",left:p,display:"block"});p=p+w;});$(pagination,obj).each(function(){n=n+1;$(this).attr("rel",n);$(pagination.eq(0),obj).parent().addClass("active");});$(o.slides,obj).children(":eq("+(s-1)+")").css({position:"absolute",left:-w});if(o.autoHeight){autoHeight(t);}$(".next",obj).click(function(){if(u===false){animate("next",true);if(o.autoStart){if(o.restart){autoStart();}else{clearInterval(sliderIntervalID);}}}return false;});$(".previous",obj).click(function(){if(u===false){animate("prev",true);if(o.restart){autoStart();}else{clearInterval(sliderIntervalID);}}return false;});if(o.containerClick){$(o.container,obj).click(function(){if(u===false){animate("next",true);if(o.restart){autoStart();}else{clearInterval(sliderIntervalID);}}return false;});}$(pagination,obj).click(function(){if($(this).parent().hasClass("active")){return false;}else{t=$(this).attr("rel");$(pagination,obj).parent().siblings().removeClass("active");$(this).parent().addClass("active");animate("fade",t);if(o.restart){autoStart();}else{clearInterval(sliderIntervalID);}}return false;});if(o.autoStart){sliderIntervalID=setInterval(function(){if(u===false){animate("next",true);}},o.autoStart);function autoStart(){if(o.restart){clearInterval(sliderIntervalID);clearInterval(interval);clearTimeout(restart);restart=setTimeout(function(){interval=setInterval(function(){animate("next",true);},o.autoStart);},o.restart);}else{sliderIntervalID=setInterval(function(){if(u===false){animate("next",true);}},o.autoStart);}}}function current(t){if(t===s+1){t=1;}if(t===0){t=s;}$(pagination,obj).parent().siblings().removeClass("active");$(pagination+'[rel="'+(t)+'"]',obj).parent().addClass("active");}function autoHeight(t){if(t===s+1){t=1;}if(t===0){t=s;}var getHeight=$(o.slides,obj).children(":eq("+(t-1)+")",obj).outerHeight();$(o.container,obj).animate({height:getHeight},o.autoHeight);}function animate(dir,clicked){u=true;switch(dir){case"next":t=t+1;m=(-(t*w-w));current(t);if(o.autoHeight){autoHeight(t);}$(o.slides,obj).animate({left:m},o.slidespeed,function(){if(t===s+1){t=1;$(o.slides,obj).css({left:0},function(){$(o.slides,obj).animate({left:m});});$(o.slides,obj).children(":eq(0)").css({left:0});$(o.slides,obj).children(":eq("+(s-1)+")").css({position:"absolute",left:-w});}if(t===s){$(o.slides,obj).children(":eq(0)").css({left:(s*w)});}if(t===s-1){$(o.slides,obj).children(":eq("+(s-1)+")").css({left:s*w-w});}u=false;});break;case"prev":t=t-1;m=(-(t*w-w));current(t);if(o.autoHeight){autoHeight(t);}$(o.slides,obj).animate({left:m},o.slidespeed,function(){if(t===0){t=s;$(o.slides,obj).children(":eq("+(s-1)+")").css({position:"absolute",left:(s*w-w)});$(o.slides,obj).css({left:-(s*w-w)});$(o.slides,obj).children(":eq(0)").css({left:(s*w)});}if(t===2){$(o.slides,obj).children(":eq(0)").css({position:"absolute",left:0});}if(t===1){$(o.slides,obj).children(":eq("+(s-1)+")").css({position:"absolute",left:-w});}u=false;});break;case"fade":t=[t]*1;m=(-(t*w-w));current(t);if(o.autoHeight){autoHeight(t);}$(o.slides,obj).children().fadeOut(o.fadespeed,function(){$(o.slides,obj).css({left:m});$(o.slides,obj).children(":eq("+(s-1)+")").css({left:s*w-w});$(o.slides,obj).children(":eq(0)").css({left:0});if(t===s){$(o.slides,obj).children(":eq(0)").css({left:(s*w)});}if(t===1){$(o.slides,obj).children(":eq("+(s-1)+")").css({position:"absolute",left:-w});}$(o.slides,obj).children().fadeIn(o.fadespeed);u=false;});break;default:break;}}});};})(jQuery);
