/* home.js */

Ext.onReady(function(){
    var aBoxes = ['left', 'middle', 'right'];
    var oTarget = null;
    var oHero = null;
    var oBox = null;
    var oLink = null;
    var sLink = null;

    function doMouseOver(evt, el, o){
        oTarget = Ext.get(el);
        if(oTarget){
            oBox = oTarget;
            if(oTarget.dom.tagName != 'DIV'){
                oBox = oTarget.parent();
            }
            oBox.addClass('hover');
        }
    }
    
    function doMouseOut(evt, el, o){
        oTarget = Ext.get(el);
        if(oTarget){
            oBox = oTarget;
            if(oTarget.dom.tagName != 'DIV'){
                oBox = oTarget.parent();
            }
            oBox.removeClass('hover');
        }
    }
    
    function doClick(evt, el, o){
        oTarget = Ext.get(el);
        if(oTarget){
            oLink = oTarget.child('a.read-more');
            if(oTarget.dom.tagName != 'DIV'){
                oLink = oTarget.parent().child('a.read-more');
            }
            if(oLink){
                sLink = oLink.dom.href;
                if(sLink){
                    location.href = sLink;
                }
            }else if(oTarget.dom.tagName.toLowerCase() == 'a'){
                location.href = oTarget.dom.href;
            }
        }
    }
    
    function init(){
        oHero = Ext.get('hero');
        if(oHero){
            oHero.setStyle('cursor', 'pointer');
            oHero.on('mouseover', doMouseOver, this);
            oHero.on('mouseout', doMouseOut, this);
            oHero.on('click', doClick, this, {
                scope: this
              , stopEvent: true
              , stopPropagation: true
            });
        }
        for(var i = 0; i < aBoxes.length; i++){
            oBox = Ext.get('home-box-' + aBoxes[i]);
            if(oBox){
                oBox.setStyle('cursor', 'pointer');
                oBox.on('mouseover', doMouseOver, this);
                oBox.on('mouseout', doMouseOut, this);
                oBox.on('click', doClick, this, {
                    scope: this
                  , stopEvent: true
                  , stopPropagation: true
                });
            }
        }
    }
    
    init();
});
