jQuery(document).ready(function() {
		
	/*jQuery("li.active-item").parent("ul").parent("li").addClass("active-parent");
	jQuery("li.active-item").parent("ul").css("display", "block");*/
		
	jQuery("#fontsize").bind("click", function() {
		var size = jQuery("body").css("font-size").replace("px", "");
		var size = parseInt(size) + 2 + "px";
		jQuery('body').css("font-size", size)
		if (size == "16px") {
			jQuery("#fontsize").css("display", "none")
			jQuery("#fontsize2").css("display", "inline")
		}
		return false;
	});

	jQuery("#fontsize2").bind("click", function() {
		var size = jQuery("body").css("font-size").replace("px", "");
		var size = parseInt(size) - 2 + "px";
		jQuery('body').css("font-size", size)
		if (size == "12px") {
			jQuery("#fontsize").css("display", "inline")
			jQuery("#fontsize2").css("display", "none")
		}
		return false;
	});

	jQuery("#print").bind("click", function() {
		window.print()
	});

	jQuery(".navhover").hover(function() {
		if (jQuery.browser.version == 6.0) {
			var xx = jQuery(this).find("ul").css({ "display": "block", "visibility": "hidden" })
			var left = jQuery(xx).css("left");
			var width = jQuery(xx).width()  + "px";
			var height = jQuery(xx).height() - 4 + "px";
			var iframe = '<iframe frameborder="0" height=' + height + ' width=' + width + ' style=" position:absolute; z-index:9; top:34px;left:' + left + '"></iframe>'
			jQuery(this).append(iframe);
			jQuery(this).find("ul").css({ "visibility": "visible", "z-index": "999" });
			jQuery(this).children("a").addClass("hover");

		} else {
			jQuery(this).children("a").addClass("hover");
			jQuery(this).find("ul").css("display", "block");
		}
	},
			function() {
				if (jQuery.browser.version == 6.0) {
					jQuery(".navhover iframe").remove();
					jQuery(this).find("ul").css({ "visibility": "hidden", "z-index": "999" });
				}
				jQuery(this).find("ul").css("display", "none");
				jQuery(this).children("a").removeClass("hover");
			}
		);
	

	var config = {
		sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)    
		interval: 200, // number = milliseconds for onMouseOver polling interval    
		over: showMenu, // function = onMouseOver callback (REQUIRED)    
		timeout: 200, // number = milliseconds delay before onMouseOut    
		out: hideMenu // function = onMouseOut callback (REQUIRED)    
	};
	var enableMenu;
	jQuery(document).mousemove(function(e) {
		enableMenu = true;
	});

	function showMenu() {
		// First close any siblings of this item
		if (enableMenu) {
			var kids = jQuery(this).siblings().children("ul");
			jQuery(kids).slideUp(300);
			jQuery(this).siblings().each(function(i) {
				if (jQuery(this).children("a").css("background-image").indexOf("arrow-2.gif") > 0 ) {
					jQuery(this).children("a").css("background-image", "url(/global/img/arrow-1.gif)");
				}
			});
			// If this item is already open, close it too, otherwise open it
			var le = jQuery(this).children("ul");
			jQuery(le).slideDown(300);
			if (le.length > 0 && jQuery(le).children("li").length > 0) {
				jQuery(this).children("a").css("background-image", "url(/global/img/arrow-2.gif)");
			}
			enableMenu = false;
		}
	}

	function hideMenu() {
		
	}

	//jQuery(".nav-aside li").hoverIntent(config);

//	var level = jQuery(".nav-aside li");
//	level.each(function(i, item) {
//		var le = jQuery(item).children("ul");
//		if (le.length > 0 && jQuery(le).children("li").length > 0) {
//			jQuery(item).children("a").each(function(i) {
//				var x = jQuery(this).css("padding-left").replace("px", "") - 10;
//				jQuery(this).attr({
//					style: "background-image:url(/global/img/arrow-1.gif);background-repeat: no-repeat;background-position: " + x + "px center;"
//				});
//			});
//			jQuery(item).children("a").toggle(
//								function() {
//									if (location.href != this) {
//										location.replace(this);
//									}
//								},
//		function() {
//			jQuery(item).children("a").css("font-weight", "100")
//			jQuery(le).css("display", "none")
//		})
//		}
//	});
   

	var url = window.location.href;
//	level.each(function(i, item) {
//		var u = jQuery(item).children("a").attr("href");
//		if (url.indexOf(u) >= 0) {
//			jQuery(item).parents("ul").css("display", "block");
//			//jQuery(item).parents("ul").prev("a").css("font-weight", "bold");
//			jQuery(item).children("ul").css("display", "block");
//		}
//	})

    jQuery(".faq dl dt").click(function()
        {
			if(jQuery(this).next("dd").css("display")=="none"){
					jQuery(this).next("dd").show(500);
			}
			else{
					jQuery(this).next("dd").hide(500);
			}
			return false;
		})
		
	jQuery(".tips dl dt").click(function(){
	        if(jQuery(this).css("backgroundImage") == ("url(" + ImageOne +")")){
	            jQuery(this).css("backgroundImage", "url('"+ImageTwo+"')");
	            jQuery(this).next("dd").show(500);
	        }else{
	            jQuery(this).css("backgroundImage", "url('"+ImageOne+"')");
	            jQuery(this).next("dd").hide(500);
	        }
	        return false;
		})
	
	//Nav aside
	 jQuery(".nav-aside ul li:has('li.li_curr_item') > a").addClass("li_child_current");
	 jQuery(".nav-aside li.li_curr_item").children("ul").show();
	 
	/*jQuery(".nav-aside > ul > li.li_curr_item > a").click(function() {
			if(jQuery(".nav-aside > ul > li.li_curr_item > ul").css("display")=="none"){
				jQuery(this).parent().removeClass("close");	
			jQuery(this).parent().children("ul").show();
			  return false;
				}else{
			jQuery(this).parent().addClass("close");
			jQuery(this).parent().children("ul").hide();
			return false;}
	   }
	  ); */
	         
	       // Search Box
			 jQuery("#cse-search-box span.text input").focus(function(){
				 if(jQuery(this).val() == jQuery(this).attr('title'))
				    {jQuery(this).val("");}          
				}).blur(function(){
					 if (jQuery(this).val() == '') {
						jQuery(this).val(jQuery(this).attr('title'));
					 }
				});	
			 
         // NewsSlider
		if (jQuery('#newsSlider').length > 0){
		   jQuery('#newsSlider div.slides_container div.item').show();
		   jQuery('#newsSlider').slides({
				width: 704,
				height: 237,
				preload: false,
				play: 10000,
				generatePagination: false,
				effect: 'slide',
				slideSpeed: 1000,
				fadeSpeed:1000,
				crossfade: true
			});
            
		  }  
		   
		   //Popup
			jQuery("a.show-all").click(function(){
					 jQuery(this).next(".popup").addClass("open");
					 jQuery(this).parent().parent().parent(".row").siblings().children().children().children(".popup").removeClass("open");
					 jQuery(this).parent().parent().siblings(".farmcontent").children().children(".popup").removeClass("open")
					 return false;
				  });
			 jQuery("span.close").click(function(){
					 jQuery(this).parent(".popup").removeClass("open")
					 return false;
				  });
				  
			 jQuery(".farmcontent:nth-child(2n)").addClass("second-column");
			 jQuery(".two-item .farmcontent").removeClass("second-column");
			 
			 //Disable a link
			 jQuery(".a-z ul.collection li a.current").click(function(){
			      return false;
			
			 })
			 				  
			//Breadcrumb last li
			jQuery(".breadcrumb ul li:last").addClass("last")
			
			//Remove RHS if empty
			//if (jQuery("div#aside-secondary").text().trim() == "")
			if (jQuery("div#aside-secondary .module").size()==0 )
			{ jQuery("div#aside-secondary").remove()}
                     
           	//Remove the arrow if the <a> in li is not from the first word
			jQuery("div.article ul li:has(a), .hotspot .row .item ul li:has(a)").each(function(){
			  String.prototype.trim = function (){return this.replace(/\s/g, '');}
			  var Astr = jQuery(this).html(); 
              Astr = Astr.trim().toLowerCase().substr(0,2);
			  if ( Astr!= "<a")
			 { jQuery(this).children().addClass("no-arrow"); }
			 
			})
			
			//MultiMedia page
			if (jQuery("#pikame").length > 0) {
			jQuery("#pikame").PikaChoose();
		    jQuery('#pikame').jcarousel();
			}

		    //Add Table border
		    jQuery("table[border='1']").addClass("has-border");
})

jQuery(window).bind('load', function() {
    jQuery("#newsSlider img").ndLazyLoad();		
});
