/*
**	core js for pb_clients.php
**
**	Creates floating div for image enlargement on mouse hover
**
**	usage: any image with class 'floatIt' will automatically be included
**/

var ClientsDivIsShowing=false;	//Should floating div be showing?
var ClientsDivDelay=0;			//True delay since last mouse over

$(document).ready( function() //wait for page to be ready
{
	//insert floating div
	$("body").append('<div id="floatDiv" style="z-index:100;position:absolute;background:black;text-align: center;border:solid 2px white;width:143;display:block;color: white;"><a href="#" onClick="return false;"><img src="" border="0" alt="" height="90" width="143"></a><div style="width:143;"></div></div>');
	//tb_init("a.thickbox");  //add thick box support to link
	$("#floatDiv").hide();
    $(".floatIt").mouseover( //add mouse over events
       function () {
			$("#floatDiv div").hide();
			var objPos=$(this).position();  //center floating div over existing image
			$("#floatDiv").css('left',objPos.left-25);
			$("#floatDiv").css('top',objPos.top-15);
			$("#floatDiv img").attr('src',$(this).attr('src'));
			if(!ClientsDivIsShowing)
				$("#floatDiv").fadeIn();
			ClientsDivIsShowing=true;
			var d = new Date()
			ClientsDivDelay=d.getTime();
			$("#floatDiv div").attr('innerHTML',$(this).attr('name'))
			var clientID=$(this).attr('rel');
			if(clientID==0)
				$("#floatDiv a").css('cursor','default');
			else
				$("#floatDiv a").css('cursor','pointer');			
			$("#floatDiv a").attr('onClick','showClientDetails('+clientID+');return false;');
		});
	$("#floatDiv").mouseout( //add mouse out event
	       function () {
				ClientsDivIsShowing=false;
			});
	setTimeout('clientsFloatDivCheck();',100); //timer for hiding divs and showing client names
});

// checks div every .1 second
// hides floatDiv on mouseOut and shows client name after delay
function clientsFloatDivCheck(){
	var d = new Date()
	if(d.getTime()-ClientsDivDelay > 500){
		if(ClientsDivIsShowing){
			ClientsDivDelay=d.getTime();  //do avoid the animation triggering again before done
			$("#floatDiv div").slideDown();
		}else{
			$("#floatDiv div").slideUp();
			$("#floatDiv").fadeOut();
		}
	}
	setTimeout('clientsFloatDivCheck();',100);
}

function showClientDetails(clientID){
	if(clientID>0)
		tb_show('','pb_clientDetails.php?id='+clientID+'&height=410&width=775&modal=true','');
}