/* minified jquery.accordion.js required by rotate */(function($){$.ui=$.ui||{};$.fn.extend({accordion:function(options,data){var args=Array.prototype.slice.call(arguments,1);return this.each(function(){if(typeof options=="string"){var accordion=$.data(this,"ui-accordion");accordion[options].apply(accordion,args);}else if(!$(this).is(".ui-accordion"))
$.data(this,"ui-accordion",new $.ui.accordion(this,options));});},activate:function(index){return this.accordion("activate",index);}});$.ui.accordion=function(container,options){this.options=options=$.extend({},$.ui.accordion.defaults,options);this.element=container;$(container).addClass("ui-accordion");if(options.navigation){var current=$(container).find("a").filter(options.navigationFilter);if(current.length){if(current.filter(options.header).length){options.active=current;}else{options.active=current.parent().parent().prev();current.addClass("current");}}}
options.headers=$(container).find(options.header);options.active=findActive(options.headers,options.active);if(options.fillSpace){var maxHeight=$(container).parent().height();options.headers.each(function(){maxHeight-=$(this).outerHeight();});var maxPadding=0;options.headers.next().each(function(){maxPadding=Math.max(maxPadding,$(this).innerHeight()-$(this).height());}).height(maxHeight-maxPadding);}else if(options.autoheight){var maxHeight=0;options.headers.next().each(function(){maxHeight=Math.max(maxHeight,$(this).outerHeight());}).height(maxHeight);}
options.headers.not(options.active||"").next().hide();options.active.parent().andSelf().addClass(options.selectedClass);if(options.event)
$(container).bind((options.event)+".ui-accordion",clickHandler);};$.ui.accordion.prototype={activate:function(index){clickHandler.call(this.element,{target:findActive(this.options.headers,index)[0]});},enable:function(){this.options.disabled=false;},disable:function(){this.options.disabled=true;},destroy:function(){this.options.headers.next().css("display","");if(this.options.fillSpace||this.options.autoheight){this.options.headers.next().css("height","");}
$.removeData(this.element,"ui-accordion");$(this.element).removeClass("ui-accordion").unbind(".ui-accordion");}}
function scopeCallback(callback,scope){return function(){return callback.apply(scope,arguments);};}
function completed(cancel){if(!$.data(this,"ui-accordion"))
return;var instance=$.data(this,"ui-accordion");var options=instance.options;options.running=cancel?0:--options.running;if(options.running)
return;if(options.clearStyle){options.toShow.add(options.toHide).css({height:"",overflow:""});}
$(this).triggerHandler("change.ui-accordion",[options.data],options.change);}
function toggle(toShow,toHide,data,clickedActive,down){var options=$.data(this,"ui-accordion").options;options.toShow=toShow;options.toHide=toHide;options.data=data;var complete=scopeCallback(completed,this);options.running=toHide.size()==0?toShow.size():toHide.size();if(options.animated){if(!options.alwaysOpen&&clickedActive){$.ui.accordion.animations[options.animated]({toShow:jQuery([]),toHide:toHide,complete:complete,down:down,autoheight:options.autoheight});}else{$.ui.accordion.animations[options.animated]({toShow:toShow,toHide:toHide,complete:complete,down:down,autoheight:options.autoheight});}}else{if(!options.alwaysOpen&&clickedActive){toShow.toggle();}else{toHide.hide();toShow.show();}
complete(true);}}
function clickHandler(event){var options=$.data(this,"ui-accordion").options;if(options.disabled)
return false;if(!event.target&&!options.alwaysOpen){options.active.parent().andSelf().toggleClass(options.selectedClass);var toHide=options.active.next(),data={instance:this,options:options,newHeader:jQuery([]),oldHeader:options.active,newContent:jQuery([]),oldContent:toHide},toShow=options.active=$([]);toggle.call(this,toShow,toHide,data);return false;}
var clicked=$(event.target);if(clicked.parents(options.header).length)
while(!clicked.is(options.header))
clicked=clicked.parent();var clickedActive=clicked[0]==options.active[0];if(options.running||(options.alwaysOpen&&clickedActive))
return false;if(!clicked.is(options.header))
return;options.active.parent().andSelf().toggleClass(options.selectedClass);if(!clickedActive){clicked.parent().andSelf().addClass(options.selectedClass);}
var toShow=clicked.next(),toHide=options.active.next(),data={instance:this,options:options,newHeader:clicked,oldHeader:options.active,newContent:toShow,oldContent:toHide},down=options.headers.index(options.active[0])>options.headers.index(clicked[0]);options.active=clickedActive?$([]):clicked;toggle.call(this,toShow,toHide,data,clickedActive,down);return false;};function findActive(headers,selector){return selector!=undefined?typeof selector=="number"?headers.filter(":eq("+selector+")"):headers.not(headers.not(selector)):selector===false?$([]):headers.filter(":eq(0)");}
$.extend($.ui.accordion,{defaults:{selectedClass:"selected",alwaysOpen:true,animated:'slide',event:"click",header:"a",autoheight:true,running:0,navigationFilter:function(){return this.href.toLowerCase()==location.href.toLowerCase();}},animations:{slide:function(options,additions){options=$.extend({easing:"swing",duration:300},options,additions);if(!options.toHide.size()){options.toShow.animate({height:"show"},options);return;}
var hideHeight=options.toHide.height(),showHeight=options.toShow.height(),difference=showHeight/hideHeight;options.toShow.css({height:0,overflow:'hidden'}).show();options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate({height:"hide"},{step:function(now){var current=(hideHeight-now)*difference;if($.browser.msie||$.browser.opera){current=Math.ceil(current);}
options.toShow.height(current);},duration:options.duration,easing:options.easing,complete:function(){if(!options.autoheight){options.toShow.css("height","auto");}
options.complete();}});},bounceslide:function(options){this.slide(options,{easing:options.down?"bounceout":"swing",duration:options.down?1000:200});},easeslide:function(options){this.slide(options,{easing:"easeinout",duration:700})}}});})(jQuery);

