window.addEvent('domready', function() {
	
	var accordion = new Accordion('a.display', 'ul.stretcher', {
			duration: 450, 
			alwaysHide:false,
			display: false,
			show: menu_item
			}
			, $('mainnav'));
	
	//var main_menu = $$('li.main_menu');
	//main_menu[menu_item].addClass('current');
	
	if($('features')) {
		if(Cookie.get("cpm_movie") != "full") {
			full_movie();
		} else {
			small_movie();
		}
	} else if($('about_features')) {
		if(Cookie.get("about_movie") != "full") {
			full_movie();
		} else {
			small_movie();
		}
	} else {
		small_movie();
	}
	
	if($('cpm_logo')) {
		intereactive_flash("cpm_logo", "/main/flash/cpm_logo.swf", "logoflash", "245", "162", "7", "#202A33", '<img src="/main/img/common/cpm_logo.gif" alt="Chosen People Ministries" width="245" height="162" />');	
	}
	
	if($('about_logo')) {
		intereactive_flash("about_logo", "/main/flash/about_logo.swf", "logoflash", "245", "162", "7", "#202A33", '<img src="/main/img/common/about_logo.gif" alt="Chosen People Ministries" width="245" height="162" />');	
	}
	
	if($('features')) {
		intereactive_flash("feature1", "/main/flash/feature1.swf", "feature1_player", "330", "238", "7", "#202A33", '<img src="/main/img/common/featured1.jpg" alt="main image" width="330" height="238" /');	
		intereactive_flash("feature2", "/main/flash/feature2.swf", "feature2_player", "330", "238", "7", "#202A33", '<img src="/main/img/common/featured2.jpg" alt="main image" width="330" height="238" /');	
		intereactive_flash("feature3", "/main/flash/feature3.swf", "feature3_player", "330", "238", "7", "#202A33", '<img src="/main/img/common/featured3.jpg" alt="main image" width="330" height="238" /');	
		intereactive_flash("feature4", "/main/flash/feature4.swf", "feature4_player", "330", "238", "7", "#202A33", '<img src="/main/img/common/featured4.jpg" alt="main image" width="330" height="238" /');
	}
	
	if($('about_features')) {
		intereactive_flash("feature1", "/main/flash/feature1_a.swf", "feature1_player", "330", "238", "7", "#202A33", '<img src="/main/img/common/featured1.jpg" alt="main image" width="330" height="238" /');	
		intereactive_flash("feature2", "/main/flash/feature2_a.swf", "feature2_player", "330", "238", "7", "#202A33", '<img src="/main/img/common/featured2.jpg" alt="main image" width="330" height="238" /');	
		intereactive_flash("feature3", "/main/flash/feature3_a.swf", "feature3_player", "330", "238", "7", "#202A33", '<img src="/main/img/common/featured3.jpg" alt="main image" width="330" height="238" /');	
		intereactive_flash("feature4", "/main/flash/feature4_a.swf", "feature4_player", "330", "238", "7", "#202A33", '<img src="/main/img/common/featured4.jpg" alt="main image" width="330" height="238" /');
	}

});

function small_movie() {
	$('bannergraphic').removeClass('full_movie');
	$('bannergraphic').addClass('small_movie');
	if($('features')) {
		$('features').removeClass('features_fullmovie');
	}
	if($('about_features')) {
		$('about_features').removeClass('features_fullmovie');
	}
	
	if($('about_logo')) {
		if($('about_features')) {
			intereactive_flash("bannergraphic", "/main/flash/banner_about_home.swf", "banner_movie", "696", "157", "7", "#202A33", '<img src="/main/img/common/banner.jpg" alt="banner graphic" width="696" height="157" />');
		} else {
			intereactive_flash("bannergraphic", "/main/flash/banner_about.swf", "banner_movie", "696", "157", "7", "#202A33", '<img src="/main/img/common/banner.jpg" alt="banner graphic" width="696" height="157" />');
		}
	} else {
		if($('features')) {
			intereactive_flash("bannergraphic", "/main/flash/banner_home.swf", "banner_movie", "696", "157", "7", "#202A33", '<img src="/main/img/common/banner.jpg" alt="banner graphic" width="696" height="157" />');
		} else {
			intereactive_flash("bannergraphic", "/main/flash/banner.swf", "banner_movie", "696", "157", "7", "#202A33", '<img src="/main/img/common/banner.jpg" alt="banner graphic" width="696" height="157" />');	
		}
	}
}

function full_movie() {
	//if($('bannergraphic').hasClass('small_movie')
	$('bannergraphic').removeClass('small_movie');
	$('bannergraphic').addClass('full_movie');
	
	if($('features')) {
		$('features').addClass('features_fullmovie');
		Cookie.set("cpm_movie", "full", {duration: 365});
		intereactive_flash("bannergraphic", "/main/flash/video_header.swf", "banner_movie", "696", "400", "7", "#202A33", '<img src="/main/img/common/banner.jpg" alt="banner graphic" width="696" height="157" />');	
	}
	
	if($('about_features')) {
		$('about_features').addClass('features_fullmovie');
		Cookie.set("about_movie", "full", {duration: 365});
		intereactive_flash("bannergraphic", "/main/flash/video_about_header.swf", "banner_movie", "696", "400", "7", "#202A33", '<img src="/main/img/common/banner.jpg" alt="banner graphic" width="696" height="157" />');	
	}

}

//initial function
function menu_init(menu_show){	
	// Pick your classes for menu		
	var stretchers = document.getElementsByClassName('stretcher'); //div that stretches
	var toggles = document.getElementsByClassName('display'); //what to click on

	
	var myAccordion = new Accordion(
								toggles, stretchers, {
									duration: 300, 
									alwaysHide:true,
									display: false,
									show: menu_show
									}
								);
	
	var main_menu = document.getElementsByClassName('main_menu');
	main_menu[menu_show].addClass('current');
}

function menu_swap(nav_id){
	$('nav_' + nav_id).addClass('current');

	//add current class to menu element
	var current_nav = $$('li.current');
	var new_nav = $('nav_' + nav_id);
	
	current_nav.each(function(a, i){
		if(a != new_nav) {
			$(a).removeClass('current');
		}
	});
}

function intereactive_flash (flash_cont, flash_file, flash_id, flash_width, flash_height, flash_version, flash_bg, alt_image) {
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if (version['major'] > 0) {
		var so = new SWFObject(flash_file, flash_id, flash_width, flash_height, flash_version, flash_bg);
		//so.addParam("wmode", "transparent");
		if (!so.write(flash_cont)) {
			document.getElementById(flash_cont).innerHTML = "<div style = \"text-align:center;\"><strong>For security, please upgrade your Flash Player</strong><br /><a href=\"http://www.macromedia.com/go/getflashplayer\" target = \"_blank\">Flash Player Upgrade</a></div>";
		}
	} else {
		document.getElementById(flash_cont).innerHTML = alt_image;
	}
}