
$(document).ready(function() {	
	initSingleMenu();
	//initIE6();
	$.preloadImages("/img/article/readOtherOpen.png", "/img/article/readOtherClose.png");
	initSmartSubMenu();
	$("#slideshowbanner").slideshowGov1({'fadetimeshuffle':300,'fadetimebutton':500,'fadetimeright':500,'fadetimeleft':500});
});

$(function(){
	var sclass = "smartManuActiveColor_helpme";
	var sections = $('#smartMenu ul li a');
	var current = -1;
	
	//register deep-links changing event
	$.address.change(function(event) {				  	
		event.preventDefault();
		//extract after slash
		page = event.value.substr(1);
		loadLink();
	});
	
	function loadLink(){
		if ($.address.value() != "/"){
			//load page and extract section 	
			var purl = $.address.value().substr(1);

			//$('#smartContent').ClearTypeFadeOut({speed: 300, callback:function(){	
				
				//load smartContent directly					
				$("#smartContent").load(purl+" #genericContent", null, function(){
					$('#smartContent').ClearTypeFadeIn({speed: 600});	
					initSingleMenu();
					//regSmoothScroll();	
					
				});
				//load related Links directly		
//				$('#relatedLinksContainer').load(purl+" ul#innerPageRelatedLinks" , null, function(){
					//init related Links
//					initRelatedLinksGeneric();
//					initIE6();
				//$('#otherArticle').load(purl+" ul.singleMenu" , null, function(){
					//init related Links
					//initSingleMenu();
				//});
			//}});	
					
				
//			});
			//left menu background and cursor color
			$('#smartMenu ul li').removeClass("active");
			var currentIndex = $('#smartMenu ul li a[href="'+ page +'"]');
			//console.log(currentIndex);
			current = currentIndex;
			$(currentIndex).parents("li").addClass("active");
			$('#smartMenu ul li a').addClass("smartMenuTitle");
			$('#smartMenu ul li a').removeClass("smartMenuTitleActive");
			$('#smartMenu ul li a').removeClass(sclass);
			$(currentIndex).addClass("smartMenuTitleActive "+sclass);
			$(currentIndex).removeClass("smartMenuTitle");			
			//Page title
			$('.breadcrumbCurrent').html(currentIndex.text());
			$.address.title($.address.title().split(' | ')[0] + ' | ' + currentIndex.text());
			$('#clusterTitle h1').html(currentIndex.text());
			$('#genericbanner span').html(currentIndex.text());
			$('#accordingContainer').load(purl+" div.accordion" , null, function(){
				$('#smartMenuSidebar .accordion').accordion({
				header:'h2',
				autoHeight:false,
				active:$('#smartMenuSidebar .accordion > div').size()-1
				});
				$('h2').focus(function(){$(this).blur();});
			});	
	
		}else{
			//$('#smartMenu ul li:first').addClass("active");
		}	
	}
	
	$.each (sections, function(n, section){
		$(section).click(function(event){
			event.preventDefault();
			addurl = $(event.currentTarget).attr("href");	
			if (current != this){			
				//change address bar address to trigger addres event
				$.address.value(addurl);  
			}
			current = this;
		});		
	});
	//smooth scrolling
	
	function regSmoothScroll(){
		//register smooth scrolling event
		$('#smartBackToTop').click(function(e){
			e.preventDefault();
			$('html, body').animate({
				scrollTop: $("#smartMenuPage").offset().top
			}, 1000);
		});		
	}
	$('#smartContentContainer2 div.sec').css("display","none");
	$('#smartContent').css("display","block");	
});



(function($) {
	$.fn.ClearTypeFadeTo = function(options) {
		if (options)
			$(this)
				.show()
				.each(function() {
					if (jQuery.browser.msie) {
						// Set the bgColor so that bold text renders correctly (bug with IE/ClearType/bold text)
						$(this).css({ 'background-color': (options.bgColor ? options.bgColor : '#f7f7f7') })
					}
				})
				.fadeTo(options.speed, options.opacity, function() {
					if (jQuery.browser.msie) {
						// ClearType can only be turned back on if this is a full fade in or
						// fade out. Partial opacity will still have the problem because the
						// filter style must remain. So, in the latter case, we will leave the
						// background color and 'filter' style in place.
						if (options.opacity == 0 || options.opacity == 1) {

							// Remove the 'filter' style to restore ClearType functionality.
							$(this).get(0).style.removeAttribute('filter');
						}
					}
					if (options.callback != undefined) options.callback();
				});
	};

	$.fn.ClearTypeFadeIn = function(options) {
		if (options)
			$(this)
				.css({ opacity: 0 })
				.ClearTypeFadeTo({ speed: options.speed, opacity: 1, callback: options.callback });
	};

	$.fn.ClearTypeFadeOut = function(options) {
		if (options)
			$(this)
				.css({ opacity: 1 })
				.ClearTypeFadeTo({ speed: options.speed, opacity: 0, callback: options.callback });
	};
})(jQuery);

/* Accordion Menu */
$(function(){
	$('#smartMenuSidebar .accordion').accordion({
		header:'h2',
		autoHeight:false,
		active:$('#smartMenuSidebar .accordion > div').size()-1
	});
});


