/**
 * Plugins for entire website activity
 *
 * @author		Gimi
 * @copyright	2009 MyGOV 1.0
 * @version		1.0
 * @since		2009.10.26
 */

/**
 * ViewPort Object - get the width / height / scroll infromation
 *
 * @param  string width - the viewPort width
 * @param  string height - the viewPort height
 * @param  string vScroll - the viewPort scroll
 */
viewPort = {
	offset : 20,
	width : $(window).width(),
	height : $(window).height(),
	vScroll : $(document).scrollTop(),
	hScroll : $(document).scrollLeft()
};


/**
 * Display div on page
 *
 * @param  string sDivID - the div ID that should be displayed
 * @return void
 */
function showDiv(sDivID, varEsc) {
	if (varEsc == null || varEsc === 'undefined') {
		varEsc = true;
	}
	
	$("#" + sDivID).overlay({ 
		top : 100,
	 	
	    expose: {
	        color: '#000',
	        loadSpeed: 100,
	        opacity: 0.5
	    },
	    
	    closeOnEsc: varEsc,
	    closeOnClick: false,
	    oneInstance: false, 
	    api: true
	}).load();
}


/**
 * Close div
 *
 * @param  string sDivID - the div ID that should be closed
 * @return void
 */
function hideDiv(sDivID) {
	$('#' + sDivID).overlay().close();
}


/**
 * Check the existing of a value in JS object
 *
 * @param  	string val - the object value
 * @param	object oObj - the object used to find
 * @return 	void
 */
function inObj(val, oObj) {
	for (i in oObj) {
		if (i == val) {
			return 1;
		}
	}
	
	return 0;
}


// tiny tip for help desk
function addTinyTip(title, width, position) {
	var offset = 20;
	var width = width || 100;
	var position = position || 'left';
	var div_html = '<div id="tooltip_subject" style="position:absolute; display:none; z-index:10000; top:0px; left:0px;">'+
					'<table align="center" width="'+ width +'" style="padding:5px" border="0" cellpadding="0" cellspacing="0">'+
					'<tr><td style="padding:8px; border:1px solid #999; background:#FFF; line-height:19px; text-align:center;">'+ title +'</td></tr></table></div>' + "\n";
				
	$(div_html).appendTo('body');
	
	$(this).mousemove(function(e) {
		var X = e.pageX;
        var Y = e.pageY;
        var posX = X - (width - offset);
        var posY = Y + offset;
        
        if (position == 'right') {
        	posX = X - 5;
        }
        
        $('#tooltip_subject').css({'top': posY+'px', 'left': posX+'px'});
        $('#tooltip_subject').show();
	});
}
function removeTinyTip() {
	if ($('#tooltip_subject').length > 0) {
		$('#tooltip_subject').hide();
		$('#tooltip_subject').remove();
	}

}
