﻿var intervalID = -1;
var dy = 20;
var dt = 80;

var fontSize = 1.2;
var highlighted;

function changeFontSize(size){
    document.body.style.fontSize = new String(size + 'em');
    fontSize = size;
    setCookie('pctcfontSize',size,null);
    highlightFontSizeBtn(size);
}
function loadFontSizeCookie(){
    var size = getCookie('pctcfontSize');
    if (size!=null && !isNaN(size)){
        changeFontSize(Number(size));
    } else {
        changeFontSize(1.2);
    }
}

function fontSizeMouseOver(obj){
    if (obj != highlighted) { obj.src = obj.src.replace('.jpg','_on.jpg'); }
}

function fontSizeMouseOut(obj){
    if (obj != highlighted) { obj.src = obj.src.replace('_on.jpg','.jpg'); }
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return null;
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+";path=/"+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function resizeBanner(){
    var obj = document.getElementById('banner');
    if (obj.offsetHeight == 300){
        clearInterval(intervalID);
        startExpandBanner();
        //expandBannerFull();
    } else {
        clearInterval(intervalID);
        startShrinkBanner();
    }
}
function startExpandBanner(){
    intervalID = setInterval('expandBanner()',dt);
}
function expandBanner(){
    var obj = document.getElementById('banner');
    if (obj.offsetHeight < 500){
        obj.style.height = obj.offsetHeight + dy + 'px';
    } else {
        obj.style.height = '500px';
        clearInterval(intervalID);
    }
}
function startShrinkBanner(){
    intervalID = setInterval('shrinkBanner()',dt);
}
function shrinkBanner(){
    var obj = document.getElementById('banner');
    if (obj.offsetHeight > 300){
        obj.style.height = obj.offsetHeight - dy + 'px';
    } else {
        obj.style.height = '300px';
        clearInterval(intervalID);
    }
}
function expandBannerFull(){
    var obj = document.getElementById('banner');
    if (obj.offsetHeight < 500){
        obj.style.height = '500px';
    } else {
        obj.style.height = '500px';
        clearInterval(intervalID);
    }
}

function showGlossary(id,target){ 
    var obj = document.getElementById(id); 
    var pos = $(target).position();
    var wrp = $("#content_wrapper");
    var twidth = $(target).width();
    var theight = $(target).height();
    var owidth = $(obj).width();
    var oheight = $(obj).height();
    var offset = 5;
    if (wrp == null){
        $(obj).css( { "left": (pos.left) + "px", "top":(pos.top + theight + offset) + "px" } );
    } else {
        var wrpleft = $(wrp).position().left;
        if ((wrpleft + pos.left + owidth) > (wrpleft*2 + 1000)){
            $(obj).css( { "left": (wrpleft+1000-owidth) + "px", "top":(pos.top + theight + offset) + "px" } );
        } else {
            $(obj).css( { "left": (pos.left) + "px", "top":(pos.top + theight + offset) + "px" } );
        }
    }
    $(obj).show();
}
function hideGlossary(id){ 
    var obj = document.getElementById(id); 
    $(obj).hide();  
}
    
function loadSWF(id,swf,width,height){
	swfobject.embedSWF(swf, id, width, height, "9.0.0", "swf/expressInstall.swf");
	//var so = new SWFObject(swf, id, "100%", "100%", "9", "#ffffff");
    //so.useExpressInstall('swf/expressinstall.swf');
	//so.addParam("allowScriptAccess","sameDomain");
	//so.addParam("quality","high");
	//so.addParam("wmode","transparent");
	//so.addParam("allowmenu","false");
	//so.write(id);
}

function launchVideoWin(div, name) {
    $('<div id="' + name + '"/>').insertAfter(div + ' h3');
    popup_open($(div).get(), $('div#popup_mask').get(), 510, 340);
    loadSWF(name, '../swf/' + name + '.swf', 480, 290);
}
function closeVideoWin(div, name) {
    $(div + ' #' + name).remove();
    popup_close($(div).get(), $('div#popup_mask').get());

}
//----- POPUP -----//
function popup_open(divid, maskid, width, height) {
    //Get the screen height and width  
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    //Set height and width to mask to fill up the whole screen  
    $(maskid).css({ 'width': maskWidth, 'height': maskHeight });
    //transition effect
    $(maskid).fadeTo('fast', 0.8);
    //Get the window height and width  
    var winH = $(window).height();
    var winW = $(window).width();
    var docTop = $(document).scrollTop();
    //Set the popup window to center
    $(divid).fadeIn('fast');
    if (!isNaN(height))
        $(divid).css('top', winH / 2 - height / 2 + docTop);
    else
        $(divid).css('top', winH / 2 - $(divid).height() / 2 + docTop);
    if (!isNaN(width))
        $(divid).css('left', winW / 2 - width / 2);
    else
        $(divid).css('left', winW / 2 - $(divid).width() / 2);
    //transition effect
}
function popup_close(divid, maskid) {
    $(divid).hide();
    //fadeOut('fast');
    $(maskid).fadeOut('fast');
}    

/*
$(document).ready(function(){
    $('div#videotestimonial1').ready(function(){
        loadSWF('videotestimonial1','../swf/videotestimonial1.swf',480,290);
    });
    $('div#videotestimonial2').ready(function(){
        loadSWF('videotestimonial2','../swf/videotestimonial2.swf',480,290);
    });
    $('div#videotestimonial3').ready(function () {
        loadSWF('videotestimonial3', '../swf/videotestimonial3.swf', 480, 290);
    });
});
*/
