/* ----------------------------------------------------------
	title		  : AGK Framework
	created		  : 9/10/09
	last updated  : 2/26/09
---------------------------------------------------------- */
jQuery.noConflict();     
jQuery(document).ready(function($){


/* Image Rotator */
//show controls in admin
if ( $('#adminbar #toolbar').length ) {
	
	$('#feature-cta').css('overflow','visible');
	
	$('#feature #feature-rotator .regionBoundary .contentRegion .regionName').remove();
	$('#feature #feature-rotator .regionBoundary .contentRegion .actions').before('<div class="slide"></div>');
	$('#feature #feature-rotator .regionBoundary .contentRegion .actions').each(function(){
		$(this).prev('.slide').append($(this));
	});
	$('#feature #feature-rotator .regionBoundary .contentRegion .element').each(function(){
		$(this).prev('.slide').append($(this));
	});
	
	
	$('#feature-rotator .sortSpacer').replaceWith($('#feature-rotator .inlineContentAdder'));
	
	
	
	if ($('#feature-rotator').length) {
	
	
	$('#feature').append('<p id="feature-btns"><span id="feature-prev"><a href="#">&laquo; Previous</a></span> <span id="feature-next"><a href="#">Next &raquo;</a></span></p>');

	
	$('#feature #feature-rotator .regionBoundary .contentRegion .sortContainer').cycle({ 
    fx:     'fade', 
    speed:  'fast', 
    timeout: 0, 
    next:   '#feature-next', 
    prev:   '#feature-prev' 
	});
	
	}


	
} else {


	if ( $('#feature-rotator').length ) {
	
	$('#feature').append('<p id="feature-btns"><span id="feature-prev"><a href="#">&laquo; Previous</a></span> <span id="feature-next"><a href="#">Next &raquo;</a></span></p>');

	
		$('#feature-rotator').cycle({
		fx: 'fade',
		speed: 'slow',
		timeout: 4000,
		pause: 1,
		next:  '#feature-next', 
    	prev:  '#feature-prev' 
		});
	
	}

}







// tabber
	
	$('#tabber .regionName').remove();
/*
	$('#tabber .element').before('<div class="j-tab"></div>').each(function() {
		$(this).prev('.j-tab').append($(this));
		
	});
*/

        $('#tabber .element').addClass('j-tab');
	
	$('#tabber .container').each(function(){
		$(this).next('.j-tab').prepend($(this));
	});
	
	$('#tabber .actions').each(function(){
		$(this).next('.j-tab').prepend($(this));
	});
	
	
	
function buildTabNav(ind) {
	var tabIndex = 'tab-'+ ind;

	$(this).attr('id', tabIndex);
	var tabTitle = $('.container', this).remove().text();
	
	if (tabTitle.replace(/\s/g,'') == '') { tabTitle = 'tab ' + (ind + 1) }
	
	$('#tab-nav').append('<li><a href="#'+ tabIndex +'">' + tabTitle + '</a></li>');
}

	
	
	
var tabberContent = $('#tabber').html();
	
	
if (tabberContent.replace(/\s/g,'') == '') {} else {
			$('#tabber').prepend('<ul id="tab-nav"></ul>');
			$('.j-tab').each(buildTabNav);
			$("#tabber").tabs();
}
	

if ( $('#adminbar #toolbar').length ) {
	if (tabberContent.replace(/\s/g,'') == '') {} else {
	
	$('#tabber').css({
		'padding': '10px 0',
		'background': '#ffc'
		}).prepend('<h1>Tab Area</h1> <p>Any element you add to this section will get its own tab.</p>');
	
	}
}

	





});//end doc ready