// Returns viewport dimensions.
//
//
function getViewportDims() {
    var viewportDims = {};
    // The more standards compliant browsers (mozilla/netscape/opera/IE7) use
    // window.innerWidth and window.innerHeight:
    if (typeof window.innerWidth != 'undefined') {
        viewportDims.width = window.innerWidth,
        viewportDims.height = 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) {
        viewportDims.width = document.documentElement.clientWidth,
        viewportDims.height = document.documentElement.clientHeight
    } else {
        // Older versions of IE:
        viewportDims.width = document.getElementsByTagName('body')[0].clientWidth,
        viewportDims.height = document.getElementsByTagName('body')[0].clientHeight
    }
    return viewportDims;
}

// Listens to mouseover #header, sets opacity for #nav_bar a.menu_items.
//
//
function headerListen() {
    jQuery(function() {
        jQuery('#header').mouseover(function() {
            if (jQuery.support.opacity) {
                jQuery('#nav_bar a.menu_item').css('opacity', '1.0');
                jQuery('#nav_bar_admin a.menu_item').css('opacity', '1.0');
            } else {
                jQuery('#nav_bar a.menu_item').css('filter', 'alpha(opacity=100)');
                jQuery('#nav_bar_admin a.menu_item').css('filter', 'alpha(opacity=100)');
            }
        });
        jQuery('#header').mouseout(function() {
            if (jQuery.support.opacity) {
                jQuery('#nav_bar a.menu_item').css('opacity', '.4');
                jQuery('#nav_bar_admin a.menu_item').css('opacity', '.4');
                jQuery('#nav_bar a.menu_item.home, #nav_bar a.menu_item.web, #nav_bar a.menu_item.print, #nav_bar a.menu_item.apps, #nav_bar a.menu_item.my_projects, #nav_bar a.menu_item.about, #nav_bar a.menu_item.contact').css('opacity', '1.0');
                jQuery('#nav_bar a.menu_item.labs, #nav_bar a.menu_item.domains, #nav_bar a.menu_item.clients, #nav_bar a.menu_item.users' ).css('opacity', '1.0');
            } else {
                jQuery('#nav_bar a.menu_item').css('filter', 'alpha(opacity=40)');
                jQuery('#nav_bar_admin a.menu_item').css('filter', 'alpha(opacity=40)');
                jQuery('#nav_bar a.menu_item.home, #nav_bar a.menu_item.web, #nav_bar a.menu_item.print, #nav_bar a.menu_item.apps, #nav_bar a.menu_item.my_projects, #nav_bar a.menu_item.about, #nav_bar a.menu_item.contact').css('filter', 'alpha(opacity=100)');
                jQuery('#nav_bar a.menu_item.labs, #nav_bar a.menu_item.domains, #nav_bar a.menu_item.clients, #nav_bar a.menu_item.users').css('filter', 'alpha(opacity=100)');
            }
        });
    });
}

// Listens to table, adds hover class to rows and columns.
// Dependent upon JQuery.
//
function tableListen() {
    // When the dom is ready:
    jQuery(function() {
        var i = 0;
        jQuery("colgroup").each(function() {
            i++;
            jQuery(this).attr("id", "col"+i);
        });
        var totalCols = i;
        i = 1;
        jQuery("td").each(function() {
            jQuery(this).attr("rel", "col"+i);
            i++;
            if (i > totalCols) { i = 1; }
        });
        jQuery("td").hover(function() {
            jQuery(this).parent().addClass("hover");
            // Uncomment if we want col hilighting:
            // var curCol = jQuery(this).attr("rel");
            // jQuery("#"+curCol).addClass("hover");
        }, function() {
            jQuery(this).parent().removeClass("hover");
            // Uncomment if we want col hilighting:
            // var curCol = jQuery(this).attr("rel");
            // jQuery("#"+curCol).removeClass("hover");
        });
    });
}

// Main pages effects - opacity for text_cols and img_row_cells, tag div for
// img_row_cells.
//
function setImgRowsMouseOut() {
    if (jQuery.support.opacity) {
        //jQuery('#text_cols .text_col').css('opacity', '1.0'); 
    } else {
        //IE does really poorly with opacity, esp. with the sifr, so
        //we're not changing opacity of this area.
        //jQuery('#text_cols .text_col').css('filter', 'alpha(opacity=100)');
    }
}
function setImgRowsMouseOver() {
    if (jQuery.support.opacity) {
        //jQuery('#text_cols .text_col').css('opacity', '.4');
    } else {
        //IE does really poorly with opacity, esp. with the sifr, so
        //we're not changing opacity of this area.
        //jQuery('#text_cols .text_col').css('filter', 'alpha(opacity=30)');
    }
}
function setImgCellsMouseOut(divId) {
    tagId = '#tag' + divId;
    divId = '#' + divId;
    if (jQuery.support.opacity) {
        jQuery(divId).css('opacity', '.5');
    } else {
        jQuery(divId).css('filter', 'alpha(opacity=50)');
    }
    jQuery(tagId).hide();
}
function setImgCellsMouseOver(divId) {
    tagId = '#tag' + divId;
    divId = '#' + divId;
    if (jQuery.support.opacity) {
        jQuery(divId).css('opacity', '1.0');
    } else {
        jQuery(divId).css('filter', 'alpha(opacity=100)');
    }
    jQuery(tagId).fadeIn(1500).show().fadeOut(4000);
}

// Set anchor style for current presentation_panel navigation item
// and adds function to anchor's click event.
//
//
function setScrollTo() {
    jQuery(function() {
        // Does nothing:
        // setTimeout("vCenterImage('centered', 1)", 1);
        // Get all link with class panel:
        // jQuery("a.panel").click(function () {
        jQuery("#presentation_panel a.panel").click(function () {
            // IE chokes on
            // item = jQuery(this).attr('href');
            // but works with the following implementation:        
            jQuery(this.parentNode).hide();
            jQuery('a.panel').removeClass('selected');
            jQuery(this).addClass('selected');
            jQuery('#sliding_wrapper').scrollTo(jQuery(this).attr('href'), 1000);		
            jQuery("#panel_nav_" + jQuery(this).attr('href').replace("#","")).show();
            // Cancel the link default behavior:
            return false;
        });
    });
}

// Centers image vertically.
//
//
function vCenterImage(which, i) {
    var which2 = which+i;
    if (document.getElementById(which2)) {
        document.getElementById(which2).style.marginTop = Math.floor( (document.getElementById(which2).parentNode.offsetHeight - document.images[which2].height) / 2 ) + 'px';
        var newi = i + 1; vCenterImage(which, newi);
    }
}

// Set reflection for the Unidada logo.
// Unidada hello logo set similarly in contact_panel.ctp.
//
function setReflection() {
    jQuery('#logo_bar img').reflect({height: 0.4, opacity: 0.1});
}

