/* Start pagination */
var troisPre = false;
var troisPost = false;
var troisPoint = false;

var pageBlockExecTime = new Array();
	
swapPageBlock = function(id,action){
	switch(id){
	
		case "pre":
			var box = "ctnPgnRight";
			if ($(box))
				$(box).style.visibility = 'hidden';				
			var box = "ctnPgnLeft";
			troisPoint=troisPre;
			if ( (action == 'over') && ($(box).style.visibility == 'visible') )	
				return;			
			break;
		
		case "post":
			var box = "ctnPgnLeft";
			if ($(box))
				$(box).style.visibility = 'hidden';
			var box = "ctnPgnRight";			
			troisPoint=troisPost;
			if ( (action == 'over') && ($(box).style.visibility == 'visible') )	
				return;				
			break;
		
		default:
		return;
		break;
		
	}
	
	if ( ($(box).style.visibility == 'visible') ){
		if ( troisPoint == false)
			$(box).style.visibility = 'hidden';
								
	
		
	}else{
	
		pageBlockExecTime[id] = Math.random(1,999);
		pageBlockExecTimeLocal = pageBlockExecTime[id];
		
		$(box).style.visibility = 'visible';
					
		setTimeout('if( ( troisPoint == false)&&("' + pageBlockExecTimeLocal + '"==pageBlockExecTime["' + id + '"]) ){ $("' + box + '").style.visibility = \'hidden\';  }', 2000); 
		
	}
	
};

awakePageBlock = function(id, idle){
	if( idle == undefined)
		idle = 1000;
	switch(id){
	
		case "pre":
			var box = "ctnPgnLeft";
			troisPoint=troisPre;
			break;
		
		case "post":
			var box = "ctnPgnRight";	
			troisPoint=troisPost;		
			break;
		
		default:
			return;
			break;
		
	}
	
		pageBlockExecTime[id] = Math.random(1,999);
		pageBlockExecTimeLocal = pageBlockExecTime[id];
	
	$(box).style.display = 'block';
			
	setTimeout('if( (troisPoint == false ) && ("' + pageBlockExecTimeLocal + '"==pageBlockExecTime["' + id + '"]) ){ $("' + box + '").style.visibility = \'hidden\';  }', idle); 
};
/* End pagination */

/*
 * Utility functions
 */
function checkEnter(e) {
	
	var characterCode;

	if (e.which || e.keyCode) {
		if ((e.which == 13) || (e.keyCode == 13)) {
			return true;
		}
	} 
	return false;
}
function refreshKey(){
	var x = Math.random();
	document.getElementById('keyImage').src = "/include/accessKey/"+x;
}
function selectUnselectAll(){
	if ($('all').checked) {
		check(true);
	}
	else {
		check(false);
	}
}
   
function check(param){
	$$('.checkboxSingle').each(function(obj) {
		obj.checked = param;		
	});
}

function emptyDiv(elemId) {
	$(elemId).innerHTML = "";
	$(elemId).style.display = "none";
}

/* Open url in a tab or new standard window */
function pop(url){		
	
	try{
		if(url==undefined){
			return false;
		}
	}catch(e){ 
		return false;
	}
	
	// Firefox2 (open popup in tabs)
	if(navigator.userAgent != null && navigator.userAgent.indexOf( "Firefox/" ) != -1   && navigator.userAgent.indexOf( "Firefox/1" ) == -1){
	
		var nnwin = window.open(url,'mywin' + Math.random(1000));

	} else {
		
		// All other traditional
		var nnwin = window.open(url,'mywin' + Math.round(Math.random(1000)*1000)); 
		nnwin.blur();
		
	}
	
	return false;
}
/* End of utility functions */

/*
 * Slide show TGPs pictures to preview video
 * Mathieu Imbert
 */
var videoPreviewArray = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");
var arrayIdx = 0;
var previewStarted = false;
var videoPreviewInterval;
var videoRestartTimeout;
var currentImageObject = '';
var currentVnumImage = '';

function initVideoPreview(imgOb, vnum) {
	
	if (previewStarted == false) {
		arrayIdx = 0;
		currentImageObject = imgOb;
		currentVnumImage = vnum;
		
		// show first image as soon as mouseover occur
		newUrl = "http://rpcache.rpcache.com/images/"+currentVnumImage+"/crop/165x124/nt/"+videoPreviewArray[arrayIdx]+".jpg";
		currentImageObject.setAttribute("src",newUrl);
		
		previewStarted = true;
		videoPreviewInterval = setInterval("previewVideo()", 700);
	}
}

function previewVideo() {
	
	arrayIdx = (arrayIdx + 1) % videoPreviewArray.length;
		
	newUrl = "http://rpcache.rpcache.com/images/"+currentVnumImage+"/crop/165x124/nt/"+videoPreviewArray[arrayIdx]+".jpg";
	currentImageObject.setAttribute("src",newUrl);
		
	if (arrayIdx == videoPreviewArray.length - 1) {
		clearInterval(videoPreviewInterval);
		previewStarted = false;
		videoRestartTimeout = setTimeout("initVideoPreview(currentImageObject, '"+currentVnumImage+"')", 700*3);
	}
}

function stopVideoPreview() {

	clearTimeout(videoRestartTimeout);
	clearInterval(videoPreviewInterval);
	currentImageObject.setAttribute("src","http://rpcache.rpcache.com/images/"+currentVnumImage+"/presentation/165x124/nt/1.jpg");
	currentVnumImage = "";
	previewStarted = false;
}
/* End video preview */

/* Method for popup under current window (once per page) */
var popupDisplayed = false;
function popunder(url){
	if (popupDisplayed == false) {
		var nnwin = window.open(url,'mywin' + Math.round(Math.random(1000)*1000),'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1'); 
		nnwin.blur();
		popupDisplayed = true;
	}
}
/* End of popup method */

/* correctly handle PNG transparency in Win IE 5.5 & 6 */
function correctPNG() // 
{
   var arVersion = navigator.appVersion.split("MSIE");
   var version = parseFloat(arVersion[1]);
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i];
         var imgName = img.src.toUpperCase();
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : "";
            var imgClass = (img.className) ? "class='" + img.className + "' " : "";
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
            var imgStyle = "display:inline-block;" + img.style.cssText;
            if (img.align == "left") imgStyle = "float:left;" + imgStyle;
            if (img.align == "right") imgStyle = "float:right;" + imgStyle;
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
            var strNewHTML = "<span " + imgID + imgClass + imgTitle;
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";";
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader";
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
            img.outerHTML = strNewHTML;
            i = i-1;
         }
      }
   }    
}