/* EQUALIZE COLUMNS
-------------------------------------------------------------- */

// these are (ruh-roh) globals. You could wrap in an
// immediately-Invoked Function Expression (IIFE) if you wanted to...
var currentTallest = 0,
    currentRowStart = 0,
    rowDivs = new Array();

function setConformingHeight(el, newHeight) {
        // set the height to something new, but remember the original height in case things change
        el.data("originalHeight", (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight")));
        el.height(newHeight);
}

function getOriginalHeight(el) {
        // if the height has changed, send the originalHeight
        return (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight"));
}

function columnConform() {

        // find the tallest DIV in the row, and set the heights of all of the DIVs to match it.
        $('.equalize').each(function() {
        
                // "caching"
                var $el = $(this);
                
                var topPosition = $el.position().top;

                if (currentRowStart != topPosition) {

                        // we just came to a new row.  Set all the heights on the completed row
                        for(currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);

                        // set the variables for the new row
                        rowDivs.length = 0; // empty the array
                        currentRowStart = topPosition;
                        currentTallest = getOriginalHeight($el);
                        rowDivs.push($el);

                } else {

                        // another div on the current row.  Add it to the list and check if it's taller
                        rowDivs.push($el);
                        currentTallest = (currentTallest < getOriginalHeight($el)) ? (getOriginalHeight($el)) : (currentTallest);

                }
                // do the last row
                for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);

        });

}


// DOM Ready
// ------------------------------------------------------------- |
$(function(){

	// Tab Slide Out
	// ------------------------------------------------------------- |
	$('.slide-out-div').tabSlideOut({
		tabHandle: '.handle',                     //class of the element that will become your tab
		pathToTabImage: '/wp-content/themes/carbon60/images/livechat_tab.png', //path to the image for the tab //Optionally can be set using css
		imageHeight: '101px',                     //height of tab image           //Optionally can be set using css
		imageWidth: '35px',                       //width of tab image            //Optionally can be set using css
		tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
		speed: 500,                               //speed of animation
		action: 'click',                          //options: 'click' or 'hover', action to trigger animation
		topPos: '200px',                          //position from the top/ use if tabLocation is left or right
		leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
		fixedPosition: true                       //options: true makes it stick(fixed position) on scroll
	});
	
	/* EQUALIZE COLUMNS
	-------------------------------------------------------------- */
	columnConform();


});
