jQuery.fn.syncHeight = function(selBiggestElement) {
	var height = jQuery(selBiggestElement).outerHeight();
	return this.each(function() {
		jQuery(this).height(height-2);
	});
};

jQuery.fn.minMax = function(){
	if (jQuery.browser.msie && jQuery.browser.version <= 6) {
		var minWidth = parseInt(this.css('min-width'));
		var maxWidth = parseInt(this.css('max-width'));
		
		var currentWidth = this.parent().width();
		
		if (minWidth > 0 && currentWidth < minWidth)
			this.width(minWidth);
		else if (maxWidth > 0 && currentWidth > maxWidth)
			this.width(maxWidth)
		else
			this.width(currentWidth);
	}
		
	return this;
};

jQuery.fn.dropShadow = function(cfg){
	cfg = jQuery.extend({
		top: true,
		bottom: true,
		left: true,
		right: true
	}, cfg);
	
	this.addClass("shadow")
		.wrapInner("<div class=\"shadow-fill\"><div class=\"shadow-content\"></div></div>");
		
	if (cfg.top) {
		this.prepend(
			"<div class=\"shadow-top\">" +
			(cfg.left ? "<span class=\"shadow-top-left\"></span>" : "") +
			"<span class=\"shadow-top\"></span>" +
			(cfg.right ? "<span class=\"shadow-top-right\"></span>" : "") +
			"</div>");
	}

	if (cfg.bottom) {
		this.append(
			"<div class=\"shadow-bottom\">" +
			(cfg.left ? "<span class=\"shadow-bottom-left\"></span>" : "") +
			"<span class=\"shadow-bottom\"></span>" +
			(cfg.right ? "<span class=\"shadow-bottom-right\"></span>" : "") +
			"</div>");
	}

	this.find("div.shadow-fill").eq(0)
		.prepend(
			(cfg.left ? "<span class=\"shadow-left\"></span>" : "") +
			(cfg.right ? "<span class=\"shadow-right\"></span>" : "")
		)
		//.children("span").syncHeight(this.find("div.shadow-fill").eq(0))
		;
	
	return this;
};

(function() {
	var lastActiveMenu;
	var timeoutId;
	var mouseOverCount = 0;
	
	jQuery.fn.getMenu = function() {
		var id = jQuery(this).attr("id");
		strMenu = id.substr(id.length-1);
		return strMenu;
	}
	
	jQuery.fn.showMenu = function(strMenu) {
		if (!strMenu || strMenu == "") {
			strMenu = jQuery(this).getMenu();
		}
		
		var activeMenu = jQuery("div#menu-cat li.active").get(0)
		if (activeMenu)
			lastActiveMenu = jQuery(activeMenu).getMenu();
		
		jQuery("div#menu-cat li").removeClass("hover active");
		jQuery("li#menu-cat-"+strMenu).addClass("hover");
		
		jQuery("div.menu-main").hide();
		jQuery("div#menu-main-"+strMenu).show();
		
		clearTimeout(timeoutId);		
		mouseOverCount++;
		
		return this;
	}
	
	jQuery.fn.hideMenu = function() {
		mouseOverCount--;
		clearTimeout(timeoutId);

		timeoutId = setTimeout(function() {
			if (lastActiveMenu && mouseOverCount <= 0) {
				jQuery("div#menu-cat li").removeClass("hover active");
				jQuery("li#menu-cat-"+lastActiveMenu).addClass("active");
				
				jQuery("div.menu-main").hide();
				jQuery("div#menu-main-"+lastActiveMenu).show();
			}
		}, 1000);
		
		return this;
	}
})();

jQuery.fn.defaultValue = function(text){
    return this.each(function(){
		if(this.type != 'text' && this.type != 'password' && this.type != 'textarea')
			return;

		var fld_current=this;

		$(this).focus(function() {
			if(this.value==text || this.value=='')
				$(this).val('').removeClass("is-default");
		});

		$(this).blur(function() {
			if(this.value==text || this.value=='')
				$(this).val(text).addClass("is-default");
		});
		
		$(this).blur();

		$(this).parents("form").each(function() {
			$(this).submit(function() {
				if(fld_current.value==text) {
					fld_current.value='';
				}
			});
		});
    });
};

