$(document).ready(function() {

/* Radio Toggle */

$(".RadioToggleHide").click(function() {
var imgRadioNotChecked = '../content/images/radio-notchecked.png';
var imgRadioChecked = '../content/images/radio-checked.png';
$(this).parents(".RadioToggleGroup").find(".RadioToggleHide, .RadioToggleShow, .RadioToggleSwitch").find("IMG").attr("src", imgRadioNotChecked);
$(this).find("IMG").attr("src", imgRadioChecked);
$(this).find("IMG").attr("src", imgRadioChecked);
$(this).parents(".RadioToggleGroup").find(".RadioToggleGravy").slideUp();
} );

$(".RadioToggleShow").click(function() {
var imgRadioNotChecked = '../content/images/radio-notchecked.png';
var imgRadioChecked = '../content/images/radio-checked.png';
$(this).parents(".RadioToggleGroup").find(".RadioToggleHide, .RadioToggleShow").find("IMG").attr("src", imgRadioNotChecked);
$(this).find("IMG").attr("src", imgRadioChecked);
$(this).parents(".RadioToggleGroup").find(".RadioToggleGravy").slideDown();
} );

/* Radio Toggle Switch */
$(".RadioToggleSwitch").css("cursor","pointer");
$(".RadioToggleSwitch").click( function() {
var imgRadioNotChecked = 'images/radio-notchecked.png';
var imgRadioChecked = 'images/radio-checked.png';
openthisdiv = $(this).attr("title");
$(this).parent(".RadioToggleGroup").children(".RadioToggleSwitch, .RadioToggleHide, .RadioToggleShow").find("IMG").attr("src", imgRadioNotChecked);
$(this).find("IMG").attr("src", imgRadioChecked);
$(this).parent(".RadioToggleGroup").children(".RadioToggleGravy").slideUp();
$(this).parent(".RadioToggleGroup").children("#" + openthisdiv + " , ." + openthisdiv).slideDown();
} );

/* New Radio Toggle Switch */
$(".RadioToggleSwitch2").css("cursor","pointer");
$(".RadioToggleSwitch2").click( function() {
		var openthisdiv = $(this).attr("rel");
		$(this).parents(".RadioToggleGroup").find(".guiICON").addClass("guiICON-radiooff").removeClass("guiICON-radioon");
		$(this).find(".guiICON").addClass("guiICON-radioon");
		$(this).parents(".RadioToggleGroup").find(".RadioToggleGravy:not([rel=" + openthisdiv + "])").slideUp();
		$(this).parents(".RadioToggleGroup").find(".RadioToggleGravy[rel=" + openthisdiv + "]").slideDown();
		});

/* Tab Toggle Switch */
$(".TabToggleGravy").css("display","none");

$(".TabToggleGroup .current").each( function() {
		openthisdiv = $(this).attr("rel");
		$("#" + openthisdiv).slideDown();
		$(".TabToggleGravy[rel=" + openthisdiv + "]").slideDown();
} );

$(".TabToggleSwitch").click( function() {
	openthisdiv = $(this).attr("rel");
	$(this).parents("UL").find("LI").removeClass("current");
	$(this).addClass("current");
	$(".TabToggleGravy:not([rel=" + openthisdiv + "])").slideUp();
	$("#" + openthisdiv).slideDown();
	$(".TabToggleGravy[rel=" + openthisdiv + "]").slideDown();
} );


/* Checkbox instead of radio buttons to open */
$(".CheckBoxToggle, .CheckBoxToggle *").css("cursor","pointer");
var imgIconChecked = 'images/ICON-checked.png';
var imgIconNotChecked = 'images/ICON-not-checked.png';

$(".CheckBoxToggle img").attr("src", imgIconNotChecked);
$(".CheckBoxToggle").toggle(function() {
		$(this).parents(".CheckBoxToggleGroup").find(".CheckBoxToggleGravy").slideDown();
		$(this).children("img").attr("src", imgIconChecked);
		$(this).parents(".CheckBoxToggleGroup").removeClass("HideFieldsetBorder").addClass("OpenedGroup");
}, function() {
		$(this).parents(".CheckBoxToggleGroup").find(".CheckBoxToggleGravy").slideUp();
		$(this).children("img").attr("src", imgIconNotChecked);
		$(this).parents(".CheckBoxToggleGroup").addClass("HideFieldsetBorder").removeClass("OpenedGroup");
});
$(".UnCheckBoxToggle img").attr("src", imgIconChecked);
$(".UnCheckBoxToggle").toggle(function() {
		$(this).parents(".CheckBoxToggleGroup").find(".CheckBoxToggleGravy").slideDown();
		$(this).children("img").attr("src", imgIconNotChecked);
		$(this).parents(".CheckBoxToggleGroup").addClass("HideFieldsetBorder").removeClass("OpenedGroup");
}, function() {
		$(this).parents(".CheckBoxToggleGroup").find(".CheckBoxToggleGravy").slideUp();
		$(this).children("img").attr("src", imgIconChecked);
		$(this).parents(".CheckBoxToggleGroup").removeClass("HideFieldsetBorder").addClass("OpenedGroup");
});

/* Checkbox Toggle Switch */
		var imgNotChecked = 'images/ICON-not-checked.png';
		var imgChecked = 'images/ICON-checked.png';
		$(".CheckBoxToggleSwitchGravy").css("display","none");

$(".CheckBoxToggleSwitch").toggle(
		function() {
			var openthisdiv = $(this).attr("title");
			$(this).parents(".CheckBoxToggleSwitchGroup").find(".CheckBoxToggleSwitch").find("IMG").attr("src", imgNotChecked);
			$(this).find("IMG").attr("src", imgChecked);
			$(this).parents(".CheckBoxToggleSwitchGroup").find(".CheckBoxToggleSwitchGravy").slideUp();
			$(this).parents(".CheckBoxToggleSwitchGroup").find("#" + openthisdiv).slideDown();
		}, function() {
			var openthisdiv = $(this).attr("title");
			$(this).find("IMG").attr("src", imgNotChecked);
			$(this).parents(".CheckBoxToggleSwitchGroup").find("#" + openthisdiv).slideUp();
	});

/* Collapse Toggle */

$(".CollapseToggle, .UnCollapseToggle").css("cursor","pointer");
$(".CollapseToggle").toggle( function() {
		var openthisdiv = $(this).attr("rel");
		$(this).parents(".CollapseToggleGroup[rel=" + openthisdiv + "]").find(".CollapseToggleGravy").slideUp();
		$(this).find(".guiICON").removeClass("guiICON-collapse").addClass("guiICON-expand");
		}, function() {
		var openthisdiv = $(this).attr("rel");
		$(this).parents(".CollapseToggleGroup[rel=" + openthisdiv + "]").find(".CollapseToggleGravy").slideDown();
		$(this).find(".guiICON").addClass("guiICON-collapse").removeClass("guiICON-expand");
		} );

$(".UnCollapseToggle").each( function() { 
			$(this).find(".guiICON").removeClass("guiICON-collapse").addClass("guiICON-expand"); 
		} )

$(".UnCollapseToggle").toggle( function() {
		var openthisdiv = $(this).attr("rel");
		$(this).parents(".CollapseToggleGroup[rel=" + openthisdiv + "]").find(".CollapseToggleGravy").slideDown();
		$(this).find(".guiICON").addClass("guiICON-collapse").removeClass("guiICON-expand");
		}, function() {
		var openthisdiv = $(this).attr("rel");
		$(this).parents(".CollapseToggleGroup[rel=" + openthisdiv + "]").find(".CollapseToggleGravy").slideUp();
		$(this).find(".guiICON").removeClass("guiICON-collapse").addClass("guiICON-expand");
		} );

/* Select Toggle */

$(".SelectSwitch").change(function () {
          $(this).find("option:selected").each(function () {
						var SwitchThis = $(this).attr("rel");
						$(this).parents(".SelectSwitchGroup").find(".SelectSwitchGravy").slideUp();
						$(this).parents(".SelectSwitchGroup").find(".SelectSwitchGravy[rel=" + SwitchThis + "]").slideDown();
						//alert("Something Changed: " + SwitchThis);
						});
        });

} );