/* minified jquery.dimensions.js required by rotate */
(function($){$.dimensions={version:'@VERSION'};$.each(['Height','Width'],function(i,name){$.fn['inner'+name]=function(){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';return num(this,name.toLowerCase())+num(this,'padding'+torl)+num(this,'padding'+borr);};$.fn['outer'+name]=function(options){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';options=$.extend({margin:false},options||{});return num(this,name.toLowerCase())
+num(this,'border'+torl+'Width')+num(this,'border'+borr+'Width')
+num(this,'padding'+torl)+num(this,'padding'+borr)
+(options.margin?(num(this,'margin'+torl)+num(this,'margin'+borr)):0);};});$.each(['Left','Top'],function(i,name){$.fn['scroll'+name]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(name=='Left'?val:$(window)['scrollLeft'](),name=='Top'?val:$(window)['scrollTop']()):this['scroll'+name]=val;}):this[0]==window||this[0]==document?self[(name=='Left'?'pageXOffset':'pageYOffset')]||$.boxModel&&document.documentElement['scroll'+name]||document.body['scroll'+name]:this[0]['scroll'+name];};});$.fn.extend({position:function(){var left=0,top=0,elem=this[0],offset,parentOffset,offsetParent,results;if(elem){offsetParent=this.offsetParent();offset=this.offset();parentOffset=offsetParent.offset();offset.top-=num(elem,'marginTop');offset.left-=num(elem,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}
return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&$.css(offsetParent,'position')=='static'))
offsetParent=offsetParent.offsetParent;return $(offsetParent);}});function num(el,prop){return parseInt($.css(el.jquery?el[0]:el,prop))||0;};})(jQuery);

