/* dialog -------------------------------- dialog ------------------------------*/
function center_div (divid)
{	
    var div = document.getElementById (divid);
       
    var width  = div.offsetWidth;
    var height = div.offsetHeight;    

    var left  = (screenWidth()/2)-(width/2);
    var top   = (screenHeight()/2)-((height*1)/2);
    
    div.style.left = Math.round (left) + 'px';
    div.style.top = Math.round (top) + 'px'; 
}

function close_dialog ()
{	
    $('#dlgcontainer').remove();
    $('#overlay').remove();
    
    $('select').toggle();
    $('#flashHeader').toggle();
}

function opendialog_cb (request)
{    
    $('#dlg').fadeIn("slow");
    center_div ('dlg');    
}

function openoverlay (dlgid)
{	
    $('select').toggle();
    
    $('#flashHeader').toggle();
    
    $('#container').before ('<div id="dlgcontainer" style="z-index: 99;"></div><div id="overlay" class="overlay"></div>');
    
    overlaySize ();
    
    $('#dlgcontainer').load ('/services/itw_popup.php', {portfolio_id: dlgid}, opendialog_cb);
  
}

function overlaySize(){
  if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) {  
    yScroll = window.innerHeight + window.scrollMaxY;
    xScroll = window.innerWidth + window.scrollMaxX;
  } else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
    yScroll = document.body.scrollHeight;
    xScroll = document.body.scrollWidth;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    yScroll = document.body.offsetHeight;
    xScroll = document.body.offsetWidth;
    }
  //$("#overlay").css({"height":yScroll +"px", "width":xScroll +"px"});
  $("#overlay").css({"height":yScroll +"px"});
}

function screenHeight()
{
    if (self.innerHeight)
        return self.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
        return document.documentElement.clientHeight;
    else if (document.body)
        return document.body.clientHeight;
    else return;
}

function screenWidth()
{
    if (self.innerWidth)
        return self.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth)
        return document.documentElement.clientWidth;
    else if (document.body)
        return document.body.clientWidth;
    else return;
}


function prev_next_images(type, total)
{	
	var huidig = $('#tracker').val();
	huidig = Number(huidig);
	
	if (type == "prev")
	{
		if (huidig == 0)
		{
			var volgende = total - 1;
		}
		else
		{
			var volgende = huidig - 1;
		}
	}
	else
	{
		if (huidig == (total - 1))
		{
			var volgende = 0
		}
		else
		{
			var volgende = huidig + 1;
		}		
	}
	
	$('#tracker').val(volgende);

	$('#pf_images #'+huidig).hide();
	$('#pf_images #'+volgende).fadeIn("slow");
	
	
	$('#pf_teksten #t'+huidig).hide();
	$('#pf_teksten #t'+volgende).fadeIn("slow");
	
	
}