// JavaScript Document

// prikazi div u sredini teksta ili ga vrati
var cTime= setTimeout("",0);
var loopCount=0;
var scrollPos=0;
var backupImg="";
var countSwap=0;
function alerter(){alert("cao");}

// Meni funkcije
function ulOpen(ul)
{
	var status=document.getElementById(ul).style.display;
	if ((status=="none") || (status=="") ) document.getElementById(ul).style.display="block";
	else document.getElementById(ul).style.display="none";

}

// end Meni funkcije ----------------------------------- end Meni ----------------------
function showMe(gImg)
{

   var myImage=document.getElementById(gImg).src;
   document.getElementById(gImg).src=document.getElementById('prImg').src.replace("images","Thumbs");
   document.getElementById('prImg').src=myImage.replace("Thumbs","images");
}

function confDiv(divId){
	//IE Mozilla 
	if (document.body.clientWidth || document.body.clientHeight) {
		document.getElementById(divId).style.width = document.body.clientWidth+'px';
		document.getElementById(divId).style.height = document.body.clientHeight+'px';
		//alert('width:' + document.body.clientWidth + ' height:' + document.body.clientHeight);
	}
	else {
		if (window.innerWidth || window.innerHeight) {
			document.getElementById(divId).style.width = window.innerWidth;
			document.getElementById(divId).style.height = window.innerHeight;
			//alert('width:' + window.innerWidth + ' height:' + window.innerHeight);
		}
		//return (width,height);
	}
}

function resizeNew(){ 
var frame = findObj("frame1"); 
var htmlheight = document.body.parentNode.scrollHeight; 
var windowheight = window.innerHeight; 
if ( htmlheight < windowheight ) { document.body.style.height = windowheight + "px"; frame.style.height = windowheight + "px"; } 
else { document.body.style.height = htmlheight + "px"; frame.style.height = htmlheight + "px"; } 
} 
function timeout(time){
	setTimeout('timeout("time")',time);
}
function doMove(width, divId) {
   
   // proveriti vrednost da li je stigao do 600
   while (loopCount <= (width / 2)){
   	 document.getElementById(divId).style.width=(width/2)+loopCount+'px';
   document.getElementById(divId).style.height=(width/2)+loopCount+'px';
   loopCount+=10;
  
  if (loopCount <= (width / 2)) 
  	setTimeout(doMove(width, divId), 250); // call doMove in 20msec
  }	
}
function resize(divId)
{
	document.getElementById(divId).style.visibility = 'visible';
	width=400; height=400;
	//alert (divId);
	doMove(width,divId);
	
}
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    changeOpac(0, id)
    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 
function shiftOpacity(id, millisec,opType,opMin,opMax) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(opType="up") { 
        opacity(id, opMin, opMax, millisec); 
    }  
	else { 
        opacity(id, opMax, opMin, millisec); 
    } 
} 
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_scrollTop(){
	scrollPos= f_filterResults(window.pageYOffset ? window.pageYOffset : 0, document.documentElement ? document.documentElement.scrollTop : 0, document.body ? document.body.scrollTop : 0);
	return scrollPos;
}
function f_scrollSet(scrollPos){
	//Cekiraj prva dva
	//window.pageYOffset=scrollPos;
	//document.documentElement.scrollTop=scrollPos;
	document.body.scrollTop=scrollPos;
}
function showDiv(divId)
{
   
	document.getElementById('present').style.top = 10+f_scrollTop()+'px';
	
	document.getElementById('shadow').style.visibility = 'visible';
	//confDiv('shadow');
	document.getElementById('present').style.visibility = 'visible';
	//shiftOpacity(id, millisec,opType,opMin,opMax)
	//shiftOpacity('shadow', 1000,'up',0,50);
	//shiftOpacity('present', 1000,'up',0,100);
	//resize('present');
	//alert (document.getElementById("tdNaz0").innerHTML);
	document.getElementById('nazivTd').innerHTML=document.getElementById("tdNaz"+divId).innerHTML;
	document.getElementById('navTd').innerHTML="<a class='nav' id='close' href=javascript:hideDiv('"+divId+"') >X</a><br/>";
	document.getElementById('dataTd').innerHTML=document.getElementById('tb'+divId).innerHTML;
	
	document.getElementById('gTd').innerHTML=document.getElementById('im'+divId).innerHTML;
	document.getElementById('prImg').src=document.getElementById('img'+divId.toString()).src.replace("Thumbs","images");
    document.getElementById('left').href="javascript:showDiv('"+(parseInt(divId)-1)+"')";
	document.getElementById('right').href="javascript:showDiv('"+(parseInt(divId)+1)+"')";
	//f_scrollSet(scrollPos);
}

function hideDiv(divId)
{
	// make visible
	//alert("Cao radi skoro");
	countSwap=0;
	// return image;
	
	document.getElementById('present').style.visibility = 'hidden';
	document.getElementById('shadow').style.visibility = 'hidden';
}