
var baseURL = getBaseURL ( ); 

//var baseURL = "";
var baseTitle = document.title;


$( document ).ready ( function () {
		var labels = $('a') 
		var i = 0;
		for ( i = 0; i< labels.length ; ++i ){
			initFormToolTip.call ( labels [ i ] ); 
		};	
} );

function getBaseURL ( ) {
	var idxofurisep = document.location.href.indexOf ( "//" );
	var s = document.location.href.split ( "//" ) [ 0 ];
	var i = document.location.href.indexOf ( "/" , idxofurisep + 2 );
	s = s + document.location.href.slice ( idxofurisep , i ) + "/";
	return s;
}		
										
function doIt () {}

// Define corners and opposites arrays
var corners = [
   'bottomLeft', 'bottomRight', 'bottomMiddle',
      'topRight', 'topLeft', 'topMiddle',
         'leftMiddle', 'leftTop', 'leftBottom',
	    'rightMiddle', 'rightBottom', 'rightTop'
	    ];
var opposites = [
	       'topRight', 'topLeft', 'topMiddle',
	          'bottomLeft', 'bottomRight', 'bottomMiddle',
		     'rightMiddle', 'rightBottom', 'rightTop',
		        'leftMiddle', 'leftTop', 'leftBottom'
];

function getOpposite ( val ){
		for ( i = 0 ; i < corners.length && corners [ i ] != val ; ++i );
		if ( i > corners.length )
				return null;
		var r = opposites [ i ];
		//alert ( val + " / " + r );
		return r;
}

function isChildOf ( tagName , el ){
		var elements = $( el ).parents ( tagName );
		return  ( elements.length > 0);
}

function initFormToolTip ( ) {
	var toolTip = 'leftMiddle';
	var target = getOpposite ( toolTip );
        
	switch ( $(this).attr ('id') ){
		case "logol":
				toolTip = 'topMiddle';
				target = getOpposite ( toolTip );
		break;		
		case "logop":
				toolTip = 'topMiddle';
				target = getOpposite ( toolTip );
		break;
	}
		
    if ( isChildOf ( 'tfoot' , this) ) {
		toolTip = 'bottomMiddle';
		target = getOpposite ( toolTip );		
	}
	
	var className = $(this).attr ( 'class' );
	switch ( className ){
		case "tipOnLeft":
				toolTip = 'rightBottom';
				target = getOpposite ( toolTip );
		break;
		case "noToolTip":
						return;
				break;
		case "dropDownToolTip":
						toolTip = 'leftMiddle';
						target = getOpposite ( toolTip );
				break;
		return;
	}
	if($(this).data("qtip")) $(this).qtip("destroy");
	$(this).qtip({
		content: $(this).attr('alt'), // Set the tooltip content to the current corner
		position: {
			corner: {
			
			tooltip: toolTip, // Use the corner...
			target: target // ...and opposite corner

			}
		},
		show:  {
			ready: false, // Show the tooltip when ready
			when: {
				target: false,
				event: 'mouseover'
			}
		},
		style: {
			border: {
				width: 0
			},
			padding: 5, 
			background: '#D71574',
			color: '#ffffff',
			zIndex: 1000,
			margin: 5,
			textAlign: 'center',
			tip: true, // Give it a speech bubble tip with automatic corner detection
			name: 'light' // Style it according to the preset 'cream' style
		}
	});
	

}
	
function firstRunSplash ( ) {
	var toolTip = 'bottomMiddle';
	var target = getOpposite ( toolTip );
	
	
	$('#help').qtip({
			content: $('#help').attr ( 'name' ),
			position: {
					corner: {
					
					tooltip: toolTip, // Use the corner...
					target: target // ...and opposite corner
		
					}
			},
			show:  {
				ready: true
			},
			
			hide: {
					fixed: false,
					delay: 500,
					when: {
							target: false,
							event: 'unfocus'
					}
			},
			style: {
				border: {
					width: 0
				},
				padding: 5, 
				background: '#D71574',
				color: '#ffffff',
				margin: 5,
				textAlign: 'center',
				tip: true, // Give it a speech bubble tip with automatic corner detection
				name: 'light' // Style it according to the preset 'cream' style
			}
        })	
}


