jq15 = jQuery.noConflict(true);


jQuery(document).ready(function() {
    var $ = jQuery;
    if(window.location.href == 'http://www.easyturf.com/') {
        // Input Masker
        $('input,textarea,password').each(function() {
            if(1) {
                if($(this).attr('type') == 'password') {
                    // We can't clone password inputs, so we have to make new ones and just copy classes & style
                    var maskElm = document.createElement('input');
                    maskElm.className = this.className;
                    maskElm.type = 'text';
                } else {
                    var maskElm = $(this).clone().attr({name:''});
                }
                for(var styleKey in this.style) {
                    if(typeof maskElm.style !== 'undefined' && typeof maskElm.style.__lookupSetter__ == 'function' && maskElm.style.__lookupSetter__(styleKey)) {
                        maskElm.style[styleKey] = this.style[styleKey];
                    }
                }
                $(maskElm).data('orginalElm',this).addClass('input_mask').val($(this).attr('value')).focus(function() {
                    $(this).toggle();
                    $($(this).data('orginalElm')).toggle().focus();
                }).insertAfter(this);
                if($(this).val() == 'Zip Code' || $(this).val() == 'Yard Size') {
                    $(this).css('width',110);
                    $(maskElm).css('width',110);
                }
                $(this).data('maskElm',maskElm).val('').blur(function() {
                    if(!$(this).val().length) {
                        $(this).toggle();
                        $($(this).data('maskElm')).toggle();
                    }
                });
                $(this).hide();
            }
        });
    }
});

var ui = {
    savings: {
        settings: {
            water: {
                per: 600 * 2500000, // saved in a year (fields * gallons)
                offset: 23990000000, 
                savings_class: "water",
                savings_title: "Water Savings",
                savings_unit: "Gallons saved YTD",
                savings_dec: 1000000000,
                savings_total: " billion"        
            }, 
            pesticides: {
                per: 15000000, // saved in a year
                offset: 120000000, 
                savings_class: "pesticides",
                savings_title: "Pesticide Prevention",
                savings_unit: "Pounds saved<br>this year-to-date",
                savings_dec: 1000000,
                savings_total: " million pounds saved since 1996"        
            }, 
            carbon: {
                per: 600 * 792 * 2.2, // saved in a year (fields * kgs * kg/lb)
                offset: 7600032 * 2.2, // 16715700
                savings_class: "carbon",
                savings_title: "Carbon Emissions",
                savings_unit: "Pounds saved<br>this year-to-date",
                savings_dec: 1000000,
                savings_total: " million pounds saved since 1996"        
            }, 
            tires: {
                per: 12000000, // saved in a year 
                offset: 60000000,
                savings_class: "tires",
                savings_title: "Recycled Tires",
                savings_unit: "Tires recycled<br>this year-to-date",
                savings_dec: 1000000,
                savings_total: " million tires recycled since 1996"        
            }
        },
        init: function(){
            jq15("#savings-water").click(function(){ ui.savings.show("water"); return false; });
            jq15("#savings-pesticides").click(function(){ ui.savings.show("pesticides"); return false; });
            jq15("#savings-carbon").click(function(){ ui.savings.show("carbon"); return false; });
            jq15("#savings-tires").click(function(){ ui.savings.show("tires"); return false; });    
            this.show("water");
        },
        show: function(what){
            
            // wipe away the old
            clearInterval(ui.savings.updater);
            jq15("#savings").attr("class","");
            
            // get the right data
            var obj;                
            switch(what){
                case "water": obj = ui.savings.settings.water; break;
                case "pesticides": obj = ui.savings.settings.pesticides; break;
                case "carbon": obj = ui.savings.settings.carbon; break;
                case "tires": obj = t = ui.savings.settings.tires; break;        
            }
            
            // write in the basics
            jq15("#savings").addClass(obj.savings_class);
            jq15("#savings-title").html(obj.savings_title);
            jq15("#savings-year-unit").html(obj.savings_unit);
                    
            // get current date in seconds
            var now = new Date().getTime();
            now = now / 1000;
            
            // determine reference points: beginning of this year and the base year that works with the offset number
            var this_year = new Date();
            this_year = this_year.getFullYear(); 
            this_year = new Date(this_year,0,1); // start of this year, ET
            base_year = new Date(2009,0,1); // start of 2009, used for totals, ET
            // this_year = new Date(Date.UTC(this_year,'01','01','00','00','00')); // start of this year, ET
            // base_year = new Date(Date.UTC('2009','01','01','00','00','00')); // start of 2009, used for totals, ET
            var seconds_since_new_year = now - (this_year.getTime()/1000);
            var seconds_since_base_year = now - (base_year.getTime()/1000); 
    
            // this will update once a second
            var _update = function(){
                var seconds = 365 * 24 * 60 * 60;
                var yearly_amount = Math.round(++seconds_since_new_year * obj.per / seconds);
                var base_amount = Math.round(++seconds_since_base_year * obj.per / seconds);
                var total_amount = Number((base_amount + obj.offset) / obj.savings_dec);            
                var _commas = function(nStr){
                    nStr += '';
                    x = nStr.split('.');
                    x1 = x[0];
                    x2 = x.length > 1 ? '.' + x[1] : '';
                    var rgx = /(\d+)(\d{3})/;
                    while (rgx.test(x1)) {
                        x1 = x1.replace(rgx, '$1' + ',' + '$2');
                    }
                    return x1 + x2;
                }            
                jq15("#savings-year-value").html(_commas(yearly_amount));
                jq15("#savings-total").html(_commas(total_amount.toFixed(2)) + obj.savings_total);
            }
            _update();
            ui.savings.updater = setInterval(function(){_update();},1000);
            ui.equallize("#spot-2, #spot-3, #spot-4, #spot-5");    
        },
        updater: null
    },
    equallize: function(id){
        var equal_height = 0;
        jq15(id).each(function(){
            jq15(this).css("height","auto");
            var this_height = jq15(this).outerHeight();
            if(this_height > equal_height){
                equal_height = this_height;
            }
        });
        jq15(id).each(function(){
            var offset = jq15(this).outerHeight() - jq15(this).height();
            var new_height = equal_height - offset;
            jq15(this).css("height",new_height);
        });
    }
    
};



function stylechange(path){
     
         if(path=="OutdoorImage"){
              document.getElementById('pawan').style.backgroundImage = 'url("http://et.publishpath.com/Websites/et/templates/NorthernLight/images/outdoor-living.jpg")';
    //alert('OutdoorImage');     
         }
         if(path=="FamilyImage"){
              document.getElementById('pawan').style.backgroundImage = 'url("http://et.publishpath.com/Websites/et/templates/NorthernLight/images/family-grass.jpg")';
           //alert('FamilyImage');     
         }
         if(path=="PetImage"){
             document.getElementById('pawan').style.backgroundImage = 'url("http://et.publishpath.com/Websites/et/templates/NorthernLight/images/pet-friendly.jpg")';
  
        
         }
         if(path=="GreenImage"){
              document.getElementById('pawan').style.backgroundImage = 'url("http://et.publishpath.com/Websites/et/templates/NorthernLight/images/putting-greens.jpg")';
              
         }
          /*if(path==""){
              document.getElementById('').style.backgroundImage = 'url("http://et.publishpath.com/Websites/et/templates/NorthernLight/images/header_bg.jpg)';
              
         }*/
    }

