/**
 * Javascript Stylesheet Selector
 *
 */

var StyleSelector = function(){
    
    var debug        = false;
          
    var stylesheetEl   = null;
    var cutoffWidth    = null;
    var styleHrefSmall = null;
    var styleHrefLarge = null;
    
    var windowEl = null;
      
    var log = function(data, args){
        if(debug){
            console.log(data, args);
        }
    }
    
    return{
                
        setDebug: function(enable){
            debug = enable;
            log('setDebug', arguments);
        },
        
        log : function(message){
            log(message);
        },
        
        /**
         * init()
         * 
         * @param el jQuery object for stylesheet link element
         * @param w  Width of window for cutoff for switching stylesheets (in pixels)
         * @param s  Stylesheet href for when smaller than width cutoff
         * @param l  Stylesheet href for when larger than or equal to width cutoff
         */
        init : function(el, w, s, l){
            log('init', arguments);
            
            stylesheetEl   = el;
            cutoffWidth    = w;
            styleHrefSmall = s;
            styleHrefLarge = l;
            windowEl       = $(window);
            
            // add event listening on body resize
            windowEl.resize(function(){
                StyleSelector.refreshStyles();
				
            });
            
            // do the initial refresh
            StyleSelector.refreshStyles();
            
        },
        
        refreshStyles : function(){
            log('refreshStyles', arguments);
            
            try{
                // determine proper stylesheet based on window width
                if(windowEl.width() >= cutoffWidth){
                    newHref = styleHrefLarge;
                }else{
                    newHref = styleHrefSmall;
                }
                
                // change stylesheet
                stylesheetEl.attr('href', newHref);
				var objHeight=$(window).height() - 102;
				$('#WeAreFallonComponent').height(objHeight);
				
            }catch(err){
                log('error', err);
            }
        }
                
    }
}();