JPGMAG.tabmod={
	paneswitch:function(){
		$j(this).parents('.tabmod').find('h3,div.tabContent').removeClass('tabOn tabHover').end().end().addClass('tabOn').parents('.tabContent').addClass('tabOn');
		return false;
	},
	hover:function(){$j(this).not('.tabOn').addClass('tabHover');},
	out:function(){$j(this).not('.tabOn').removeClass('tabHover');},
	fromContacts:function(){
		var type=($j(this).parents('.tabContent').attr('id').indexOf('Photos')>-1)?'photos':'stories';
		$j.ajax({type:'get',url:'/actions/home_from_contacts.php',data:{content:type},success:function(d){
					var destination=(type!='photos')?'#tabStoriesFromContacts':'#tabPhotosFromContacts';
					destination+=' .tabpane';
				if(d!='0'){
					$j(destination).html(d);
					$j(destination+' .thumb').mouseover(JPGMAG.rollover.thumbs);
				}else{
					$j(destination).html('<p class="empty">Sorry, something went wrong. Did you log out?</p>');
				}
			},error:function(){
				var destination=(type!='photos')?'#tabStoriesFromContacts':'#tabPhotosFromContacts';
				destination+=' .tabpane';
				$j(destination).html('<p class="empty">Sorry, we were unable to retrieve '+type+' from your contacts. <a href="/" class="tryagain">Try again?</a></p>');
				$j(destination+' .tryagain').click(JPGMAG.tabmod.fromContacts);
			}
		});
		return false;
	},
	moreLinkSwitch:function(){
		var type=($j(this).parents('.tabContent').attr('id').indexOf('Photos')>-1)?'photos':'stories',
			i=$j(this).parents('.tabmod').find('h3').index($j(this)),
			copy=['',' from contacts'],
			ends=[];
		ends['photos']=['/submitted','/contacts'];
		ends['stories']=['','/contacts'];
		$j(this).parents('.tabmod').find('.tabMore a').attr('href','/'+type+ends[type][i]).html('More '+type+copy[i]+'...');
	}
}
JPGMAG.rollover={
	thumbs:function(){
		$j(this).parent('.tabPhotos').children('.thumb').removeClass('on');
		var i=$j(this).addClass('on').parent('.tabPhotos').children('.thumb').index(this);
	},
	otdHover:function(){$j(this).not('.on').addClass('hover');},
	otdOut:function(){$j(this).not('.on').removeClass('hover');},
	otdPaneswitch:function(){$j(this).not('.on').removeClass('hover');}
}

$j(function(){
	$j('.tabmod').not('#homeWorks').each(function(){$j(this).css('height',$j(this).height());});
	$j('.tabmod h3').click(JPGMAG.tabmod.paneswitch).mouseover(JPGMAG.tabmod.hover).mouseout(JPGMAG.tabmod.out);
	$j('.tabsFeatured h3').click(JPGMAG.tabmod.moreLinkSwitch);
	$j('.thumb').mouseover(JPGMAG.rollover.thumbs);
	$j('#tabPhotosFromContacts h3,#tabStoriesFromContacts h3').one('click',JPGMAG.tabmod.fromContacts);

	$j('#ofTheWeek h3').click(JPGMAG.rollover.otdPaneswitch).mouseover(JPGMAG.rollover.otdHover).mouseout(JPGMAG.rollover.otdOut);
	$j('#ofTheWeek .accordionContent div').each(function(){$j(this).css('padding-top',(($j('.accordionContent:first').height()-$j(this).height())/2)+'px')});
	$j('#ofTheWeek').accordion({active:'.paneOpen',autoheight:true,event:'click',header:'h3',selectedClass:'on'}).accordion('activate',0);
	$j('.accordion').each(function(){$j(this).css('height',$j(this).height()+'px');});
});


