/*
@author Sam <kinsamqiu (at) gmail.com
@blog http://pebbly.cc/Sam
*/


function tips(content){       
	$('body').prepend('<span id="tips" class="fix" style="display:none;">' + content + '</span>');	
	$('#tips').slideToggle(300, function(){
		setTimeout(function(){
			$('#tips').slideToggle(function(){
				$('#tips').remove();
			});
		},1700)
	});
	$('#tips').click(function(){
		$(this).slideToggle(function(){
			$(this).remove();
		})
	});
}

function loadjs(url, callback, charset){
    var script = document.createElement('script');
    script.onload = script.onreadystatechange = function(){
        if (script && script.readyState && /^(?!(?:loaded|complete)$)/.test(script.readyState)) return;
        script.onload = script.onreadystatechange = null;
        script.src = '';
        script.parentNode.removeChild(script);
        script = null;
        callback();
    };
    script.charset=charset || document.charset || document.characterSet;
    script.src = url;
    try{
		document.getElementsByTagName('head')[0].appendChild(script);
	}catch (e){}
}

var sweetTitles = {
	x : 10,
	y : 20,
	tipElements : 'a',
	init : function() {
		$(this.tipElements).mouseover(function(e){
			this.myTitle = this.title;
			this.myHref = this.href;
			this.myHref = (this.myHref.length > 30 ? this.myHref.toString().substring(0,30)+'...' : this.myHref);
			this.title = '';
			var tooltip = '<div id="tooltip"><p>'+this.myTitle+'</p></div>';
                        if(this.myTitle.length > 0){
                                    $('body').append(tooltip);
                                    $('#tooltip')
                                    .css({
                                    "opacity":"0.8",
                                    "top":(e.pageY+20)+"px",
                                    "left":(e.pageX+10)+"px"
                                }).show('fast');
                            }
		}).mouseout(function(){
			this.title = this.myTitle;
			$('#tooltip').remove();
		}).mousemove(function(e){
			$('#tooltip')
			.css({
				"top":(e.pageY+20)+"px",
				"left":(e.pageX+10)+"px"
			});
		});
	}
};

$(function(){
	sweetTitles.init(); 
})

