if (!("console" in window) || !("firebug" in console))
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}

function init() {
    function overCards(e) {
	    $$('.hover, li').each(function(item) {
	    	item.removeClassName('hover');
	    });
        if(!this.hasClassName('selected')) {
            this.addClassName('hover');
        }
        var pos = Position.cumulativeOffset(this);
        var leftPos = pos[0]+66;
        var topPos = pos[1]-25;
        var applyLink = this.getElementsByClassName('applyLink')[0];
        var learnLink = this.getElementsByClassName('learnLink')[0];
        
        var popupLearnLink = $('tooltip').getElementsByClassName('learnLink')[0];
        
        $('tooltip').getElementsByClassName('applyLink')[0].href = applyLink.href;
        popupLearnLink.href = learnLink.href;
        
        $('tooltip').setStyle({ top: topPos, left: leftPos });
        $('tooltip').show();
        var that = this;
        $('tooltip').observe('mouseout', outCards.bindAsEventListener(that), true);
        
        popupLearnLink.observe('click', popupLink.bindAsEventListener(popupLearnLink), true);
    }
    
    function popupLink(e) {
        e.stop();
        //Start:Modified for MSE MP270
        window.open(this.href, "LearnMore", "")
        //End:Modified for MSE MP270
    }
    
    function outCards(e) {
        var posTip = Position.cumulativeOffset($('tooltip'));
        var posEl = Position.cumulativeOffset(this);
		var that = this;
		var scrollOffset = document.viewport.getScrollOffsets();

        if(// check of mouse is over the area of the tooltip
            e.clientX+scrollOffset[0] <= posTip[0] ||
            e.clientX+scrollOffset[0] >= (posTip[0]+129) ||
            e.clientY+scrollOffset[1] <= posTip[1] ||
            e.clientY+scrollOffset[1] >= (posTip[1]+51) // 3 pixels taller seems to fix windows
        ) {
            $('tooltip').hide();
            that.removeClassName('hover');
            $('tooltip').stopObserving('mouseout');
        }
    }
    
    function clickCards(e) {
        this.check = this.getElementsByTagName('input')[0];
        if(this.hasClassName('selected')) {
            this.removeClassName('selected');
            this.check.checked = "";
        } else {
            this.addClassName('selected');
            this.check.checked = "checked";
        }
        console.log(this.check.checked);
    }
    
    $$('li.cardselect').each(function(card) {
        card.observe('mouseover', overCards.bindAsEventListener(card));
        card.observe('mouseout', outCards.bindAsEventListener(card));
        card.observe('click', clickCards.bindAsEventListener(card));
    });
    
    function selectAll(e) {
        Event.stop(e);
        $$('#comparisonForm ul input').each(function(input) {
            input.checked = 'checked';
        });
        $$('li.cardselect').each(function(card) { card.addClassName('selected') });
    }
    
    function clearAll(e) {
        Event.stop(e);
        $$('#comparisonForm ul input').each(function(input) {
            input.checked = '';
        });
        $$('li.cardselect').each(function(card) { card.removeClassName('selected') });
        $$('li.cardselect').each(function(card) { card.removeClassName('hover') });
    }
 
    $$('.selectAll')[0].observe('click', selectAll.bindAsEventListener());
    $$('.clearAll')[0].observe('click', clearAll.bindAsEventListener());
}

Event.observe(window, 'load', init);
