var theme1_dyk=new Array(4);
theme1_dyk[0]="Large turbines have propellers spanning more than the length of a football field, stand 20 stories high, and can power 700 homes.";
theme1_dyk[1]="A home-sized turbine has rotors between eight and 25 feet, and stands upwards of 40-feet.";
theme1_dyk[2]="Wind resources are characterized by wind-power density classes: Class 1 (lowest) to Class 7 (highest).";
theme1_dyk[3]="Indiana has wind-power density Class ratings of 1, 2 &amp; 3.";

var theme2_dyk=new Array(1);
theme2_dyk[0]="There are two different approaches to generating electricity from the sun: using the sun's light or using the sun's heat.";

var theme3_dyk=new Array(3);
theme3_dyk[0]="Animal waste can be converted to clean, renewable electricity.";
theme3_dyk[1]="Indiana-based Fair Oaks Farms, a large dairy farm operation, uses anaerobic digesters to treat manure and generate electricity for its own operations.";
theme3_dyk[2]="An average 3,500-cow dairy can generate enough electricity to power 750 homes.";

var theme4_dyk=new Array(4);
theme4_dyk[0]="Look for the Energy Star label when purchasing new appliances.";
theme4_dyk[1]="CFL bulbs use 25% of the energy of their equivalent incandescent bulbs.";
theme4_dyk[2]="Sealing your home's air leaks can increase the efficiency of heating and cooling equipment.";
theme4_dyk[3]="When planning to build a new home, consult a HERS Rater for ways to be sure you're using energy efficiently.";

var theme5_dyk=new Array(3);
theme5_dyk[0]="Everyone working together can help to reduce the daily demand for electricity.";
theme5_dyk[1]="Seal and insulate your home! The air leaks in an average American home are equivalent to a three-foot hole in an outside wall.";
theme5_dyk[2]="Be ENERGY SMART - know how your home uses Energy: HVAC = 50%, Water heater = 20%, Refrigerator = 15%, Lights &amp; other = 15%.";

var theme6_dyk=new Array(4);
theme6_dyk[0]="The methane gas that builds up under landfills can be used to create electricity.";
theme6_dyk[1]="Landfill gas is created when organic materials, like food wastes, paper and yard clippings, decompose inside the landfill.";
theme6_dyk[2]="Methane emissions, which have 23 times the negative environmental impact of CO2, can be captured and converted into electricity.";
theme6_dyk[3]="Our landfill gas plants generate, on average, enough electricity to power nearly 2,100 homes.";

var fact_counter = 0;

var theme_titles=new Array(6);
theme_titles[0]="Wind = Power";
theme_titles[1]="Sun = Power";
theme_titles[2]="Cows = Power";
theme_titles[3]="Efficiency = Power";
theme_titles[4]="People = Power";
theme_titles[5]="Trash = Power";

var rand_no = Math.ceil(6*Math.random());
var src = "wp-content/themes/indiana/include/styles/images/bg-home-"+rand_no+".jpg";
$('body.home').css('backgroundImage','url(' + src +')');
$('#dyk-fact').html(eval('theme'+rand_no+'_dyk[0]'));
$('#current-theme').html(eval('theme_titles['+(rand_no-1)+']'));

/*if($.cookie("body-bg")) {
    var src = "wp-content/themes/indiana/include/styles/images/bg-home-"+$.cookie("body-bg")+".jpg";
    $('body.home').css('backgroundImage','url(' + src +')');
    $('#dyk-fact').html(eval('theme'+$.cookie("body-bg")+'_dyk[0]'));
    $('#current-theme').html($.cookie("current-theme"));    
}*/

