// JAVASCRIPT FUNCTIONS - jQuery - 0.2
// © Jason Stockton 2009
// 23rd August 2009


// PHP STYLE ROUND
function round(val, precision) {
    return parseFloat(parseFloat(val).toFixed(precision));
}

// SET EMAIL EXP
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

// JQUERY PLUGIN
var jqsmooth = [];
jQuery.fn.extend({
	smooth: function(dir, pos, fcn) {
		var obj = this;
		pos = parseInt(pos);
		if(jqsmooth[obj+dir]) {
			clearTimeout(jqsmooth[obj+dir])
		}
		jQuery(this).js_goMoveToStep(obj, dir, pos, fcn);
	},
	js_goMoveToStep: function(obj, dir, pos, fcn) {
		var last = jQuery(obj).css(dir);
		last = parseInt(last);
		if(!last && last !=0) {
			switch (dir) {  
				case "left":
					last = jQuery(obj).css("left");
					break;
				case "top":
					last = jQuery(obj).css("top");
					break;
				case "width":
					last = jQuery(obj).width();
					break;
				case "height":
					last = jQuery(obj).height();
					break;
			}
		}
		if(last < pos) {
			var next = last + Math.ceil((pos - last) / 5);
		} else if(last > pos) {
			var next = last - Math.ceil((last - pos) / 5);
		}
		jQuery(obj).css(dir,next+"px");
		if(last != pos) {
			jqsmooth[obj+dir] = setTimeout(function() { jQuery(obj).js_goMoveToStep(obj, dir, pos, fcn); }, 20);
		} else {
			if(typeof fcn=='function'){
				fcn();
			}
		}
	}
});

// STRPOS
function strpos(haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}

// A HREF 
function ahref(url) {
	window.location = url;
}

// ANTI-CACHE URL
function anticache(url) {
	d = new Date();
	time = d.getTime();
	if(strpos(url, "?")) {
		url += "&anticache="+time;
	} else {
		url += "?anticache="+time;
	}
	return url;
}