// JavaScript Document
var AJAX_FILE='ajax/ajax_indealsoftgallery.php';
var image_index=0;
var images=null;

function IndealsoftGallery(repertoire)
{
	this.repertoire = repertoire;
	var value = $.ajax({ url: AJAX_FILE,type:'POST',data:{rep:repertoire},async:false}).responseText;
	images=null;
	image_index=0;
	eval(value);
	if(images!=null)
	{
		if(document.getElementById('headerflash'))
		document.getElementById('headerflash').style.display='none';
		var first = images[image_index];
		container = document.createElement('div');
		container.id='indealsoft_gallery_container';
		container.style.position='absolute';
		container.style.top='0px';
		container.style.left='0px';

		if(document.body.scrollHeight> window.innerHeight)
		container.style.height= getSize().height + (document.body.scrollHeight - window.innerHeight) +'px';
		else
		container.style.height= getSize().height  +'px';
		container.style.width=getSize().width+'px';	
		container.style.backgroundImage='url(js/background.png)';
		container.style.zIndex=10;
		
		innercontent = document.createElement('div');
		innercontent.id='indealsoft_gallery_innercontent';
		innercontent.style.position='absolute';
		innercontent.style.backgroundColor="#000000";
		innercontent.style.border='solid 3px #FFFFFF';
		innercontent.style.width=first.width+'px';
		innercontent.style.height=first.height+'px';		
		
		innercontent.style.left = ((Number(getSize().width) / 2) - (Number(first.width) / 2 ))+'px';	
		innercontent.style.top = ((Number(getSize().height) / 2) - (Number(first.height) / 2 ))+'px';
		
		waitcontent = document.createElement('div');
		waitcontent.id='indealsoft_gallery_innercontent_wait';
		waitcontent.style.position='absolute';
		waitcontent.style.backgroundColor="#000000";
		waitcontent.style.width=first.width+'px';
		waitcontent.style.height=first.height+'px';		
		waitcontent.innerHTML='<img src="js/gallery_wait.gif" style="margin-left:' + ((Number(first.width) / 2 )-7) + 'px;margin-top:' + ((Number(first.height) / 2 )-7) + 'px" />'
		waitcontent.style.left = '0px';	
		waitcontent.style.top = '0px';
		waitcontent.style.zIndex=100;
				
		
		innercontent.style.opacity='1';
		innercontent.style.zIndex=11;
		innercontent.innerHTML='<img id="gallery_image" src="' + first.file + '" tag="" width="' + first.width + '" height="' + first.height + '" />';
		
		innercontent.appendChild(waitcontent);
		
		footer = document.createElement('div');
		footer.id='indealsoft_gallery_footer';
		footer.style.position='absolute';
		footer.style.width=first.width+'px';
		footer.style.height='20px';
		footer.style.left = '-3px';	
		footer.style.bottom = '-29px';
		footer.style.backgroundColor="#FFFFFF";
		footer.style.border='solid 3px #FFFFFF';
		
		if(image_index==0)
		{
			footer.innerHTML='<table cellspacing="0" cellpadding="0" width="100%"><tr><td style="text-align:left;width:33%">&nbsp;</td><td style="text-align:center;width:33%"><a class="gallerylink" href="#" onclick="document.getElementById(\'headerflash\').style.display=\'\';document.body.removeChild(document.getElementById(\'indealsoft_gallery_container\'))">Fermer</a></td><td style="text-align:right;width:33%"><a class="gallerylink" href="#" onclick="nextImage('+ Number(Number(image_index)+1) +')">Suivant</a></td></tr></table>';
		}
		else if(image_index==images.length-1)
		{
			footer.innerHTML='<table cellspacing="0" cellpadding="0" width="100%"><tr><td style="text-align:left;width:33%"><a class="gallerylink" href="#" onclick="nextImage('+ Number(Number(image_index)-1) +')">Pr&eacute;c&eacute;dent</a></td><td style="text-align:center;width:33%"><a class="gallerylink" href="#" onclick="document.getElementById(\'headerflash\').style.display=\'\';document.body.removeChild(document.getElementById(\'indealsoft_gallery_container\'))">Fermer</a></td><td style="text-align:right;width:33%">&nbsp;</td></tr></table>';			
		}
		else
		{
			footer.innerHTML='<table cellspacing="0" cellpadding="0" width="100%"><tr><td style="text-align:left;width:33%"><a class="gallerylink" href="#" onclick="nextImage('+ Number(Number(image_index)-1) +')">Pr&eacute;c&eacute;dent</a></td><td style="text-align:center;width:33%"><a class="gallerylink" href="#" onclick="document.getElementById(\'headerflash\').style.display=\'\';document.body.removeChild(document.getElementById(\'indealsoft_gallery_container\'))">Fermer</a></td><td style="text-align:right;width:33%"><a class="gallerylink" href="#" onclick="nextImage('+ Number(Number(image_index)+1) +')">Suivant</a></td></tr></table>';
		}
		innercontent.appendChild(footer);
		
		container.appendChild(innercontent);

		document.body.appendChild(container);
		$('#gallery_image').load(ClearImage )		
	}
	return false;
}

