/*
 * jquery-util.js - JavaScript Library
 * Original Copyright (c) 2008 Lucas Ferreira (www.lucasferreira.com)
 *
 * Version: 0.5.1b
 */
 
/*
 * jquery-util-lite.js - JavaScript Library
 * Fork Copyright (c) 2008 Diego Rocha
 * Fork Version: 0.3.1b
 */
 
var defaultUrl = $.find('script')[0].src.toString().split("js/")[0];

$.fn.initValue = function(def){
	this.focus(function(){
		if($(this).val() == this.defaultValue){
			$(this).val('');
		}
	}).blur(function(){
		if(!$(this).val()) {
			$(this).val(this.defaultValue);
		}
	});
	return this;
};

/* fix menu hover */
$.fn.FixSFMenu = function(opened){

	var opened = (opened || false);
	
	if(opened){
		this.parent().find('li:nth-child('+opened+')').addClass('over')
	}
	
	this.find("li").hover(function(){
		$(this).addClass('over').parent().find('.over').not($(this)).removeClass('over');
	}, function(){
		if(!opened){
			$(this).removeClass('over');
		}
	}).each(function(){
		if($(this).find('ul').length > 0){//acessibilidade - tab
			$(this).find('a:first').focus(function(){
				$(this).parent().addClass('over');
			});
			$(this).find('a:last').blur(function(){
				$(this).parent().parent().parent().removeClass('over');
				$(this).parent().parent().removeClass('over');
			});
		}
	});
	return this;
};

//CSS position:fixed for ie6
$.fn.positionFix = function(e){
	if($.browser.msie && $.browser.version < '7.0'){
		var that = $(this);
		var thatTop = parseInt(that.css('top'));
		$(window).scroll(function(e){
			that.css({top:(document.documentElement.scrollTop || 0)+thatTop});
		});
		$(this).css({position: 'absolute'});
	}else{
		$(this).css({position: 'fixed'});
	}
	return this;
}
	
/* CakePHP Integration*/
function $cake(s){
	var s = s.split('_').join('.').split('.');
	for(var i=1; i<s.length; i++){
		s[i] = s[i].substr(0, 1).toUpperCase() + s[i].substr(1);
	}
	s = s.join('');
	return $('#'+s);
};

/* fake columns */
function equalColumns(param1,param2,adjust){
	var adjust = (adjust || 0);
	if(param1.outerHeight() > param2.outerHeight()){
		param2.height(param1.outerHeight()-param2.outerHeight()+param2.height()-adjust);
	}else if(param1.outerHeight() < param2.outerHeight()){
		param1.height(param2.outerHeight()-param1.outerHeight()+param1.height()+adjust);
	}
}

function pMail(obj){
	obj = obj.replace(/\[ponto\]/g,'.').replace(/\[arroba\]/g,'@');
	obj = obj.replace(/%5Bponto%5D/g,'.').replace(/%5Barroba%5D/g,'@');
	return obj;
}
