if(typeof console == 'undefined' ) {
	console = {
		log: function() {}
	};
}

var fangohr = {};

var deviceIphone = "iphone";
var deviceIpod = "ipod";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current device is an iPhone.
function DetectIphone()
{
   if (uagent.search(deviceIphone) > -1)
      return true;
   else
      return false;
}

//**************************
// Detects if the current device is an iPod Touch.
function DetectIpod()
{
   if (uagent.search(deviceIpod) > -1)
      return true;
   else
      return false;
}

//**************************
// Detects if the current device is an iPhone or iPod Touch.
function DetectIphoneOrIpod()
{
    if (DetectIphone())
       return true;
    else if (DetectIpod())
       return true;
    else
       return false;
}



fangohr.params = [];

var stack = { //allows delayed iteration with jQuery.each() - see stack.actions.push(function(){ }) below.
    delay: 200,
    actions:[],
    run: function() {
        if (stack.actions.length) {
            stack.actions.shift()();
            setTimeout(stack.run, stack.delay);
        }
    }
};

var number = 1;

jQuery(document).ready(function(){
	var wrapper = jQuery('#wrapper');
	var sections = jQuery('.nav li');
	sections.hide();

	sections.each(function(){
        var el = this;
        stack.actions.push(function(){
			jQuery(el).fadeIn('slow');
        });
	});
	
	jQuery('.nav a').click(function(event){
		wrapper.fadeOut('fast');
	});
	wrapper.fadeIn('slow',function(){
        stack.run();	
	});
	
    if (Modernizr.video && Modernizr.video.ogg){
        $("#flashwrapper").html("");
    } 
    else if (Modernizr.video && Modernizr.video.h264){
        $("#flashwrapper").html("");
    }else{
        $(".html5").hide();
    }
    
    if(DetectIphoneOrIpod()){
        $("#no-ipod").html("");
    }else{
        
        $("#ipod").html("");
    }
    
    
	
	setTimeout(function(){setInterval(function(){ weather(number%3); number +=1;}, 8000)}, 5000)	


		
});

function weather(number){
    switch(number){
        case 1:
            $.simpleWeather({
				zipcode: '11201',
				unit: 'f',
				success: function(weather) {
				    $("#weather-info").html('');
				    
					$("#weather-info").append('<h2>weather</h2>');
					$("#weather-info").append('<p>'+weather.currently+'<br /><span>'+weather.temp+'&deg; '+weather.units.temp+'</span></p>');
		 			/* $("#weather-info").append('<img style="float:left;" width="125px" src="'+weather.image+'">');  */
					
					/* $("#weather-info").append('<a href="'+weather.link+'">View Forecast &raquo;</a>'); */
				},
				error: function(error) {
					$("#weather-info").html('<p>'+error+'</p>');
				}
			});
			break;
		case 2:
	        $.simpleWeather({
				zipcode: '11201',
				unit: 'f',
				success: function(weather) {
				    $("#weather-info").html('');
					$("#weather-info").append('<h2>wind</h2>');
					$("#weather-info").append('<p>direction: '+weather.wind.direction+'<br />speed: '+weather.wind.speed+' mph</p>');
				},
				error: function(error) {
					$("#weather-info").html('<p>'+error+'</p>');
				}
			});
			break;
		case 0:
		    $.simpleWeather({
				zipcode: '11201',
				unit: 'f',
				success: function(weather) {
				    $("#weather-info").html('');
					$("#weather-info").append('<h2>astronomy</h2>');
					$("#weather-info").append('<p>sunrise: '+weather.sunrise+'<br />sunset:  '+weather.sunset+'</p>');
				},
				error: function(error) {
					$("#weather-info").html('<p>'+error+'</p>');
				}
			});
			break;

    }
}

