/*
Project: Theme
Author: Brian DiChiara
Version: 1.0
*/
var Theme = {
	
	path: '',
	apppath: '',
	
	options : {
		label_opacity : .4
	},
	
	init : function(opts){
		Theme._setopts(opts);
		
		Theme.focus_fade_inputs();
		
	},
	
	focus_fade_inputs : function(){
		var $inputs = $('.focus-fade input.text, .focus-fade textarea');
		$.each($inputs, function(i, el){
			var $input = $(el);
			var $label = $(el).parents('label').find('.label');
			
			setTimeout(function(){ // delay for browser password auto-fillers
				if($input.val()){
					$label.hide();
				}
			}, 50); // 50ms should be enough. maybe bump it to 100
			
			$input.focus(function(e){
				if(!$input.val()){
					if($input.css('opacity') != Theme.options.label_opacity){
						$label.fadeTo('fast', Theme.options.label_opacity);
					}
				} else {
					$label.hide();
				}
			});
			
			$input.blur(function(e){
				if(!$input.val()){
					$label.fadeTo('fast', 1);
				} else {
					$label.hide();
				}
			});
			$input.keyup(function(e){
				if(!$input.val()){
					$label.fadeTo('fast', Theme.options.label_opacity);
				} else if($input.val()){
					$label.fadeTo('fast', 0);
				}
			});
		});
	},
	
	_setopts : function(opts){
		if(typeof(opts) == 'object'){
			for(var opt in opts){
				Theme.options[opt] = opts[opt];
			}
		}
	}
}

$(function(ready){
	Theme.init();
});


function ajaxJSON(json){
	if(json){
		var obj = (typeof(json) == 'object') ? json : eval('(' + json + ')');
		eval(obj.script);
		if(obj.confirm){
			obj.success = confirm(obj.confirm);
		}
		return obj;
	}
	return {};
}
