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

jQuery(document).ready(function () {
  	setOpacity();
	setToggleInputs();
	setHoverOnButtons();
	setImageStyles();

});

function setImageStyles () {
	jQuery("img[border!='']").each(function (i) {
		jQuery(this).css('border-width',jQuery(this).attr('border') + 'px');
		jQuery(this).css('border-style','solid');
	});
	jQuery("img[vspace!='']").each(function (i) {
		jQuery(this).css('margin-top',jQuery(this).attr('vspace') + 'px');
		jQuery(this).css('margin-bottom',jQuery(this).attr('vspace') + 'px');
	});
	jQuery("img[hspace!='']").each(function (i) {
		jQuery(this).css('margin-left',jQuery(this).attr('hspace') + 'px');
		jQuery(this).css('margin-right',jQuery(this).attr('hspace') + 'px');
	});


	return true;

}

/**
 * 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+')');
	});
	
	return true;
}

/**
 * Toggle inputs default values 
 * 
 * @return bool
 */

function setToggleInputs () {
	
	jQuery("[class*='toggle-inputs']").each(function (i) {
		var defaultValue = jQuery(this).val(); 
		jQuery(this).bind("click", function(){
			if (jQuery(this).val() == defaultValue) {
				jQuery(this).val('');
			}
		});

		jQuery(this).bind("focus", function(){
			if (jQuery(this).val() == defaultValue) {
				jQuery(this).val('');
			}
		});

		jQuery(this).bind("blur", function(){
			if (jQuery(this).val() == '') {
				jQuery(this).val(defaultValue);
			}
		});
	});

	return true;
}

/**
 * Set hover on buttons
 * 
 * @return bool
 */

function setHoverOnButtons () {
	
	jQuery("button").each(function (i) {
		jQuery(this).bind("mouseover", function(){
			jQuery(this).css("color","#da251c");
		});
		jQuery(this).bind("mouseout", function(){
			jQuery(this).css("color","#9f9f9f");
		});
	});
	jQuery(".button").each(function (i) {
		jQuery(this).bind("mouseover", function(){
			jQuery(this).css("background-image","url(templates/default/images/button-hover.gif)");
		});
		jQuery(this).bind("mouseout", function(){
			jQuery(this).css("background-image","url(templates/default/images/button.gif)");
		});
	});
	return true;
}
