sIsPageCinema=true;
var sCinemaEditMode=false;
var sMaxZIndex=0;
var sCurrentHoveredId=0;
var sRQLog=false;
var sCineDetailsMargin=17;
var sShowTimeout=null;
var sPngExt=".png";
function RQLog(s)
{	
	var d
	if( d=$("#console"))
	{
		d.html( "<div>"+s+"</div>"+d.html())
	}
}
function InitCinema()
{

  // Fix PNGs in IE6
  if (navigator.appVersion.match(/MSIE [0-6]\./))
  {	sPngExt = ".gif";
    $('img').each(function () {
		if( this.src.match(/\.png$/))
			this.src= this.src.replace(new RegExp("(\.png)","g"), ".gif" );

    });
  }


	if( sCinemaEditMode)
	{	InitCinemaEdit();
	}
	else
	{
		// move all detail divs to the outside, to prevent further cropping problems
		//$("#carteDepartement .cineDetails").prependTo($(document.body));

		$(".cine").css({cursor:"pointer"}).mouseover(function()
		{	
			var id=$(this).attr('id');
			var dId="d"+id;
			var delayOver = 400;
			if(sRQLog)RQLog("OVER ("+id+")");

			if( sCurrentHoveredId && (sCurrentHoveredId!=dId ))
			{	
				hideCinema(sCurrentHoveredId);
				delayOver = 5;
			}
			if( !sCurrentHoveredId)
			{
				if( sShowTimeout) clearTimeout(sShowTimeout);
				var z = sMaxZIndex+1;
				var z1 = z+1;
				sMaxZIndex+=3;
				$(this).css("zIndex",z1);
				var o = $(this).offset();
				var y = sCineDetailsMargin+o.top;
				var x = o.left;
				$("#"+dId).css({left:x, top:y, zIndex:z})
				sShowTimeout = self.setTimeout("showCinema('"+dId+"');",delayOver);
				//showCinema(dId);
			}
		}).mouseout(function()
		{
			if(sRQLog)RQLog("OUT ("+$(this).attr("id")+")");

		});


		$(document).mousemove( function(e)
			{
				if( sCurrentHoveredId)
				{
					//var pageCoords = "( " + e.pageX + ", " + e.pageY + " )"; 
					var d = $("#"+sCurrentHoveredId);
					var o = d.offset();
					var x=e.pageX-o.left;
					var y=e.pageY-o.top;
					//if(sRQLog)RQLog( "xRel = "+x+" yRel="+y);
					if( x<0 || y<(0-sCineDetailsMargin) || x>(d.width()) || y> (d.height()) )
					{
						hideCinema(sCurrentHoveredId)
					}
					return false;
				}
			}
		);




		/*$(".cineDetails").mouseover(function()
		{	
		
			var id=$(this).attr("id");
			if(sRQLog)RQLog("Detail OVER ("+id+")");
			showCinema(id);

		}
		);

		$(".cineDetails").mouseout(function()
		{	
			if(sRQLog)RQLog("Detail OUT ("+$(this).attr("id")+")");
			hideCinema($(this).attr("id"));
		});*/


	}

}
function showCinema(id)
{
	sShowTimeout=null;
	sCurrentHoveredId = id;

	if(sRQLog)RQLog("showCinema("+id+") z="+$("#"+id).css("zIndex"));
	$("#"+id).fadeIn("fast");
	//$(this).css({width:$(this).width(), height:$(this).height()});

}
function hideCinema(id)
{
	sCurrentHoveredId=0;
	if(sRQLog)RQLog("hideCinema("+id+")");
	$("#"+id).fadeOut("fast");
	$("#"+id).css("zIndex",0);
}

