/*
main.js
 */

$(function() {

	// set up the main contents div
	$("#main-content").hide();
	
	// set up the anchor tags




	// browser specific
	var browserVer = $.browser.version.substring(0,$.browser.version.indexOf('.')); 

	if( browserVer < 8 && $.browser.msie){
		 $("#views-options a:contains('Dialog')").css( { display:'none'} ) ;
	}

	// get text out of the cache and build the templates
	$.cache = {};
	$.cache.content = {
		headers : [],
		bodies : []
	};
	$.selectedView = 'accordion';

	
	// get the data content from the #accordion dif
	var domAll = $('#main-content');

	// populate the cache
	$(domAll).find('h3').each(function(i) {
		$.cache.content.headers.push($(this).text());
	});
	$(domAll).find('div.outer').each(function(i) {
		//$.log( $(this).text().length );
		if( $(this).text().length > 1300) {
			//$.log( 'l >1000' );
			$.cache.content.bodies.push('<div style="overflow:auto;height:250px">'+$(this).html()+'</div>');
		}
		else {
			$.cache.content.bodies.push($(this).html());
		}		
	});

//	$.log($.cache.content.bodies);

	// HACK Safari want to make this length 5!!!!
	$.cache.content.bodies = $.cache.content.bodies.slice(0,4);
//	$.log($.cache.content.bodies);

	//	$("#accordion-content").setAccordion();
	$("#accordion-content").html($("#main-content").html());	
	$("#accordion-content").find('span').wrap('<a></a>' );
	$("#accordion-content").find('div:eq(1) p').remove();
	$("#accordion-content").find('div:eq(1) h4').remove();
	$("#accordion-content").find('div:eq(1) div.over-flow-div').html($.cache.content.bodies[1]);
	$("#accordion-content").accordion( { clearStyle : false,  autoHeight: false });
	
	// set up the menus
	$('#switcher').themeswitcher();

	$('.fg-button').hover(function() {
		$(this).removeClass('ui-state-default').addClass('ui-state-focus');
	}, function() {
		$(this).removeClass('ui-state-focus').addClass('ui-state-default');
	});

	$('#effects').menu( {
		content : $('#effects-options').html(), // grab content from this page
		showSpeed : 400,
		linkHover : 'ui-state-hover'
	});

	$('#views').menu( {
		content : $('#views-options').html(), // grab content from this page
		showSpeed : 400,
		linkHover : 'ui-state-hover'
	});


	

	$('#tabs-content').setTabs().tabs();

	$('#dialogs-content').setDialogs();
});