jQuery(document).ready(function(){
	// initilize drop down navigation using superfish plugin
	$(".nav").superfish();
	
	//initialize login form toggle link
	$(".nav_login").click(function () {
		$("#form_login").toggle();
		$(this).toggleClass("active");
		return false;
	});
	
	//initialize_header image slider if present on page
	$('#header_images').cycle({ 
		fx:    'fade', 
		speed:  5000 
	});
	
	//load wymeditor on textarea in CMS
	if($('#submit_button')) {
		$(".richtext").wymeditor();
		$('#submit_button').click(function(){
			// the update command gets the 1st wymeditor on the page using (0)
			$.wymeditors(0).update();
			$('#form_admin').submit();
		});
	}
	
	// form helpers for vendor forum registration form
	formVendorRegistrationInit();
	
	// fix IE CSS hover flicker
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}

});

function formVendorRegistrationInit() {
	var community_member = $("#community_member");
	if (community_member) {
		$("#community_member").change(toggleCommunityMember).change();
	}
	var community_member_company = $("#community_member_company");
	if (community_member_company) {
		$("#community_member_company").change(updateCompany).change();
	}
}

function toggleCommunityMember() {
	if($("#community_member").val() == "I am a PLM Community Member") {
		$("#community_member_details").show();
		$("#payment_info").hide();
	} else {
		$("#community_member_details").hide();
		$("#payment_info").show();
	}
	updateCompany();
}

function updateCompany() {
	if($("#community_member").val() == "I am a PLM Community Member") {
		$("#company").val($("#community_member_company").val());
	} 
}