/**
 * Nucleo (X)HTML/CSS Framework
 *
 * Supporting scripts for makeup
 *
 * Don't make any changes in this file!
 *
 * @copyright       Copyright (c) Sergey Gogolev
 * @link            http://css.softprojects.ru/
 * @license    		CC-A-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * @version         0.1.5
 */

jQuery(document).ready(function () {

  	setOpacity();
	setCatItems();
		Menu.Init();
});

/**
 * Set opacity style for elements, which have style like 'opacity-15'
 * 
 * @return bool
 */

function setOpacity () {
	
	jQuery("[class*='opacity']").each(function (i) {
		var opacityValue = this.className.substr(this.className.indexOf('opacity-') + 'opacity-'.length, 2);
		jQuery(this).css('opacity','.' + opacityValue);
		jQuery(this).css('filter','Alpha(opacity=' + opacityValue+')');
	});
	
	jQuery(".menu-item").bind('mouseover',function () {
		jQuery(this).children(':first').css('opacity','1');
		jQuery(this).children(':first').css('filter','Alpha(opacity=100)');
	});
	
	jQuery(".menu-item").bind('mouseout',function () {
		var opacityValue = jQuery(this).children(':first').attr('class').substr(jQuery(this).children(':first').attr('class').indexOf('opacity-') + 'opacity-'.length, 2);
		jQuery(this).children(':first').css('opacity','.' + opacityValue);
		jQuery(this).children(':first').css('filter','Alpha(opacity=' + opacityValue+')');
	});
	
	
	return true;
}

function setCatItems () {
	
	jQuery(".catmenu-item").bind('mouseover', function () {
		jQuery(this).css('color',jQuery(this).css('borderBottomColor'));
	});

	jQuery(".catmenu-item").bind('mouseout', function () {
		jQuery(this).css('color','rgb(14, 107, 202)');
	});

	
	return true;
}

var Menu = {

	  version	: '0.0.1'
	
	, menuTimeOut : 0
	, menuTimeOutMS : 1000
	
	, Init : function() {
		jQuery('.menu-item').bind('mouseover', function() {
			
			jQuery('.menu-sub').filter('[id!='+this.id+']').hide();
			if (jQuery('#' + this.id + '-submenu').css('display') == 'none') {
				jQuery('#' + this.id + '-submenu').fadeIn();
				clearTimeout(Menu.menuTimeOut);
			}
		});
		jQuery('.menu-item').bind('mouseout', function() {
			Menu.menuTimeOut = setTimeout("jQuery('#" + this.id + "-submenu').fadeOut('slow');  ", Menu.menuTimeOutMS);
		});
		jQuery('.menu-sub').bind('mouseout', function() {
			Menu.menuTimeOut = setTimeout("jQuery('#" + this.id + "').fadeOut('slow'); ", Menu.menuTimeOutMS);
		});
		jQuery('.menu-sub').bind('mouseover', function() {
			clearTimeout(Menu.menuTimeOut);
		});
		return true;
	}
}