//begin functions before document ready

//begin hide videolinks
$("#videoLinks").hide();
//end hide videolinks

//begin function to open dialogue if certain link is clicked, was used in introFlash
function dialogOpen(rVar) {
	$('#dialog').dialog("open");
	$("#selectState").append("<input type=\"hidden\" name=\"r\" value=\"" + rVar + "\">");
}
//end function to open dialogue if certain link is clicked

//end functions before document ready

//begin document ready
$(function() { 
	//begin open dialogue
	$.fx.speeds._default = 1000;
	// increase the default animation speed to exaggerate the effect
	$('#dialog').dialog({
		autoOpen: false,
		//show: 'fade',
		//'hide: 'explode'
		resizable: false,
		height:260,
		width:400,
		modal: true,
		buttons: {
			'Select State': function() {
				$(this).dialog('close');
				$('#selectState').submit();
			},
			Cancel: function() {
				$(this).dialog('close');
				dialogTimer();
			}
		}
	});
	//end open dialogue
	
//begin dialog timer
function dialogTimer() {
	setTimeout(function () {
	   $('#dialog').dialog("open");
	}, 60000);
}
//end dialog timer

//BANDAIDED FOR NOW, SHOWS SELECT STATE WITH NO RADIALS CHECKED, BUT DOESN'T SHOW WHEN ONE OF THEM IS CHECKED
//begin Get Territories By Distribution Channel
// if Distribution Channel radio button is already set...
	if ($('input:radio[id=Brokerage]:not(:checked)') && $('input:radio[id=FinancialInstitution]:not(:checked)')) {
	//if ($('input:radio[id=Brokerage]:checked') || $('input:radio[id=FinancialInstitution]:checked')) {
			//$('#stateDropdownTitle').hide();
		$DistributionChannel = $('input:radio[name=DistributionChannel]:checked').val();
		$.post('/includes/master-functions.php', { DistributionChannel: $DistributionChannel }, function(data) {
			$('#stateDropdown').html(data);
		});
	}
	else {
		$('#stateDropdownTitle').show();
		$DistributionChannel = $('input:radio[name=DistributionChannel]:checked').val();
		//$.post('/home/58/32/2913258/web/includes/master-functions.php', { DistributionChannel: $DistributionChannel }, function(data) {
		$.post('/includes/master-functions.php', { DistributionChannel: $DistributionChannel }, function(data) {
			$('#stateDropdown').html(data);
		});
	}
// Otherwise, on click of the Distribution Channel radio button...
	$('input:radio[name=DistributionChannel]').click(function(){ 
	$('#stateDropdownTitle').show();
	$DistributionChannel = $('input:radio[name=DistributionChannel]:checked').val();
	$.post('/includes/master-functions.php', { DistributionChannel: $DistributionChannel }, function(data) {
		$('#stateDropdown').html(data);
	});
    });

//begin hiding and toggling channel definitions for dialog
$("#DescriptionFinancialInstitution").hide();
$("#DescriptionBrokerage").hide();
$("a#defLinkFI").hover(function(){
	$("#DescriptionFinancialInstitution").toggle();
});
$("a#defLinkB").hover(function(){
	$("#DescriptionBrokerage").toggle();
});
//end hiding and toggling channel definitions for dialog
				
//begin to show/populate page items if cookie is detected
if ($.cookie('oaState') && $.cookie('oaFSMName')) {
	$(".ConsumerContent").hide();
	$(".BrokerOnlyContent").show();
}
//end to show/populate page items if cookie is detected
		

//begin function to open dialogue if certain link is clicked
$('a.opener').click(function(event) {
	event.preventDefault();
	$('#dialog').dialog('open');
	//checkDistributionChannel();
});
//end function to open dialogue if certain link is clicked

//begin product image hovers
$("img.hover").hover(
function() {
$(this).animate({"opacity": ".5"}, 200);
},
function() {
$(this).animate({"opacity": "1"}, 500);
});
//end product image hovers

//begin buttonShadow hovers
//$(".buttonShadow").hover(
//function() {
//$(this).switchClass("buttonShadow", "buttonShadowDark", 1000);},
//function() {
//$(this).switchClass("buttonShadowDark", "buttonShadow", 1000);});
$("img.buttonShadow").hover(
function() {
$(this).toggleClass("buttonShadowDark", 1000);});
//end buttonShadow hovers

//begin hide videolinks for the "after navbar loads"
$("#videoLinks").hide();
//end hide videolinks for the "after navbar loads"

//begin toggle #videoLinks
$("#hideVideoLinks").click(function() {
$("#videoLinks").toggle();
});
//end toggle #videoLinks

//begin hide .sidebarLinks for the "after navbar loads"
$(".sidebarLinks").hide();
//end hide .sidebarLinks for the "after navbar loads"

//begin toggle .sidebarLinks
$(".showSidebarLinks").click(function() {
$(this).parent().siblings(".sidebarLinks").toggle(); //shows next sidebarLinks
//$(this).siblings("ul.sidebarLinks").toggle(); //shows next sidebarLinks
//$(this > ".sidebarLinks"); //shows next sidebarLinks
//$(this).next("ul .sidebarLinks").toggle(); //shows next sidebarLinks
//$(".sidebarLinks").toggle(); //shows next sidebarLinks
});
//end toggle .sidebarLinks

//begin if cookie is detected
if ($.cookie('oaState')) {
}
else {
	//Start timer for popup login
	dialogTimer();
}
//end if cookie is detected

});
//end document ready
