var ctuPopup_t=33;
var ctuPopup_step = 20;
var ctuPopup_op=100;
var ctuPopup_event;
var ctuPopup_w, ctuPopup_h;
var ctuPopup_cw, ctuPopup_ch;
var ctuPopup_zoomStep = 50;
var ctuPopup_url;
var photo_id = 1;
var nextPhoto_id = 2;
var no_of_photo = 4;
var photo_op=100;
var switchPhoto_t=50;
var switchphoto_event;
var rotatephoto_event;
var rotatePhoto_t=10000;
var photo_step=10;

function switchPhoto(){

    nextPhoto_id = photo_id + 1;
    if (nextPhoto_id > no_of_photo){ nextPhoto_id = 1;}
    photo_op=100;
    switchphoto_event = setTimeout('fadeOutPhoto()',switchPhoto_t);
    rotatephoto_event = setTimeout('switchPhoto()',rotatePhoto_t);

}

function switchToPhoto(id){

    clearTimeout(rotatephoto_event);
    if (id > 0 && id <= no_of_photo){
        nextPhoto_id = id;
    }
    else{
        nextPhoto_id = photo_id + 1;
        if (nextPhoto_id > no_of_photo){ nextPhoto_id = 1;}
    }
    photo_op=100;
    switchphoto_event = setTimeout('fadeOutPhoto()',switchPhoto_t);
    rotatephoto_event = setTimeout('switchPhoto()',rotatePhoto_t);

}

function fadeOutPhoto(){

    photo_op -= photo_step;
    if (photo_op < 0){ photo_op = 0;}
    setOpacity('photo'+photo_id, photo_op);
    if (photo_op > 0){
        switchphoto_event = setTimeout('fadeOutPhoto()',switchPhoto_t);
    }
    else{
/*        document.getElementById('photo'+photo_id).style.visibility='hidden';*/
        document.getElementById('photo'+photo_id).style.display='none';
        document.getElementById('navPhoto'+photo_id).className='navTabsItem';
/*        document.getElementById('photo'+photo_id).style.visibility='visible';*/
        photo_id = nextPhoto_id;
        setOpacity('photo'+photo_id, 0);
        document.getElementById('photo'+photo_id).style.display='block';
        document.getElementById('navPhoto'+photo_id).className='navTabsSelectedItem';
        switchphoto_event = setTimeout('fadeInPhoto()',switchPhoto_t);
    }

}

function fadeInPhoto(){

    photo_op += photo_step;
    if (photo_op > 100){ photo_op = 100;}
    setOpacity('photo'+photo_id, photo_op);
    if (photo_op < 100){
        switchphoto_event = setTimeout('fadeInPhoto()',switchPhoto_t);
    }
}

function setOpacity(pid, op){
    try{
        if (op==100){
            document.getElementById(pid).style.filter='none';
        }
        else{
            document.getElementById(pid).style.filter='alpha(opacity='+op+')';
        }
    }
    catch(e){
    }
    try{
    document.getElementById(pid).style.opacity=op/100;
    }
    catch(e){
    }
    try{
    document.getElementById(pid).style.MozOpacity=op/100;
    }
    catch(e){
    }
    try{
    document.getElementById(id).style.KhtmlOpacity=op/100;
    }
    catch(e){
    }
}

function closePopup(){
    document.getElementById('popupOverlay').style.display='none';
    ctuPopup_op=100;
    ctuPopup_event = setTimeout('fadeOutPopup()',ctuPopup_t);    
}

function fadeOutPopup(){

    ctuPopup_op -= ctuPopup_step;
    if (ctuPopup_op < 0){ ctuPopup_op = 0;}
    setOpacity('popupDiv', ctuPopup_op);
    if (ctuPopup_op > 0){
        ctuPopup_event = setTimeout('fadeOutPopup()',ctuPopup_t);
    }
    else{
        document.getElementById('popupContent').style.display='none';
        document.getElementById('popupContent').src='';
        document.getElementById('popupClose').style.display='none';
        document.getElementById('popupDiv').style.display='none';
        rotatephoto_event = setTimeout('switchPhoto()',rotatePhoto_t);
    }

}

function openPopup(url, width, height){
    var default_width = 660;
    var default_height = 500;
    var popup_left =130;
    var popup_top = 81;
    var myDivStyle = document.getElementById('popupDiv').style;
    var content_h = 617;
    if (width==null){ width=default_width;}
    if (height==null){ height=default_height;}
    clearTimeout(rotatephoto_event);
    document.getElementById('popupOverlay').style.cursor='wait';
/*    content_h = document.getElementById('topDiv').style.height + document.getElementById('midDiv').style.height + document.getElementById('gatway').style.height + document.getElementById('footer').style.height;*/
    if (document.documentElement.clientWidth > content_h){
        document.getElementById('popupOverlay').style.height=document.documentElement.clientHeight + 'px';
    }
    else{
        document.getElementById('popupOverlay').style.height= content_h + 'px';
    }
    document.getElementById('popupOverlay').style.display='block';
    /*document.getElementById('popupContent').style.display='none';*/
    /*document.getElementById('popupContent').src=url;*/
    ctuPopup_url = url;
    ctuPopup_op=100;
    setOpacity('popupDiv', ctuPopup_op);
    ctuPopup_w = width;
    ctuPopup_h = height;
    ctuPopup_cw = width - (ctuPopup_zoomStep * 8);
    ctuPopup_ch = height - (ctuPopup_zoomStep * 8);
    if (ctuPopup_ch < ctuPopup_zoomStep){ ctuPopup_ch = ctuPopup_zoomStep;}
    if (ctuPopup_cw < ctuPopup_zoomStep){ ctuPopup_cw = ctuPopup_zoomStep;}
    myDivStyle.width=ctuPopup_cw+'px';
    myDivStyle.height=ctuPopup_ch+'px';
    if (document.documentElement.clientWidth > 990){
        popup_left += Math.floor((document.documentElement.clientWidth - 990)/2);
    }
    if (popup_left + width > document.documentElement.clientWidth){popup_left=document.documentElement.clientWidth - width;}
    if (popup_left < 0){ popup_left=0;}
    if (popup_top + height > document.documentElement.clientHeight){popup_top=document.documentElement.clientHeight - height;}
    if (popup_top < 0){ popup_top=0;}
    myDivStyle.top=popup_top+'px';
    myDivStyle.left=popup_left+'px';
    myDivStyle.cursor='wait';
    myDivStyle.display='block';
    document.getElementById('popupClose').style.display='block';
    
    ctuPopup_event = setTimeout('zoomInPopup()',ctuPopup_t);
}

function zoomInPopup(){

    var myDivStyle = document.getElementById('popupDiv').style;
    ctuPopup_cw += ctuPopup_zoomStep;
    if (ctuPopup_cw > ctuPopup_w){ ctuPopup_cw = ctuPopup_w; }
    ctuPopup_ch += ctuPopup_zoomStep;
    if (ctuPopup_ch > ctuPopup_h){ ctuPopup_ch = ctuPopup_h; }
    myDivStyle.width=ctuPopup_cw+'px';
    myDivStyle.height=ctuPopup_ch+'px';

    if (ctuPopup_cw == ctuPopup_w && ctuPopup_ch == ctuPopup_h){
        myDivStyle.cursor='default';
        document.getElementById('popupOverlay').style.cursor='pointer';
        document.getElementById('popupContent').src=ctuPopup_url;
        document.getElementById('popupContent').style.display='block';
    }
    else{
        ctuPopup_event = setTimeout('zoomInPopup()',ctuPopup_t);
    }
}



