// JavaScript Document

$(document).ready(function() {
	
	// To Replace blank space with &nbsp;
	$("#naviGation ul ul li a").each(function(){
		var text = jQuery(this).html();
		jQuery(this).html(text.replace(/ /g, "&nbsp;"));
	});
	// Append Something
	$("#naviGation ul ul").append("<li class='last'><div><span>&nbsp;</span></div></li>")
	$("#naviGation ul li.active").append("<span class='aSn'>&nbsp;</span>");
	
	$("#naviGation ul li a").mouseenter(function () {
      jQuery(this).next("ul").slideDown(300);
     });
	$("#naviGation ul li").mouseleave(function () {
        $(this).find("ul").slideUp(200);
    });
	
});


/** Scroll to Top **/
//plugin
jQuery.fn.topLink = function(settings) {
  settings = jQuery.extend({
    min: 1,
    fadeSpeed: 200
  }, settings);
  return this.each(function() {
    //listen for scroll
    var el = $(this);
    el.hide(); //in case the user forgot
    $(window).scroll(function() {
      if($(window).scrollTop() >= settings.min)
      {
        el.fadeIn(settings.fadeSpeed);
      }
      else
      {
        el.fadeOut(settings.fadeSpeed);
      }
    });
  });
};

//usage w/ smoothscroll
$(document).ready(function() {
  //set the link
  $('a[href="#top"]').topLink({
    min: 400,
    fadeSpeed: 700
  });
  //smoothscroll
  $('a[href="#top"]').click(function(e) {
    e.preventDefault();
    $.scrollTo(0,300);
  });
});
