// tcc.js

function openClientVideo() {
	set_scrim('page', 200, .9);
	
	$('#client_video_embed').css("top", (($('#client').outerHeight() - $('#client_video_embed').outerHeight()) / 2) + $('#client').position().top);
	$('#client_video_embed').css("left", (($('#client').outerWidth() - $('#client_video_embed').outerWidth()) / 2) + $('#client').position().left);
	$('#client_video_embed').show();
	$('body').prepend('<img id="video_close" src="img/video_close.gif"/>');
	$("#video_close").css("top", $('#client_video_embed').position().top - 48).css("left", $('#client_video_embed').position().left + $('#client_video_embed').outerWidth() - 80).click(close_video);
}

function close_video() {
	$('#client_video_embed').fadeOut("slow", function(){
		$("#video_close").remove();
		clear_scrim();
	});
}

function resizeText(className) {
	$("." + className).css("font-size", function(index) {
		var size = 15;
		var newsize;
		var chars = $(this).text().length;
		if (chars <= 25 ) newsize = size;
		else if (chars > 25 && chars <= 35) newsize = size - 1;
		else if (chars > 35 && chars <= 45) newsize = size - 2;
		else if (chars > 45 && chars <= 55) newsize = size - 3;
		else if (chars > 55 && chars <= 65) newsize = size - 4;
		else newsize = size - 5;
		return newsize + "px";
	});
}


function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function set_scrim(container_div_id, z, o) {
	//alert("set_scrim");
	if ( z == null ) z = 200;
	if ( o == null ) o = 0;
	var arrPageSizes = ___getPageSize();
	if ( o > 0 ) {
		$('select').css({ 'visibility' : 'hidden' });
	}
	$("#" + container_div_id).prepend('<div id="scrim_clear"></div>');
    
	$("#scrim_clear").css({
		backgroundColor:	"Black",
		opacity:			o,
		'z-index':			z,
		position:			"absolute",
		top:				"0px",
		left:				"0px",
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).show().click(function(){});
}

function clear_scrim() {
	$('select').css({ 'visibility' : 'visible' });
	$("#scrim_clear").remove();
}

function showdeadcenterdiv(Xwidth, Yheight, divid) {
    // First, determine how much the visitor has scrolled

    var scrolledX, scrolledY;
    if (self.pageYoffset) {
        scrolledX = self.pageXoffset;
        scrolledY = self.pageYoffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftoffset = scrolledX + (centerX - Xwidth) / 2;
    var topoffset = scrolledY + (centerY - Yheight) / 2;
    // The initial width and height of the div can be set in the
    // style sheet with display:none; divid is passed as an argument to // the function
    var o = document.getElementById(divid);
    var r = o.style;
    r.position = 'absolute';
    r.top = topoffset + 'px';
    r.left = leftoffset + 'px';

	$("#" + divid).css("z-index", "201").show();
} 
