/* P H O T O - G A L L E R Y */					   
function $(id){
return document.getElementById(id);
}
function STO(func,time){
return window.setTimeout(func,time);
}
function openModal(sUrl,oArguments,w,h){
  var width= w || '320px';
  var height= h || '300px' 																							
  var r = window.showModalDialog(sUrl,oArguments, "dialogwidth: "+width+"; dialogheight: "+height+"; resizable: yes");
  return r;
}
function DecToHexa(dec){
var hex=parseInt(dec).toString(16);
if(dec<16){
hex="0"+hex;
}
return hex;
}
function getHeight(id){
var	height=$(id).clientHeight;
	if(height==0){height=$(id).offsetHeight;}
	return height;
}
function getWidth(id){
var	width=$(id).clientWidth;
	if(width==0){width=$(id).offsetWidth;}
	return width;
}
	  
function resizeImage(id,width,height){
var maxW = width || 100;
var maxH = height || 100;
var w = getWidth(id);
var h = getHeight(id);
var ratio=w/h;	 
	maxW = Math.min(w,maxW);
	maxH = Math.min(h,maxH);
	newW = maxW;
	newH = Math.round(maxW/ratio);
	if (newH>newW){
		newH = maxH;
		newW = Math.round(newH * ratio);
	}
	var obj = $(id).style;
	obj.width = newW;
	obj.height = newH;  
	return [newW,newH];
}
function opacity(id,Start,End,Delay){
var speed = Math.round(Delay/100);
var timer = 0;
	if (Start>End){	for(var i = Start; i>=End; i--){STO("changeOpacity("+i+",'"+id+"')",timer-speed);timer++;}
	} else if (Start<End){for(var i = Start; i>=End; i++){STO("changeOpacity("+i+",'"+id+"')",timer-speed);timer++;}}
}

function changeOpacity(opacity,id){					 
var obj = $(id).style;   
	obj.opacity = (opacity/100);
	obj.MozOpacity = (opacity/100);
	obj.KhtmlOpacity = (opacity/100);
	obj.filter = "alpha(opacity="+opacity+")";	 
}

function fadeout(id){
var timer = 0;
var speed = 50;																						
	for(var i = 100; i>=0; i--){STO("changeOpacity("+i+",'"+id+"')",timer+speed);timer=timer+10;}	
	return timer;
}							
function setDimension(id,width,height){
	if ($(id)) {
		$(id).style.width = width;
		$(id).style.height = height;  
	}
}
function changePicture(id,file,text,url){
	if ($(id)) {
		$(id+"image").src = file;	
		$(id+"image").title=text;
		$(id+"link").href=url;
		$(id+"link").alt=text;
	/*$(id).style.width = width;
	$(id).style.height = height;  
	resizeImage(id,100,100);*/
	}
}
function fadein(id){
var timer = 0;
var speed = 50;																						
	for(var i = 10; i<=100; i++){STO("changeOpacity("+i+",'"+id+"')",timer+speed);timer=timer+10;}
	return timer;
}	   
function transaction(id,file,text,url,width,height){
var timer = 0;
var speed = 50;																						

	if ($(id)){
		timer = fadeout(id);
		STO("changePicture('"+id+"','"+file+"','"+text+"','"+url+"')",timer+10);
		timer=timer+5;
		for(var i = 1; i<=100; i++){STO("changeOpacity("+i+",'"+id+"')",timer+speed);timer=timer+10;}
		return timer;
	}
}
function rotate(photoGallery){
var gap;
 //photoGallery=photoGallery1;	 					  
	if (photoGallery.listPicture){
		if (photoGallery.index==photoGallery.listPicture.length){photoGallery.index=0;}
		indice = (photoGallery.index++)%photoGallery.listPicture.length;
		gap = transaction(photoGallery.id,photoGallery.listPicture[indice].file,photoGallery.listPicture[indice].text,photoGallery.listPicture[indice].link,photoGallery.listPicture[indice].width,photoGallery.listPicture[indice].height);
		gap = gap +  parseInt(photoGallery.listPicture[indice].duration);
		//window.status =getWidth(photoGallery.id+"image")+" - "+getHeight(photoGallery.id+"image")+' - '+indice;
		setTimeout(function(){rotate(photoGallery)},gap);
	}											
}

