// change $ to jQuery so it works with Prototype
jQuery.noConflict();

// IMM 02.23.10: Custom tooltip function 
// Tooltip script 
// * powered by jQuery (http://www.jquery.com)
// * written by Alen Grakalic (http://cssglobe.com)
this.quicktip = function()
{	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		

	jQuery(".quicktip").hover(function(e)
	{
		this.t = this.title;
		this.title = "";									  
		jQuery("body").append("<p id='quicktip'>"+ this.t +"</p>");
		jQuery("#quicktip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast");		
    },
	function()
	{
		this.title = this.t;		
		jQuery("#quicktip").remove();
    });	
	
	jQuery(".quicktip").mousemove(function(e)
	{
		jQuery("#quicktip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


jQuery(document).ready(function()
{
	jQuery('ul#nav li.HasChildren').mouseover( function() 
	{ 
		jQuery(this).children('ul').css( 'left', jQuery(this).position().left + 10 ); 
		jQuery(this).children('ul').css('top', jQuery(this).position().top + 26 );
	});

	jQuery('ul#nav li.HasChildren').mouseout( function()
	{ 
		jQuery(this).children('ul').css('left', '-98765px'); 
		jQuery(this).children('ul').css('top', 'auto' );
	});

	jQuery('ul#nav li.HasChildren ul li a').mouseover( function()
	{
		jQuery(this).css('background-color','#fff');
		jQuery(this).children('a').css('color', '#5e6a14' );
	});

	jQuery('ul#nav li.HasChildren ul li a').mouseout( function()
	{
		jQuery(this).css('background-color','transparent');
		jQuery(this).children('a').css('color', '#fff' );
	});

	// IMM 02.23.10: Bind all '*' required asterisks with quicktip tooltip
	quicktip();

	// Setup header logo hover
	jQuery("strong.logo").hover( function()
	{
		jQuery(this).addClass("logo-over");
	},
	function()
	{
		jQuery(this).removeClass("logo-over");
	});
});

function initSSK()
{
	dNowTme = Math.ceil(new Date().getTime() / 1000);
	dBegTme = Math.ceil(dBegDte.getTime() / 1000);
	SecBeg = (dNowTme - dBegTme);
	//alert("NowTme=[" + dNowTme + "]\nBegTme=[" + dBegTme + "]\nSecBeg=[" + SecBeg + "]");
	nValue = addCommas(dBseVal + Math.ceil(((SecBeg / dSPC) * dIPC)));
	jQuery('span.sskilled').html(nValue);
	jQuery('span.sskilled').textShadow();
	setInterval( "updateSSK()", dIntVal );
}

function updateSSK()
{
	dNowTme = Math.ceil(new Date().getTime() / 1000);
	dBegTme = Math.ceil(dBegDte.getTime() / 1000);
	SecBeg = (dNowTme - dBegTme);
	nValue = addCommas(dBseVal + Math.ceil(((SecBeg / dSPC) * dIPC)));
	jQuery('span.sskilled').html(nValue);
}

function numeric_only( val )
{
	num = "";
	for (i = 0; i < val.length; i++ )
	{
		if ("0123456789".indexOf(val.substr(i,1)) > -1)
			num += val.substr(i,1);
	}
	return num;
}

function addCommas(val)
{
	val += '';
	x = val.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1))
	{
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

