(function( $ ){

	var settings = {
		delay: 250
	};

	var methods = {

		init : function( options ) {

			if ( options ) $.extend( settings, options );

			settings.nav = this;

			return this.each(function() {
				$(this)
				.children("li")
				.hover(
					function(){ $(this).ElestrinTopNav("scheduleShow"); }
					,function(){ $(this).ElestrinTopNav("scheduleHide"); }
				);
			});
		},

		scheduleShow : function(){
			$(this).addClass("show");
			$(this).removeClass("hide");
			setTimeout(function(){
				$.fn.ElestrinTopNav("doShow");
			},settings.delay);

		},

		scheduleHide : function(){
			$(this).addClass("hide");
			$(this).removeClass("show");
			setTimeout(function(){
				$.fn.ElestrinTopNav("doHide");
			},settings.delay);
		},

		doShow : function(){

			$.fn.ElestrinTopNav("doHide");

			var toShow = settings.nav.find(".show .sub");

			switch(true) {
			case $.browser.msie:
				toShow.show();
				break;
			default:
				toShow.fadeIn();
				break;
			}
			toShow.calcSubWidth();
			toShow.css({'width' : rowWidth});
			toShow.find(".sub_top").css({'width' : rowWidth+5});

		},

		doHide : function(){

			var toHide = settings.nav.find(".hide .sub");

			switch(true) {
			case $.browser.msie:
				toHide.hide().removeClass("hide");
				break;
			default:
				toHide.fadeOut().removeClass("hide");
				break;
			}
		}

	};

	$.fn.ElestrinTopNav = function( method ) {
		// Method calling logic
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		}
	};

})( jQuery );

$(document).ready(function(){
	$("#topnav").ElestrinTopNav("init");
});