function nextImage(index)
{
	image_index=index;
		
	var first = images[image_index];
	container = document.getElementById('indealsoft_gallery_container');
	if(document.body.scrollHeight> window.innerHeight)
		container.style.height= getSize().height + (document.body.scrollHeight - window.innerHeight) +'px';
	else
		container.style.height= getSize().height  +'px';
	container.style.width=getSize().width+'px';	
	
	innercontent = document.getElementById('indealsoft_gallery_innercontent');
	innercontent.style.width=first.width+'px';
	innercontent.style.height=first.height+'px';		
	
	waitcontent = document.createElement('div');
	waitcontent.id='indealsoft_gallery_innercontent_wait';
	waitcontent.style.position='absolute';
	waitcontent.style.backgroundColor="#000000";
	waitcontent.style.width=first.width+'px';
	waitcontent.style.height=first.height+'px';		
	waitcontent.innerHTML='<img src="js/gallery_wait.gif" style="margin-left:' + ((Number(first.width) / 2 )-7) + 'px;margin-top:' + ((Number(first.height) / 2 )-7) + 'px" />'
	waitcontent.style.left = '0px';	
	waitcontent.style.top = '0px';
	waitcontent.style.zIndex=100;
		
	innercontent.style.left = ((Number(getSize().width) / 2) - (Number(first.width) / 2 ))+'px';	
	innercontent.style.top = ((Number(getSize().height) / 2) - (Number(first.height) / 2 ))+'px';
	
	innercontent.innerHTML='<img id="gallery_image" src="' + first.file + '" tag="" width="' + first.width + '" height="' + first.height + '" />';
	innercontent.appendChild(waitcontent);
	
	footer = document.createElement('div');
	footer.id='indealsoft_gallery_footer';
	footer.style.position='absolute';
	footer.style.width=first.width+'px';
	footer.style.height='20px';
	footer.style.left = '-3px';	
	footer.style.bottom = '-29px';
	footer.style.backgroundColor="#FFFFFF";
	footer.style.border='solid 3px #FFFFFF';
		
	if(image_index==0)
	{
		footer.innerHTML='<table cellspacing="0" cellpadding="0" width="100%"><tr><td style="text-align:left;width:33%">&nbsp;</td><td style="text-align:center;width:33%"><a class="gallerylink" href="#" onclick="document.body.removeChild(document.getElementById(\'indealsoft_gallery_container\'))">Fermer</a></td><td style="text-align:right;width:33%"><a class="gallerylink" href="#" onclick="nextImage('+ Number(Number(image_index)+1) +')">Suivant</a></td></tr></table>';
	}
	else if(image_index==images.length-1)
	{
		footer.innerHTML='<table cellspacing="0" cellpadding="0" width="100%"><tr><td style="text-align:left;width:33%"><a class="gallerylink" href="#" onclick="nextImage('+ Number(Number(image_index)-1) +')">Pr&eacute;c&eacute;dent</a></td><td style="text-align:center;width:33%"><a class="gallerylink" href="#" onclick="document.body.removeChild(document.getElementById(\'indealsoft_gallery_container\'))">Fermer</a></td><td style="text-align:right;width:33%">&nbsp;</td></tr></table>';			
	}
	else
	{
		footer.innerHTML='<table cellspacing="0" cellpadding="0" width="100%"><tr><td style="text-align:left;width:33%"><a class="gallerylink" href="#" onclick="nextImage('+ Number(Number(image_index)-1) +')">Pr&eacute;c&eacute;dent</a></td><td style="text-align:center;width:33%"><a class="gallerylink" href="#" onclick="document.body.removeChild(document.getElementById(\'indealsoft_gallery_container\'))">Fermer</a></td><td style="text-align:right;width:33%"><a class="gallerylink" href="#" onclick="nextImage('+ Number(Number(image_index)+1) +')">Suivant</a></td></tr></table>';
	}
	innercontent.appendChild(footer);
	$('#gallery_image').load( ClearImage )		
}

function ClearImage()
{
	$("#indealsoft_gallery_innercontent_wait").fadeOut("slow",function() { document.getElementById('indealsoft_gallery_innercontent').removeChild(document.getElementById('indealsoft_gallery_innercontent_wait')); 	document.getElementById('gallery_image').style.display=''; } );

	

}

function getInner()
{
 var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
	return {width:viewportwidth,height:viewportheight}	;
}

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	return {width:myWidth,height:myHeight};
}
