/*
* JTip
* By Cody Lindley (http://www.codylindley.com)
* Under an Attribution, Share Alike License
* JTip is built on top of the very light weight jquery library.
*/
//on page load (as soon as its ready) call JT_init
jQuery(document).ready(JT_init);
function JT_init(){
jQuery("a.jTip")
.hover(function(e){
JT_show(this.href,this.id,this.name,this.rel, e)
},function(){
jQuery('#JT').remove()
})
.click(function(){
return false
});
}
function JT_show(url,linkId,title,contentDivId, event_object){
if(title == false)title=" ";
var de = document.documentElement;
var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
var linkIdLeft = getAbsoluteLeft(linkId);
var hasArea = w - linkIdLeft;
var clickElementy = getAbsoluteTop(linkId) +2; //set y position
var parentSelector = jQuery('#' + contentDivId).data('parent-selector');
var relativePlacement = false;
if (jQuery(parentSelector).html() === null) {
parentSelector = 'body';
} else if (jQuery('#' + contentDivId).data('relative-placement')) {
relativePlacement = true;
}
var queryString = url.replace(/^[^\?]+\??/,'');
var params = parseQuery( queryString );
if(params['width'] === undefined){
params['width'] = 250
};
if(params['link'] !== undefined){
jQuery('#' + linkId).bind('click',function(){
window.location = params['link']
});
jQuery('#' + linkId).css('cursor','pointer');
}
var orientation = 'right';
if(hasArea < (params['width']+75)){
if (hasArea < linkIdLeft) {
orientation = 'left';
if (params['width'] > linkIdLeft) {
params['width'] = linkIdLeft - 20;
}
} else {
params['width'] = hasArea - 60;
}
}
var clickElementx = 0;
if(orientation == 'right'){
jQuery(parentSelector).append("
"+title+"
");//right side
var arrowOffset = getElementWidth(linkId) + 8;
if (relativePlacement) {
clickElementx = jQuery(parentSelector).width() + 8;
clickElementy = jQuery(parentSelector).position().top;
} else {
clickElementx = linkIdLeft + arrowOffset; //set x position
}
}else if(orientation == 'left') {
jQuery(parentSelector).append("
"+title+"
");//left side
if (relativePlacement) {
clickElementx = -params['width'];
clickElementy = jQuery(parentSelector).position().top;
} else {
clickElementx = linkIdLeft - ((params['width']*1) + 12); //set x position
}
}
if (relativePlacement) {
jQuery('#JT').css({
'margin-left': clickElementx+"px",
'top': clickElementy+"px",
'z-index': "99999999999"
});
} else {
jQuery('#JT').css({
left: clickElementx+"px",
top: clickElementy+"px",
'z-index': "99999999999"
});
}
jQuery('#JT').show();
jQuery('#JT_copy').html(jQuery('#'+contentDivId).html());
if(jQuery('#JT').offset().top + jQuery('#JT').height() > jQuery(window).height() + jQuery(window).scrollTop()) {
if (relativePlacement) {
jQuery('#JT').css({top: (jQuery(window).height() + jQuery(window).scrollTop() - jQuery('#JT').offset().top - jQuery('#JT').height()) + "px"});
} else {
jQuery('#JT').css({
top: clickElementy + (jQuery(window).height() + jQuery(window).scrollTop() - jQuery('#JT').offset().top - jQuery('#JT').height()) +"px"});
}
if(orientation == 'right') {
jQuery('#JT_arrow_left').css({top: Math.abs(event_object.clientY - jQuery('#JT').offset().top + jQuery(window).scrollTop()) + "px"});
} else if(orientation == 'left') {
jQuery('#JT_arrow_right').css({top: Math.abs(event_object.clientY - jQuery('#JT').offset().top + jQuery(window).scrollTop()) + "px"});
}
} else {
if(orientation == 'right') {
jQuery('#JT_arrow_left').css({top: ""});
} else if(orientation == 'left') {
jQuery('#JT_arrow_right').css({top: ""});
}
}
//jQuery('#JT_copy').load(url);
// console.clear();
// console.log(
// 'element position top:'+jQuery('#JT').offset().top
// + "\n"
// + "element height: " + jQuery('#JT').height()
// + "\n"
// + "sum: " + (jQuery('#JT').offset().top + jQuery('#JT').height())
// + "\n"
// + "window height: " + jQuery(window).height()
// + "\n"
// + "window height scroll: " + jQuery(window).scrollTop()
// + "\n"
// + "sum: " + (jQuery(window).height() + jQuery(window).scrollTop())
// + "\n"
// );
}
function getElementWidth(objectId) {
x = document.getElementById(objectId);
return x.offsetWidth;
}
function getAbsoluteLeft(objectId) {
// Get an object left position from the upper left viewport corner
o = document.getElementById(objectId)
oLeft = o.offsetLeft // Get left position from the parent object
while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
oParent = o.offsetParent // Get parent object reference
oLeft += oParent.offsetLeft // Add parent left position
o = oParent
}
return oLeft
}
function getAbsoluteTop(objectId) {
// Get an object top position from the upper left viewport corner
o = document.getElementById(objectId)
oTop = o.offsetTop // Get top position from the parent object
while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
oParent = o.offsetParent // Get parent object reference
oTop += oParent.offsetTop // Add parent top position
o = oParent
}
return oTop
}
function parseQuery ( query ) {
var Params = new Object ();
if ( ! query ) return Params; // return empty object
var Pairs = query.split(/[;&]/);
for ( var i = 0; i < Pairs.length; i++ ) {
var KeyVal = Pairs[i].split('=');
if ( ! KeyVal || KeyVal.length != 2 ) continue;
var key = unescape( KeyVal[0] );
var val = unescape( KeyVal[1] );
val = val.replace(/\+/g, ' ');
Params[key] = val;
}
return Params;
}
function blockEvents(evt) {
if(evt.target){
evt.preventDefault();
}else{
evt.returnValue = false;
}
}