/* http://keith-wood.name/themes.html
   Applying CSS themes for jQuery v1.3.0.
   Written by Keith Wood (kbwood{at}iinet.com.au) September 2008.
   Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license. 
   Please attribute the author if you use it. */
(function($){function Themes(){this.currentTheme='';this._linkID='th'+new Date().getTime();this._defaults={themes:[],themeBase:'',themeFile:'jquery-ui.css',defaultTheme:'',icons:'img/themes.gif',iconSize:[23,20],previews:'img/themes-preview.gif',previewSize:[90,80],showPreview:true,compact:true,cookieExpiry:0,cookiePath:'/',cookieDomain:'',onSelect:null};this._themes={'blacktie':{display:'Black Tie',icon:0,preview:0,url:'black-tie/'},'blitzer':{display:'Blitzer',icon:1,preview:1,url:'blitzer/'},'cupertino':{display:'Cupertino',icon:2,preview:2,url:'cupertino/'},'darkhive':{display:'Dark Hive',icon:17,preview:17,url:'dark-hive/'},'dotluv':{display:'Dot Luv',icon:3,preview:3,url:'dot-luv/'},'eggplant':{display:'Eggplant',icon:18,preview:18,url:'eggplant/'},'excitebike':{display:'Excite Bike',icon:4,preview:4,url:'excite-bike/'},'flick':{display:'Flick',icon:19,preview:19,url:'flick/'},'hotsneaks':{display:'Hot Sneaks',icon:5,preview:5,url:'hot-sneaks/'},'humanity':{display:'Humanity',icon:6,preview:6,url:'humanity/'},'lefrog':{display:'Le Frog',icon:20,preview:20,url:'le-frog/'},'mintchoc':{display:'Mint Choc',icon:7,preview:7,url:'mint-choc/'},'overcast':{display:'Overcast',icon:21,preview:21,url:'overcast/'},'peppergrinder':{display:'Pepper Grinder',icon:22,preview:22,url:'pepper-grinder/'},'redmond':{display:'Redmond',icon:8,preview:8,url:'redmond/'},'smoothness':{display:'Smoothness',icon:9,preview:9,url:'smoothness/'},'southstreet':{display:'South Street',icon:10,preview:10,url:'south-street/'},'start':{display:'Start',icon:11,preview:11,url:'start/'},'sunny':{display:'Sunny',icon:23,preview:23,url:'sunny/'},'swankypurse':{display:'Swanky Purse',icon:12,preview:12,url:'swanky-purse/'},'trontastic':{display:'Trontastic',icon:13,preview:13,url:'trontastic/'},'uidarkness':{display:'UI Darkess',icon:14,preview:14,url:'ui-darkness/'},'uilightness':{display:'UI Lightness',icon:15,preview:15,url:'ui-lightness/'},'vader':{display:'Vader',icon:16,preview:16,url:'vader/'}}}$.extend(Themes.prototype,{markerClassName:'hasThemes',propertyName:'themes',cookieName:'themeID',_currentClass:'themes_current',_compactClass:'themes_compact',_listClass:'themes_list',_previewClass:'themes_preview',setDefaults:function(a){$.extend(this._defaults,a||{});return this},_init:function(){var a=new RegExp(this.cookieName+'=([^;]*)');var b=a.exec(document.cookie);var c=(b?b[1]:'')||this._defaults.defaultTheme;var d='';var e=false;for(var f in this._themes){d=d||f;e=(c==f);if(e){break}}c=(e?c:d);this._setTheme(c,this._themes[c].display,this._defaults.themeBase+this._themes[c].url+this._defaults.themeFile,true)},addTheme:function(a,b,c,d,e){this._themes[a]={display:b,icon:c,preview:d,url:e};return this},getThemes:function(){return this._themes},_attachPlugin:function(a,b){a=$(a);if(a.hasClass(this.markerClassName)){return}var c={options:$.extend({},this._defaults)};a.addClass(this.markerClassName).data(this.propertyName,c);this._optionPlugin(a,b)},_optionPlugin:function(a,b,c){a=$(a);var d=a.data(this.propertyName);if(!b||(typeof b=='string'&&c==null)){var e=b;b=(d||{}).options;return(b&&e?b[e]:b)}if(!a.hasClass(this.markerClassName)){return}b=b||{};if(typeof b=='string'){var e=b;b={};b[e]=c}$.extend(d.options,b);this._updateTheme(a,d)},_updateTheme:function(d,e){if(e.options.themes.length==0){$.each(this._themes,function(a){e.options.themes[e.options.themes.length]=a})}var f=function(a){return a.replace(/'/,'\\\'')};var g='<ul class="'+this._listClass+(e.options.compact?' '+this._compactClass:'')+'">';var h=this._themes;$.each(e.options.themes,function(a,b){var c=h[b];if(!c){return}g+='<li class="'+p.propertyName+'__'+b+(p.currentTheme==b?' '+p._currentClass:'')+'"><a data-theme="'+b+'">';if(c.icon!=null){g+='<span title="'+c.display+'"';if(typeof c.icon=='number'){g+=' style="background: transparent url('+e.options.icons+') no-repeat -'+(c.icon*e.options.iconSize[0])+'px 0px;">'}else{g+='><img src="'+c.icon+'" alt="'+c.display+'"/>'}g+='</span>'+(e.options.compact?'':'&#xa0;')}g+=(e.options.compact?'':c.display)+'</a></li>'});g+='</ul><div class="'+this._previewClass+'"><div '+'style="width: '+e.options.previewSize[0]+'px; height: '+e.options.previewSize[1]+'px; background: url('+e.options.previews+') no-repeat;"></div></div>';d.html(g).on('mouseenter','a',function(){if(e.options.showPreview){p._showPreview(this)}}).on('mouseleave','a',function(){p._hidePreview(this)}).on('click','a',function(){var a=$(this).data('theme');var b=p._themes[a];p._setTheme(a,b.display,e.options.themeBase+b.url+e.options.themeFile)})},_destroyPlugin:function(a){a=$(a);if(!a.hasClass(this.markerClassName)){return}a.removeClass(this.markerClassName).empty()},_setTheme:function(c,d,e,f){if($('#'+p._linkID).length==0){$('head').append('<link rel="stylesheet" type="text/css" id="'+p._linkID+'"/>')}$('#'+p._linkID).attr('href',e);p.currentTheme=c;$('.'+p.markerClassName+' li').removeClass(p._currentClass);$('.'+p.propertyName+'__'+c).addClass(p._currentClass);var g=$('.'+p.propertyName+'__'+c).closest('.'+p.markerClassName).data(p.propertyName);if(g&&$.isFunction(g.options.onSelect)){g.options.onSelect.apply(window,[c,d,e])}if(!f){var h=function(a){var b=new Date();b.setDate(b.getDate()+a);return b};var i=(g.options.cookieExpiry?(typeof g.options.cookieExpiry=='number'?h(g.options.cookieExpiry):g.options.cookieExpiry):null);document.cookie=p.cookieName+'='+c+(i?'; expires='+i.toUTCString():'')+(g.options.cookiePath?'; path='+g.options.cookiePath:'')+(g.options.cookieDomain?'; domain='+g.options.cookieDomain:'')}return false},_showPreview:function(b){var c=$(b).data('theme');var d=p._themes[c];if(d.preview==null){return}var e=$(b).closest('.'+p.markerClassName);var f=e.data(p.propertyName);var g=e.find('div.'+p._previewClass);var h='';if(typeof d.preview=='number'){g.find('div').show().css('background-position','-'+(d.preview*f.options.previewSize[0])+'px 0px')}else{g.find('div').hide();h+='<img src="'+d.preview+'" alt="'+d.display+'"/><br/>'}h+='<span>'+d.display+'</span>';var i=$(b).parent();var j=null;$(b).parents().each(function(){var a=$(this).css('position');if(a=='absolute'||a=='relative'){j=$(this)}return!j});var k=i.offset();var l=(j?j.offset():{left:0,top:0});var m=k.left-l.left+parseInt(i.css('padding-left'),10);var n=k.top-l.top+i.height()+parseInt(i.css('padding-top'),10)+1;g.children(':not(:first)').remove().end().append(h).css({left:m,top:n}).show()},_hidePreview:function(a){$(a).closest('.'+p.markerClassName).find('div.'+p._previewClass).hide()}});var o=[''];function isNotChained(a,b){if(a=='option'&&(b.length==0||(b.length==1&&typeof b[0]=='string'))){return true}return $.inArray(a,o)>-1}$.fn.themes=function(a){var b=Array.prototype.slice.call(arguments,1);if(isNotChained(a,b)){return p['_'+a+'Plugin'].apply(p,[this[0]].concat(b))}return this.each(function(){if(typeof a=='string'){if(!p['_'+a+'Plugin']){throw'Unknown command: '+a;}p['_'+a+'Plugin'].apply(p,[this].concat(b))}else{p._attachPlugin(this,a||{})}})};var p=$.themes=new Themes();$(function(){p._init()})})(jQuery);