/* Popup window browse gallery */
var width = 1200;
var height = 1200;
var viewportwidth = 1200;
var viewportheight = 1200;
var index=0;
var xScroll=0;
var yScroll=0;
var links= new Array();
var jobtitles = new Array();
var bodyPadding = "";
var bodyMargin = "";
var isOpen = false;
var ie_version = getInternetExplorerVersion();

function getViewport(){
    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;
    } 
}

function setwrapsize(){
    document.getElementById('body').style.overflow = 'hidden'; 
    getViewport();
    document.getElementById('bodywrap').style.height = viewportheight+'px';
    document.getElementById('bodywrap').style.width = viewportwidth+'px';
    if(document.getElementById("greybox").style.height){
        document.getElementById("greybox").style.height = viewportheight + 'px';
        document.getElementById("greybox").style.width = viewportwidth + 'px';
    }
    loaded(); 
}


function adjustPosition(){
    var cord_y=(navigator.appName=='Microsoft Internet Explorer')?document.body.scrollTop:window.pageYOffset;
    document.getElementById("greybox").style.top=cord_y;
}

function show(url,i){
    getViewport();
    if(i > -1){
		index = i;
		getIndex();
	}
	width=0;
    document.getElementById("bodywrap").style.overflow = 'hidden';
	frames["inframe"].document.getElementById('navigate_buttons').style.display = 'block';
    loading();

    frames["inframe"].frames["inframe"].location.href=url;
    xScroll=(navigator.appName=='Microsoft Internet Explorer')?document.body.scrollLeft:self.pageXOffset;
    yScroll=(navigator.appName=='Microsoft Internet Explorer')?document.body.scrollTop:self.offsetHeight;  
    document.getElementById("greybox").style.top=yScroll;
    document.getElementById("greybox").style.left=xScroll; 
    document.getElementById("greybox").borderStyle="hidden";
    animate_open();

    window.frames["inframe"].frames["inframe"].focus();

}

function show_one(url,title){
    loading();
    document.getElementById("bodywrap").style.overflow = 'hidden';
	frames["inframe"].document.getElementById('greybox_jobtitle').innerHTML = title;
	frames["inframe"].document.getElementById('navigate_buttons').style.display = 'none';
    frames["inframe"].frames["inframe"].location.href=url;
    document.getElementById("greybox").style.top=yScroll;
    document.getElementById("greybox").style.left=xScroll; 
    document.getElementById("greybox").borderStyle="hidden";
    animate_open();
    window.frames["inframe"].frames["inframe"].focus();
}

function close(){
    width=100;
    document.getElementById("bodywrap").style.overflow= "auto";
    animate_close();
    window.scrollTo(xScroll,yScroll);
}

function animate_open(){
    width=0;
    showIndex();
	showJobTitle();
    isOpen = true;
    document.getElementById("greybox").style.visibility='visible';
    document.getElementById("greybox").style.display='block';
    document.getElementById("greybox").style.width = viewportwidth+'px';
    document.getElementById("greybox").style.height = viewportheight+'px';
    bodyPadding = document.getElementById("body").style.padding;
	bodyMargin = document.getElementById("body").style.margin;
	document.getElementById("body").style.padding = "0px";
    document.getElementById("body").style.margin = "0px";	
}

function animate_close(){
    width=0;
    isOpen = false;
    document.getElementById("greybox").style.width="0px";
    document.getElementById("greybox").style.height="0px";
    document.getElementById("greybox").style.top="0px";
    document.getElementById("greybox").style.left="0px";
    document.getElementById("greybox").style.visibility='hidden';
    document.getElementById("greybox").style.display='none';
    document.getElementById("body").style.padding = bodyPadding;
    document.getElementById("body").style.margin = bodyMargin;	
    adjustPosition();
}

function next(){
    index++;
    loading();
    getjob();
    showIndex();
	showJobTitle();
}

function back(){
    index--;
    loading();
    getjob();
    showIndex();
	showJobTitle();
}

function getjob(){
    if(isOpen)
        frames["inframe"].frames["inframe"].location.href=links[getIndex()];
}

function getIndex(){
    index=(index>links.length-1)?0:index;
    index=(index<0)?links.length-1:index;
    return index;
}

function showIndex(){
    if(isOpen || typeof( frames["inframe"].document.getElementById('indexlabel')) != 'undefined' )
        frames["inframe"].document.getElementById('indexlabel').innerHTML = (index+1)+"/"+links.length;
}

function showJobTitle(title){
    if(isOpen){
        if(typeof(title) != 'undefined'){
            frames["inframe"].document.getElementById('greybox_jobtitle').innerHTML = title;
        }else{
            frames["inframe"].document.getElementById('greybox_jobtitle').innerHTML = document.getElementById('displayedjobtitle_'+index).innerHTML;
        }
    }
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function loaded(){
    frames["inframe"].document.getElementById('loader').style.display = 'none';
    frames["inframe"].document.getElementById('inframecontent').style.display = 'block';
    if(ie_version > -1 && ie_version < 7) {
        var w = viewportwidth * 0.69;
        var h = viewportheight * 0.80;
        document.getElementById('inframe').style.width = w+'px';
        document.getElementById('inframe').style.height = h+'px';
        w-=10;
        frames["inframe"].document.getElementById('inframecontent').style.width = w+'px';
        h-=40;
        frames["inframe"].document.getElementById('inframecontent').style.height = h+'px';
    }
}

function loading(){
    frames["inframe"].document.getElementById('inframecontent').style.display = 'none';
    frames["inframe"].document.getElementById('loader').style.display = 'block';
}