/* theme browser */
JPGMAG.rotate = {
    theme_data: {},             //gets loaded from external call
    first_loop: true,           //first time thru the rotation... flag for setting random theme
    img_queue: [],
    init_delay: 1000,           //1000 -- wait this long before firing up the theme browser

    timer: null,                //the timer for showing the *next* item
    delay: 8000,                //7000 -- show photo for this long
    duration: 2000,             //1000 -- how long it takes the image to fade in/out

    control_timer: null,        //so you can clearTimeout()
    control_delay: 1000,        //1000 -- how long to wait before starting the timer after the user mouses out of the img

    cat_timer: null,            //so you can clearTimeout()
    cat_duration: 0,            //0 -- how long it takes for the cat to slide open/closed

    settimer: function(){
        clearTimeout(JPGMAG.rotate.timer);
        JPGMAG.rotate.timer = setTimeout(function(){JPGMAG.rotate.update();}, JPGMAG.rotate.delay);
    },
    show: function(key){
        /**
         * SHOW THE ITEM
         */
        
        if(key === 'cat' && JPGMAG.rotate.first_loop === false){ JPGMAG.rotate.current.theme = 0; }
        if(key === 'theme'){JPGMAG.rotate.current.img = 0; }
        
        //shortcuts
        var c = JPGMAG.rotate.current.cat;
        var t = JPGMAG.rotate.current.theme;
        var i = JPGMAG.rotate.current.img;
        
        var this_theme = JPGMAG.rotate.theme_data[c].themes[t];
        var this_meta = this_theme.meta;
        var this_imgs = this_theme.imgs;
        var this_stats = this_theme.stats;
        var statlen  = this_stats.length;
        var statstr = '';

        var out;
        var n = JPGMAG.rotate.current[key] + 1;

        //show the selected item
        switch(key){
            case 'cat':
                //--unhilite the old cat, hilite the new cat
                $j("#rotate-nav").accordion('activate', JPGMAG.rotate.current.cat);

                //show the stuff
                JPGMAG.rotate.show('theme');
            break;

            case 'theme':
                if(JPGMAG.rotate.first_loop === true){JPGMAG.rotate.first_loop = false;};
                //set up the new theme info
                out = {
                    id: this_meta.theme_id,
                    h6: JPGMAG.rotate.theme_data[c].cat_name,
                    h2: this_meta.name,
                    h5: (this_meta.short_description !== '') ? this_meta.short_description : '&nbsp;'
                };
                
                //set the title and header info
                $j('#rotate-theme h5').html(out.h5);
                $j('#rotate-theme h2').html('<a href="/themes/'+ out.id +'">' + out.h2 + '</a>');
                $j('#rotate-theme h6').html(out.h6);
                
                JPGMAG.rotate.counts.stats = statlen;
                //create the stats
                for(var s = 0; s < statlen; s++){
                    statstr += '<li>' + this_stats[s] + '</li>';
                }
                
                //remove the old stats
                $j('#rotate-stats').find('li').remove();
                
                //inject the new stats
                $j('#rotate-stats').append($j(statstr));
                
                //reset the stats to start at the 0th item
                JPGMAG.rotate.current.stats = 0;
                
                //set _key_ marker (the <<)
                $j('#rotate-nav li.on').removeClass('on');
                $j('a#c_'+ JPGMAG.rotate.current.cat +'__t_' + JPGMAG.rotate.current.theme).parent('li').addClass('on');
                
                
                //set up the imgmarkers
                JPGMAG.rotate.markers(this_imgs, $j('#rotate-imgmarkers'), 'img');
                
                //show the theme sponsor
                JPGMAG.rotate.show('theme_sponsor');
                
                //set the current.img to 0 -- start from the first item in the set for the theme
                JPGMAG.rotate.current.img = 0;
                JPGMAG.rotate.show('img');
                
                JPGMAG.rotate.show('blog');
                JPGMAG.rotate.next('blog');
                
                JPGMAG.rotate.show('site'); 
                JPGMAG.rotate.next('site');     
            break;

            case 'theme_sponsor':
                //opening a new theme...

                //clear out the sponsor box
                $j('#rotate-sponsor a').css('position','absolute').fadeOut('fast',function(){ $j(this).remove(); });

                //create the sponsor badge
                if(this_meta.sponsored > 0 && this_meta.sponsor_url_tb !== '' && this_meta.sponsor_image_tb !== ''){
                    $j('#rotate-sponsor').append('<a href="'+ this_meta.sponsor_url_tb +'" target="_sponsor"><img src="'+ this_meta.sponsor_image_tb +'" width="100" height="50" border="0" style="display:none;" /></a>');
                    $j('#rotate-sponsor img').fadeIn('fast');
                }
            break;
            
            case 'img':
                out = {
                    id:   this_imgs[i].id,
                    img:  this_imgs[i].url,
                    span: this_imgs[i].title,
                    cite: this_imgs[i].photographer
                };

                //remove the loading bar so you don't see it in the crossfade...
                $j('#rotate-feature').removeClass('loading');

                //fade the old img out
                $j('#rotate-img div:last').fadeOut(JPGMAG.rotate.duration);

                //create the new img
                $j('#rotate-img').append('<div onclick="document.location.href=\'/photos/'+ out.id +'\';" style="display:none; background:transparent url('+ out.img +') center center no-repeat;cursor:pointer; _cursor:hand;"><img src="' + out.img + '" /></div>');

                //fade in the new image, remove the old one
                $j('#rotate-img div:last').fadeIn(JPGMAG.rotate.duration, function(){
                    $j('#rotate-img div:not(:last)').remove();

                    //put the loading bar in... so if the image is not loaded, you'll see the loading bar
                    $j('#rotate-feature').addClass('loading');
                });

                //change the imgmarker
                $j('#rotate-imgmarkers a.on').removeClass('on');

                $j('#rotate-imgmarkers a:nth-child('+ n +')').addClass('on');
                $j('#rotate-caption em').text(out.span);
                $j('#rotate-caption cite').text('by ' + out.cite);

                JPGMAG.rotate.show('stats');
                if(JPGMAG.rotate.counts.stats > 1){
                    JPGMAG.rotate.next('stats');
                }
            break;

            default:
                //--(fade) out with the old
                $j('#rotate-' + key + ' li.on').css('display','none').removeClass('on');

                //--(fade) in with the new
                $j('#rotate-' + key + ' li:nth-child('+ (JPGMAG.rotate.current[key] + 1) +')').css('display','block').addClass('on');
            break;
        }
    },
    set_and_show: function(key, item){
        clearTimeout(JPGMAG.rotate.timer);
        JPGMAG.rotate.current[key] = item;
        JPGMAG.rotate.show(key);
    },
    next: function(key){
        /**
         * GET THE *NEXT* ITEM BASED ON THE KEY
         */
        //figure out which cat/theme the current image is in
        var c = JPGMAG.rotate.current.cat;
        var t = JPGMAG.rotate.current.theme;

        var counter = 0;
        var parent = false;

        switch(key){
        case 'img':
            //figure out where you are in the rotation
            counter = JPGMAG.rotate.counts['c_'+c+'__t_'+t] -1;
            parent = 'theme';
            break;

        case 'theme':
            //figure out where you are in the rotation
            counter = JPGMAG.rotate.counts['c_' + c] -1;
            parent = 'cat';
            break;

        case 'cat':
            //figure out where you are in the rotation
            counter = JPGMAG.rotate.counts.cats -1;
            break;

        default:
            //generic handler
            counter = JPGMAG.rotate.counts[key] -1;
            break;
        }

        if(JPGMAG.rotate.current[key] === counter){
            JPGMAG.rotate.current[key] = 0;

            if(parent !== false){
                JPGMAG.rotate.next(parent);
                JPGMAG.rotate.show(parent);
            }

        } else {
            JPGMAG.rotate.current[key]++;
        }
    },
    markers: function(items, box, prefix){
        /**
         * SET UP THE BOXES THAT INDICATE CURRENT ITEM IN SET
         */
        var m = [];
        var ilen = items.length;
        var item = 1;
        for(var i = 0; i < ilen; i++){

            m[i] = '<a href="/photos/' + items[i].id + '" onclick="JPGMAG.rotate.set_and_show(\'img\', '+ i + '); return false;">' + item + '</a>';
            item++;
        }

        box.html(m.join(' '));
    },
    update: function(){
        /**
         * get the next item, then show it
         * - you don't need to get the next cat or theme, as this will be handled automatically in the show(img) call
         * - this is a wrapper to update all the stuff you need to update during an update :) (right now, that's just an image
         *   but say you wanted to update some other module... you could: by adding it here)
         */
        JPGMAG.rotate.next('img');
        JPGMAG.rotate.show('img');

        //reset the timer
        JPGMAG.rotate.settimer();
    },
    set_events: function(){
        /**
         * INITIALIZE THE MOUSE HANDLERS FOR VARIOUS COMPONENTS
         */
        //IMAGE PAUSE/RESUME
        //-- image over
        $j('#rotate-feature').bind('mouseenter',
            function () {
                clearTimeout(JPGMAG.rotate.control_timer);
                clearTimeout(JPGMAG.rotate.timer);
            }
        );

        //-- image out
        $j('#rotate-feature').bind('mouseleave',
            function () {
                JPGMAG.rotate.control_timer = setTimeout(JPGMAG.rotate.update, JPGMAG.rotate.delay);
            }
        );

        //CATEGORY EVENTS
        //--category hover (mouseover)
        $j('#rotate-nav li[id^="cat_"] h4').bind('mouseover', function(){
            //if the themelist is still animated OR if *this* is the current category, bail
            if($j(this).parent().hasClass('selected')){ return; }

            //set the current_cat_handle so you can get a hook on it in the setTimeout...
            JPGMAG.rotate.current_cat_handle = $j(this);

            //hilite *this* cat
            $j(this).addClass('cathilite');
        });

        //--category hover (mouseout)
        $j('#rotate-nav li[id^="cat_"] h4').bind('mouseout', function(){
            $j(this).removeClass('cathilite');
            clearTimeout(JPGMAG.rotate.cat_timer);
        });

        //--category click (use instead of the accordion default)
        $j('#rotate-nav li[id^="cat_"] h4').bind('click', function(){
            //get a handle on the item the user clicked
            var cat_id = JPGMAG.rotate.current_cat_handle.parent().attr('id').split('_')[1];

            //*this* is not the current category -- you didn't bail...
            //kill the main timer
            clearTimeout(JPGMAG.rotate.timer);

            //set the current values...
            JPGMAG.rotate.current.cat   = parseInt(cat_id, 0);
            
            //show the stuff
            JPGMAG.rotate.show('cat');

            //restart the timer
            JPGMAG.rotate.settimer();
        });

        //THEME EVENTS
        //--theme click
        $j('#rotate-nav li[id^="cat"] ul li a').bind('click', function(e){
            e.preventDefault();
            e.stopPropagation();

            if($j(this).parent('li').hasClass('c')){ return; } //bail

            var theme_id = $j(this).attr('id').split('__')[1].split('_')[1];

            clearTimeout(JPGMAG.rotate.timer);
            JPGMAG.rotate.current.theme = parseInt(theme_id,0);
            JPGMAG.rotate.show('theme');
            
            JPGMAG.rotate.settimer();
        });
    },
    check_imgs_loaded: function(){

        var iqlen = JPGMAG.rotate.img_queue.length;
        for(var i = 0; i < iqlen; i++){
            if(!JPGMAG.rotate.img_queue[i].height){
                setTimeout(function(){JPGMAG.rotate.check_imgs_loaded();}, 2000);
                return;
            }
        }
        JPGMAG.rotate.settimer();
        return;
    },
    get_theme_images: function(imgs){
        /**
         * PRELOAD THE IMAGES FOR THE THEME
         */
        var ilen = imgs.length;

        for(var img = 0; img<ilen; img++){

            var i = new Image();
            i.id = 'img_' + imgs[img].id;
            i.src = imgs[img].url;

            if(!i.height){
                JPGMAG.rotate.img_queue.push(i);
            }
        }
    },
    init_cat: function(c){
        /**
         * BUILD THE CATEGORY NAVIGATION
         */

        //--get the cat data
        var o = JPGMAG.rotate.theme_data[c];

        //--build the header
        var h4 = '<h4>' + o.cat + '</h4>';

        //--loop over the cat/themes and build the theme headers
        var tlen = o.themes.length;

        var ul = '<div style="display:none;"><ul>';
        for(var i = 0; i < tlen; i++){
            var sponsor = '';

            if(o.themes[i].meta.sponsored > 0){
                sponsor = ' <span>Sponsored by '+ o.themes[i].meta.sponsor_name +'</span>';
            }
            ul += '<li><a id="c_'+ c +'__t_'+i+'" href="/themes/'+ o.themes[i].meta.theme_id +'">'+ o.themes[i].meta.name +'</a>'+ sponsor +'</li>';
        }
        ul += '</ul></div>';

        //--append the cat nav to the document
        $j('<li id="cat_' + c + '">' + h4 + ul + '</li>').appendTo('#rotate-nav');
    },
    init: function(){
        /**
         * SET UP THE THEME BROWSER AND START THE SHOW
         */
        //INITIALIZE CURRENT
        JPGMAG.rotate.current = {
            blog:0,
            site:0,
            //cat:0,
            //theme:0,
            img:0,
            stats:0
        };
        
        //get random cat
        JPGMAG.rotate.current.cat = Math.floor(Math.random()*JPGMAG.rotate.theme_data.length)
        //get random theme
        JPGMAG.rotate.current.theme = Math.floor(Math.random()*JPGMAG.rotate.theme_data[JPGMAG.rotate.current.cat].themes.length);
        
        
        //INITIALIZE COUNTS
        JPGMAG.rotate.counts = {
            blog: $j('#rotate-blog li').length,
            site: $j('#rotate-site li').length
        };

        //INITIALIZE COUNTS FOR CATS, THEMES/CAT, AND IMGS/THEME
        var numcats;

        //--cat count
        numcats = JPGMAG.rotate.counts.cats = JPGMAG.rotate.theme_data.length;
        for(var c = 0; c < numcats; c++){
            JPGMAG.rotate.init_cat(c);

            //--theme/cat count
            var tic = JPGMAG.rotate.theme_data[c].themes.length;
            JPGMAG.rotate.counts['c_' + c] = tic;

            for(var t = 0; t < tic; t++){
                var imgs = JPGMAG.rotate.theme_data[c].themes[t].imgs;
                var iit = imgs.length;

                //--imgs/theme count
                JPGMAG.rotate.counts['c_' + c + '__t_' + t] = iit;

                //preload the images
                JPGMAG.rotate.get_theme_images(imgs);
            }
        }

        // INITIALIZE THE UI
        //--show the stuff (the timeouts are to "time" the animations...
        setTimeout(function(){
            //--setup the accordion
            var accordion_options = {
                active: '.selected',
                selectedClass: 'selected',
                header: 'li h4',
                event:false //use my own handler
                //animated: 'rotate_slide'
            };
            //--if the cat_duration is different than the default, set up the custom handler
            //  and add it to the options
            if(JPGMAG.rotate.cat_duration > 0){
                $j.ui.accordion.animations.rotate_slide = function(options) {
                    this.slide(options, {
                        duration: JPGMAG.rotate.cat_duration
                    });
                };
                accordion_options.animated = 'rotate_slide';
            }
            //--initialize the accordion
            $j('#rotate-nav').accordion(accordion_options);

            //--show stuff
            JPGMAG.rotate.show('cat');
            
            //--set up mouse events
            JPGMAG.rotate.set_events();

            //--set the auto-updater
            JPGMAG.rotate.check_imgs_loaded();
        }, JPGMAG.rotate.init_delay);
    }
};