$(document).ready(function() {

    $(".post-thoughts .text").focus(function() {
        $(this).css({'border-color' : '#7b8090', 'color' : 'white'});
        if(this.defaultValue == this.value){
            this.value = "";
        }
    });
    
    $(".post-thoughts .text").blur(function() {
        $(this).css({'color' : '#5a6071'});
        if(this.value == ""){
            this.value = this.defaultValue;
        }
    });
    
    $(".post-thoughts form").submit(function() {
        //$("input .stamp").attr("value", "killnonjsbots");
        //validate twitter form on the client side
        var validation = $('#form-content').validate();
        if(validation > 0){
            //alert("validation failed!");
            switch (validation)
            {
            case 1:
              $("#thought_comment").attr("defaultValue", "Comment must be at least 5 characters");
              $("#thought_comment").attr("value", "Comment must be at least 5 characters");
              $("#thought_comment").css({'border-color' : 'red', 'color' : 'red'});
              break;
            case 2:
              $("#thought_comment").attr("defaultValue", "You must enter a comment");
              $("#thought_comment").attr("value", "You must enter a comment");
              $("#thought_comment").css({'border-color' : 'red', 'color' : 'red'});
              break;
            case 3:
              $("#thought_name").attr("defaultValue", "You must enter a name");
              $("#thought_name").attr("value", "You must enter a name");
              $("#thought_name").css({'border-color' : 'red', 'color' : 'red'});            
              break;              
            case 0:
              //data validated - this shouldn't ever happen
              break;
            }
            return false;
        }else{
            $('#form-content').hide();
            $('#form-content').before('<span id="loading"><img src="/wp-content/themes/indiana/images/ajax-loader.gif" />Sending Message...</span>');
            $.ajax({
                url: '/twitter-post-ajax.php',
                type: 'POST',
                data: 'thought_comment='+$("#thought_comment").val()+'&thought_name='+$("#thought_name").val()+'&thought_trap='+$("#thought_trap").val()+'&token='+$("#token").val(),
                dataType: 'text',
                error: function(){
                    $("#form-response").html('Error loading executing file!');
                    $("#form-response").css('color','red');
                },
                success: function(data){
                    $('#loading').remove();
                    $('#form-content').show();
                    $("#form-response").html(data);
                    $("#form-response").css('color','#ebb600');
                }
            });
            return false;
        }
    });        

    $(".theme a").click(function() {
        var src = "wp-content/themes/indiana/include/styles/images/bg-home-"+$(this).attr('rel')+".jpg";
        
        $('body').append('<div id="overlay" />');
        // Give body a height of 100% (to fix IE6 issue):
        $('body').css({height:'100%'});
        $('#overlay')  
        .css({  
             display: 'none',  
             position: 'fixed',  
             top:0,  
             left: 0,  
             width: '100%',  
             height: '100%',  
             zIndex: 1000, 
             opacity: '.8',
             background: 'black url(wp-content/themes/indiana/images/loading.gif) no-repeat center'  
         })  
        // Now fade in the div (#overlay):  
        .fadeIn(500,function(){
            // The following will happen when the div has finished fading in:
            var newBGimage = new Image();
            $(newBGimage).attr('src', src).load(function() {  
                // When New Background image has loaded, fade out and remove the #overlay div:  
                $('#overlay').fadeOut(500,function(){  
                    $(this).remove();
                    $('body.home').css('backgroundImage','url(' + src +')');                    
                });
            });
        });        
        
        //$('body.home').css('backgroundImage','url(' + src +')');
        $('#dyk-fact').html(eval('theme'+$(this).attr('rel')+'_dyk[0]'));
        $('#current-theme').html($(this).html());
        $.cookie("body-bg",$(this).attr('rel'), {expires: 365, path: '/'});
        $.cookie("current-theme",$(this).html(), {expires: 365, path: '/'});
        fact_counter = 0;
        return false;
    });
    
    $("a.next-fact").click(function() {
        if(fact_counter >= eval('theme'+$.cookie("body-bg")+'_dyk').length - 1){
            fact_counter = 0;
        }else{
            fact_counter += 1;
        }
        $('#dyk-fact').fadeOut(500, function () {
            $('#dyk-fact').html(eval('theme'+$.cookie("body-bg")+'_dyk['+fact_counter+']'));
            $('#dyk-fact').fadeIn(500);
        });
        return false;
    });
    
    $.fn.validate = function() {
        if($("#thought_comment").val().length < 5){
            return 1;
        }else if($("#thought_comment").val() == $("#thought_comment").attr("defaultValue")){
            return 2;            
        }else if($("#thought_name").val().length < 2){
            return 3;
        }else if($("#thought_name").val() == $("#thought_name").attr("defaultValue")){
            return 3;
        }else{
            return 0;
        }
    }
    
    
/*    
    //$("a[href='test.html']").colorbox({fixedWidth:"80%", fixedHeight:550, iframe:true});
    $("#test-modal").click(function() {
        tb_show('','test.html?TB_iframe=true&height=300&width=600');
        return false;
    });
    
    $.fn.getHTML = function() {
        var args = arguments[0] || {};
        var file = args.file;
        
    }
*/

});


function loadTrackingFile(){
    var ts = new Date();
    var trackingSrc = "<img src='http://smp.specificmedia.com/smp/v=5;m=1;t=1149;ts="+ts.getTime()+"' width='0' height='1' border='0' />";
    var trackingImage = new Image();
    $(trackingImage).attr('src', trackingSrc);
    //alert("Tracking Image Loaded!");
}
