/**
 * Nucleo (X)HTML/CSS Framework
 *
 * @copyright       Copyright (c) Sergey Gogolev
 * @link            http://www.softprojects.ru/
 * @license    		CC-A-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * @version         0.2.3
 */
 
jQuery(document).ready(function() {

	CAccardeon.init({
		'speed'	: 600
	});
	CToggles.init();
});

 
/**
 *  CAccardeon
 */
 
	var CAccardeon = {version : '0.3.2'
	
		, options : {}
	
		, defaults : {
			'speed'		: 600
		}

		, init : function(options) {var self = this;
		
			self.options  	= jQuery.extend({}, self.defaults, options || {});
			
			jQuery('div.accardeon').find('div.bar').unbind('click').click(function(){
				var parent  = jQuery(this).parent();
				var text 	= parent.find('div.text');
				var height  = text.height();
				var wrapper = parent.find('div.text-wrapper');
				
				wrapper.slideToggle(self.options.speed);

			return false;})
		}
	}
	
var Form = {version	: '0.0.2'
	  
	, refreshCodeImage : function () {
		jQuery('#codeimageChangeable').attr('src','codeimage/' + Math.random());
	return true;} 

	, checkmail : function (email) { 
		dog = email.indexOf("@"); 
		if (dog == -1) return false; 
		if (email.indexOf(".") == -1) return false; 
		if ((dog < 1) || (dog > email.length - 5)) return false;  
		if ((email.charAt(dog - 1) == '.') || (email.charAt(dog + 1) == '.')) return false; 
	return true;} 
	
	, check : function (form) { 
	
		var error = 0;
	
		jQuery('.check-simple', jQuery(form)).each(function(){
			var currentId = jQuery(this).attr('id');
				
		
			jQuery('#'+ currentId +'-error').html('');
			if 	((jQuery(this).val() == '') ||
				(jQuery(this).html() == '' && jQuery(this).attr('tagName') == 'textarea') ||
				(jQuery(this).attr('type') == 'checkbox' && jQuery(this).attr('checked') == false)) {
				jQuery('#'+ currentId +'-error').html('Заполните данное поле');	
				error++;
			}
		});
		
		jQuery('.check-email', jQuery(form)).each(function(){
			var currentId = jQuery(this).attr('id');
			jQuery('#'+ currentId +'-error').html('');
			if 	(jQuery(this).val() == '') {
				jQuery('#'+ currentId +'-error').html('Заполните данное поле');	
				error++;
			} else if (!Form.checkmail(jQuery(this).val())) {
				jQuery('#'+ currentId +'-error').html('Некорректный email');	
				error++; 
			}
		});

		if (error > 0) return false;
		
	return true;}

}
