//replace headings
function replaceHeading(){
	$("#copyCopy h2").each(function (){
		content = $(this).text().toLowerCase();
		//alert(content);	
		if ($(this).css('color') == 'rgb(255, 255, 255)') headingColorRep = "0xffffff";
		else headingColorRep = "0x603c20";
		$(this).css({ height: "32px"}).flashembed({
			//flashembed vars
			src: "/assets/flash/hRep.swf", version: [9, 0], wmode: "transparent", width: "100%", height: "100%", scale: "noscale", salign: "lt" }, {
			//vars to flash file
			headingText: encodeURIComponent(content), headingColor: headingColorRep, headingSize: 34, headingLetterSpacing: 0, headingOffsetX: 29, headingOffsetY: -7 });
	});
}

function mainMenu(){
	$('#mainMenu li ul').css({ 'display' : 'none' }); // Opera Fix
	
	$("#mainMenu li a span").css({ 'opacity': "0", 'display': "block" });
	
	$('#mainMenu li').hover(function(){
		$(this).find('a span').fadeTo(50, 1.0);
		},function(){
		$(this).find('a span').fadeTo(500, 0.0);
		});
	}

function tabulator(){
	if( $('#tabbyColL').length > 0 ) $("#tabbyControl").tabs("#tabbyColR > .tabbedContent", {effect: 'fade'}).history(); 
	}
	
function mapalize(){
    $('#plotMapImageMap area.fancy').click(function(){
        mapalizeGoTo = $(this).attr('href');
        $('#plotMapLegendList > li').fadeOut(200).css({ 'display' : 'none'});
        $('#plotMapImageList > li').fadeOut(200).css({ 'display' : 'none'});
        $('#plotMapLegendList').scrollTop(0);
        $('#plotMapImageList').scrollTop(0);
        $(mapalizeGoTo).fadeIn(300);
        $(mapalizeGoTo+"img").fadeIn(300);
        return false;
    });
}

function calendarize(){
    var calendarizeClickDidntHappenYet = true;
    
    $('td.cellPast a, td.cellNow a, td.cellFuture a').click(function(){
        calendarize = $(this).attr('href');
        //alert(clickDidntHappenYet);
        if($(calendarize+":visible").length != 1 || calendarizeClickDidntHappenYet){
            calendarizeClickDidntHappenYet = false;
            $('.calendarH3, .eventsSet').slideUp();
            $(calendarize+', #setForDay'+calendarize.replace("#day", "")).slideDown();
        }
    });
}

$(document).ready(function(){
    if( $('#slidyShow').length ) $('#slidyShow').cycle({ fx: 'fade', speed: 600, timeout: 3200});
    if( $('#bigMeanCalendarTable').length ) calendarize();
	replaceHeading();
	mainMenu();
	tabulator();
    if( $('#plotMapSling').length) mapalize();
    if( $('#gallerySlideSling').length) $("a.slideLinky").fancybox({
			'transitionIn'		: 'none'            ,
			'transitionOut'		: 'none'            ,
			'overlayOpacity'	: '0.5'            ,
			'titleShow' 		: 'false'           //,
			
		});	
	});