$(document).ready(function() {
	$("#main_tabs").tabs({ fx: { opacity: 'toggle', duration: 'fast' } }).show();


	$("a.toggle_notice").click(function () {
			$("div.notice").fadeOut("slow");
	});

	
	$('#site_search').blur(function(){
		if($(this).val() == "")
		{
			$(this).val('Search MyGov365...');
		}
	});
	
	$(".flag").click(function(){				
	var answer = confirm($(this).attr('title'));
		if(answer)
		{
			url = $(this).attr("href");
			$.get(url);
			$(this).parent().html("<img src='"+document.location.protocol+"//assets.mygov365.com/resources/img/icons/famfamfam/flag_red.png'> Content Flagged.").removeClass('dim');
		}
		return false;
	});
	
	
	
	 //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	$("ul.topnav li").stop().hover(function(){
		$(this).find("span").addClass('topnav_buttonhover').parent().parent().find("em").addClass('topnavsubhover');
			}, function(){
		$(this).find("span").removeClass('topnav_buttonhover').parent().parent().find("em").removeClass('topnavsubhover');
	}); 
 
 
	$("ul.topnav li em").stop(true, true).click(function() { //When trigger is clicked...
		$(this).parent().find("ul.subnav").slideDown('fast'); //Drop down the subnav on click
			$(this).parent().hover(function() {
				}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});
	 
	//Following events are applied to the trigger (Hover events for the trigger)
	});
	
	

});

function cherryActive() {
	if ($(this).hasClass('cherry')) {
		this.origValue = this.value;
		$(this).filter(".cherry").removeClass('cherry').val('');
	}
}

$(".cherry").click(cherryActive).focus(cherryActive).blur(function () {
	if (!this.value && !$(this).hasClass('cherry')) {
		$(this).addClass('cherry').val(this.origValue);
	}
});

$("#search").submit(function () {
	$(this).find('.cherry').val('');
});


$(".force_login").live('click', function(){
	$("#login_window").dialog('open');
	
	href = $(this).attr('href');
	if ($('#login_window').length != 0) {
		if (href.length != 0) {
			href.replace(document.location.protocol + "//" + document.domain, '');
			$('#modal_redirect').val(href);
		}
	}
	
	return false;
});
	
$("#login_window").dialog({
		autoOpen: false,
		bgiframe: true,						
		width: 402,
		modal: true,
		overlay: {
			opacity: 0.75,
			background: "black"
		}
});