﻿var photoPage = '';
var emptyStr = '_empty_'

function setPhotoPage(page){
    photoPage = page;
}

function openPhoto(photoId){
    window.open(photoPage + "photoId=" + photoId,"photo","width=400,height=400,menubar=no,scroolbars=yes,statusbar=no,toolbar=no,status=yes,resizable=no");		
	return false;
}

function setPhoto(index){
    if(objPhotos[index].src.indexOf(emptyStr)>-1){objPhotos[index].src = photos[index];}
    var photo = document.getElementById('photo');
    photo.src = objPhotos[index].src;
   
         
    setPhotoCaption(index);
    loadPhotoPreviours(index);
    loadPhotoNext(index);
    loadPhotoDisplay(index);
    return false;
}

function setPhotoCaption(index){
    var strip = document.getElementById("pStrip");
    var lt = document.getElementById("ltCaption");
	var caption = captions[index];
	
	if(caption!="undefined" && caption.length>0){
		lt.innerHTML = caption;
		strip.style.visibility='visible';
	}else{
	    lt.innerHTML = '';
		strip.style.visibility='hidden';
	}
}

function loadPhotoPreviours(index){
	var lk = document.getElementById("btPreviours");

	if(index > 0){
		var i = (index - 1)
		lk.onclick = function(){return setPhoto(i);};
		if(objPhotos[i].src.indexOf(emptyStr)>-1){
			objPhotos[i].src = photos[i];
		}
	}else{
		lk.onclick = function(){return false;};
	}
}

function loadPhotoNext(index){
	var lk = document.getElementById("btNext");
	if(index < (objPhotos.length - 1)){
		var i = (index + 1)
		lk.onclick = function(){return setPhoto(i);};
		
		if(objPhotos[i].src.indexOf(emptyStr)>-1){
			objPhotos[i].src = photos[i];
		}
	}else{
		lk.onclick = function(){return false;};
	}
}

function loadPhotoDisplay(index){
    var lt = document.getElementById('display');
    lt.innerHTML = (index+1) + " / " + photos.length;
}

function resizePhotoWin()
{
    var obj = document.getElementById("photoWin");
	var w = obj.clientWidth;
	var h = obj.clientHeight;
	
	window.resizeTo(w,h);
	
	var diff_w = w - getDocWidth();
	var diff_h = h - getDocHeight();
	
	window.resizeTo((w + diff_w),(h + diff_h));
	
	self.focus();
	centralize();
	
	 if(navigator.appName=="Opera"){
        var photo = document.getElementById('photo');
        photo.style.display="inline";
    }
	 
}




function centralize(){
	var w = 0;
	var h = 0;
	
	if(navigator.appName=='Microsoft Internet Explorer'){
		h = document.documentElement.offsetHeight;
		w = document.documentElement.offsetWidth;
    }else{
		h = window.innerHeight;
		w = window.innerWidth;
    }
	
	
	var y = window.screen.availHeight;
	var x = window.screen.availWidth;
	
	if(w > x & h > y){
		window.moveTo(0,0);
		return false;
	}
	
	if(w > x){
		window.moveTo((x/2)-(w/2),0);
		return false;
	}
	
	if(h > y){
		window.moveTo(0,(y/2)-(h/2));
		return false;
	}
	
	window.moveTo((x/2)-(w/2),(y/2)-(h/2));
}



function getDocHeight()
{
    if(navigator.appName=='Microsoft Internet Explorer'){
       return document.documentElement.offsetHeight; 
    }
    
    return window.innerHeight;
}

function getDocWidth()
{
    if(navigator.appName=='Microsoft Internet Explorer'){
       return document.documentElement.offsetWidth; 
    }
    
    return window.innerWidth;
}

function isRadioSelected(groupName)
{
var objs = document.getElementsByName(groupName);
    for(i=0;i<objs.length;i++){
        if(objs[i].checked==true){
            return true;
        }
    }
return false;
}

function conditionMessage(msg,condition){
    if(condition==true){
        alert(msg);
    }
}


