$(document).ready(function() {

// Sub Menus

	$('#nav a').mouseover(function(){
		$(this).siblings('ul').show();
	});
	
	$('#nav li ul').mouseover(function(){
		$(this).show();
	});
	
	$('#nav a').mouseout(function(){
		$(this).siblings('ul').hide();
	});
	
	$('#nav li ul').mouseout(function(){
		$(this).hide();
	});
	
// Homepage random background image 

totalImages=4;
var randomNum = Math.round(Math.random()*(totalImages-1))+1;
imgPath=('images/bkgd-home'+randomNum+'.jpg');
$('#schedule-today').css('background-image', ('url("'+imgPath+'")'));
	

// Inner h1 sIFR
	$('#content h1').flash(
        { 
            src: '/swf/headers.swf',
         	wmode: 'transparent', 
            flashvars: { 
                css: [
                    '* {color: #ffffff}'
                ].join(' ')
            }
        },
        { version: 7 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
    
// Member Updates sIFR
	$('.memberupdates h3').flash(
        { 
            src: '/swf/headers.swf',
         	wmode: 'transparent', 
            flashvars: { 
                css: [
                    '* {color: #355b1d}'
                ].join(' ')
            }
        },
        { version: 7 },
        function(htmlOptions) {
            htmlOptions.flashvars.txt = this.innerHTML;
            this.innerHTML = '<div>'+this.innerHTML+'</div>';
            var $alt = $(this.firstChild);
            htmlOptions.height = $alt.height();
            htmlOptions.width = $alt.width();
            $alt.addClass('alt');
            $(this)
                .addClass('flash-replaced')
                .prepend($.fn.flash.transform(htmlOptions));						
        }
    );
    
  
// Schedule functionality 
// Get which day of the week it is
	var today=new Date();
	var thisDay=today.getDay(); 
// Hide all schedules
	$('.schedule ul').hide();
// On page load, first two lines of each set reveals today's schedule by default
// third line inputs the today's schedule on the homepage
	if (thisDay == '0'){
		$('.schedule h2.sunday').addClass('selected');
		$('.schedule ul.sunday').show();
		$(".today").append('.sunday').load("/schedule/index.html ul.sunday");	
	} else if (thisDay == '1'){
		$('.schedule h2.monday').addClass('selected');
		$('.schedule ul.monday').show();
		$(".today").append('.monday').load("/schedule/index.html ul.monday");
	} else if (thisDay == '2'){
		$('.schedule h2.tuesday').addClass('selected');
		$('.schedule ul.tuesday').show();
		$(".today").append('.tuesday').load("/schedule/index.html ul.tuesday");
	} else if (thisDay == '3'){
		$('.schedule h2.wednesday').addClass('selected');
		$('.schedule ul.wednesday').show();
		$(".today").append('.wednesday').load("/schedule/index.html ul.wednesday");
	} else if (thisDay == '4'){
		$('.schedule h2.thursday').addClass('selected');
		$('.schedule ul.thursday').show();
		$(".today").append('.thursday').load("/schedule/index.html ul.thursday");
	} else if (thisDay == '5'){
		$('.schedule h2.friday').addClass('selected');
		$('.schedule ul.friday').show();
		$(".today").append('.friday').load("/schedule/index.html ul.friday");
	} else {
		$('.schedule h2.saturday').addClass('selected');
		$('.schedule ul.saturday').show();
		$(".today").append('.saturday').load("/schedule/index.html ul.saturday");
	}

// Show schedules for other days 
	$('.schedule h2').click(function(){
// Hide all visible schedules
		$('.schedule h2').removeClass('selected');
		$('.schedule ul').slideUp('fast');
// Set variable based on which H2 was selected
		var daySchedule = $(this).attr('class');
// Show UL based on class
		$(this).addClass('selected');
		$('.schedule ul.'+daySchedule).slideDown('fast');
	});

});   
