var winHeight = 0;
var winWidth = 0;
var processCentering = false;
var thisW = 600;
var thisH = 600;

function setOpacity(value,beg,end,type) {
    
    if (type == 1) { // Fade In
    	beg = beg + 1;
    } else if (type == 2) { // Fade Out
    	beg = beg - 1;
    }
    document.getElementById(value).style.opacity = beg/10;
    document.getElementById(value).style.filter = 'alpha(opacity=' + beg*10 + ')';
    if (type == 1) { // Fade In
    	if (beg >= end) {
    		return;
    	}
    } else if (type == 2) { // Fade Out
    	if (beg <= end) {
    		if (end == 0) {
    			document.getElementById(value).style.display = 'none';
    		}
    		return;
    	}
    }
    setTimeout("setOpacity('"+value+"',"+beg+","+end+","+type+");", 10);
}

function PullSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number') {
    // Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  winWidth = myWidth;
  winHeight = myHeight;
}

function SetCentered(value) {
    var offsetLeft = ((winWidth - thisW) / 2);
    var offsetTop = ((winHeight - thisH) / 2);
    //alert(winWidth+' - '+thisW+' '+offsetTop)
    document.getElementById(value).style.left = 0;
    document.getElementById(value).style.top = 0;
    document.getElementById(value).style.marginLeft = offsetLeft+'px';
    document.getElementById(value).style.marginTop = offsetTop+'px';
    if (processCentering) {
    	setTimeout("SetCentered('"+value+"')", 4000);
    }
}

function FadeBlackBoxIn() {
    processCentering = true;
    PullSize();
    document.getElementById('blackBlock').style.width = winWidth+'px';
    document.getElementById('blackBlock').style.height = winHeight+'px';
    setOpacity('blackBlock',1,7,1);
    document.getElementById('blackBlock').style.display = '';
    document.getElementById('flashcontent').style.display = '';
    SetCentered('flashcontent');
    setOpacity('flashcontent',1,10,1);
}

function FadeBlackBoxOut() {
    processCentering = false;
    Element.hide('blackBlock');
    Element.hide('flashcontent');
}

function ToggleBlackBox(w, h) {
	if (w != undefined) {
		thisW = w;
	}
	if (h != undefined) {
		thisH = h;	
	}
	document.getElementById('flashcontent').style.width = thisW+'px';
	document.getElementById('flashcontent').style.height = thisH+'px';
    if (document.getElementById('blackBlock').style.display == 'none') {
    	FadeBlackBoxIn();
    } else {
    	FadeBlackBoxOut();
    }
}

/*var handlerFuncNew = function(t) {
	document.getElementById('picText').innerHTML = t.responseText;
}

function GetBooking(uid,capid) {
	new Ajax.Request('/js/ajax/getBooking.ajax.php', {method:'post', postBody:'uid='+uid+'&&capid='+capid, onSuccess:handlerFuncNew});
}*/