var Three60 = {}; 

// UTILS ----------------------------------------------------------  

Three60.Utils = (function(){ 
			   
	return{ 
	
		log: function(msg) { 
		   	if (window.console && window.console.firebug)
				console.log(msg);
		}, 
		
		isIE: function(){
		   return (jQuery.browser.msie && jQuery.browser.version < 9);
		},
		
	  	truncate: function (str, limit) {
			var bits, i;
			bits = str.split('');
			if (bits.length > limit) {
				for (i = bits.length - 1; i > -1; --i) {
					if (i > limit) {
						bits.length = i;
					}
					else if (' ' === bits[i]) {
						bits.length = i;
						break;
					}
				}
				bits.push('...');
			}
			return bits.join('');
		}
		  
	};  
 
})(); 

// ROCKET ----------------------------------------------------------

Three60.Rocket = (function(){ 
	
	var flutter_count = 0, 
	flutter_interval = null; 
	
	return{ 
	
		init: function() { 
			
			// init custom events  
						
			$("#three60-rocket").bind("ignite", function(e) {
				Three60.Utils.log('ignite triggered'); 
				Three60.Rocket.ignite();
				return this;
			}); 
			
			$("#three60-rocket").bind("emerge", function(e) {
				Three60.Utils.log('emerge triggered'); 
				Three60.Rocket.emerge();
				return this;
			}); 
			
			$("#three60-rocket").bind("liftoff", function(e) {
				Three60.Utils.log('liftoff triggered'); 
				Three60.Rocket.liftoff();
				return this;
			}); 
			
			$("#three60-rocket").bind("entered-stratospere", function(e) {
				Three60.Utils.log('going to breakup'); 
				Three60.Rocket.breakup();
				return this;
			});

			$("#three60-rocket").trigger("emerge"); // start things rolling  
		},

		liftoff: function() {
			Three60.Utils.log('liftoff started'); 
			
			if( !Three60.Utils.isIE() ){
			 	setTimeout(function(){
					$("#three60-rocket-smoke").slideDown('fast').fadeOut('slow');  
				}, 700);   
			}
			
			$("#three60-rocket").animate({
				top: '-500px',
			    opacity: 0.0
			},
			1000, 'easeInExpo', function() {
				Three60.Utils.log('liftoff complete'); 
				$("#three60-rocket").trigger("entered-stratospere");  
			});  
  		},   
		
		emerge:function(){
		  	$("#three60-rocket").animate({
				top: '-50px'
			},
			1000, 'linear', function() {
				Three60.Utils.log('emerge complete'); 
				$("#three60-main-nav").fadeIn(3000);
				// pause here 
				setTimeout(function(){
				   $("#three60-rocket").trigger("ignite"); 
				}, 3000);
			}); 
			
			$("#three60-rocket-hole-shadow").fadeIn(7000)
		},

		ignite: function() {
			Three60.Utils.log('ignite started');		
			flutter_interval = setInterval ( function(){
			   Three60.Rocket.flutter();  
			    $("#three60-rocket").trigger("liftoff");  
			}, 100 );
		}, 
		
		breakup: function(){  
			clearInterval(flutter_interval);
		   	$("#three60-rocket-hole").fadeOut('slow'); 
			$("#three60-rocket-hole-shadow").fadeOut('slow');
			
			setTimeout(function(){
		  		$("#three60-rocket-scene").hide();
				$("#three60-content").fadeIn();    
			}, 1000);
		},
		
		flutter: function(){
 			$("#tail-flame").animate({ opacity: 0.0, height: "160%"},
				50, 'linear', function() {
					Three60.Utils.log('flutter count' + flutter_count);  
					$("#tail-flame").animate({ opacity: 1, height: "100%"}, 50, 'linear', function(){  
					   // if(flutter_count > 6){  
							//Rocket.flutter_count = 0;  
					  //  }  
					});
			});   
			flutter_count++;		
		} 
	 
	};  
 
})(); 

// CYCLER ----------------------------------------------------------

Three60.Cycler = (function(){
	var cycles = 0,
	cycle_interval = null,
	style_callback = null, 
	link_callback = null,
	container = null, 
	revolutions = 0, 
	requested_revolutions = 0,
	index = 0,
	items = [],
	number_of_items = 0
	
	return{   
		
		init:function(opts){
			items = opts.items; 
			style_callback =  opts.style_callback; 
			link_callback = opts.link_callback;
			container = opts.container;
			requested_revolutions =  opts.revolutions;
			number_of_items = items.length;  
			cycle_interval = setInterval(Three60.Cycler.cycle, opts.cycle_interval); 
			items = items.map(function(item){
			  return style_callback.apply(this, [item] );  
			});
		},
		
		cycle:function(){
		  	if(cycles >= number_of_items){   
				revolutions++; 
				Three60.Utils.log('revolution number '+revolutions);
				
				if(revolutions >= requested_revolutions) {
				   	clearInterval(cycle_interval); 
					Three60.Utils.log('reached the end');
				}
			}else{
				container.hide().html(items[cycles]).fadeIn(2000);
				if(link_callback) link_callback.call(this); 
				Three60.Utils.log( items[cycles] );
				cycles++;	
			}  
		}
	} 
	
})();
       

// CONSTANTS ----------------------------------------------------------

Three60.rocket_scientist_quotes = [
	{author: "Werner von Braun", quote: "Man is the best computer we can put aboard a spacecraft, and the only one that can be mass produced with unskilled labor"}, 
	{author: "Werner von Braun", quote: "Our sun is one of 100 billion stars in our galaxy. Our galaxy is one of billions of galaxies populating the universe. It would be the height of presumption to think that we are the only living things in that enormous immensity."},
	{author: "Werner von Braun", quote: "Research is what I'm doing when I don't know what I'm doing."},
	{author: "Werner von Braun", quote: "Don't tell me that man doesn't belong out there. Man belongs wherever he wants to go -- and he'll do plenty well when he gets there."},
	{author: "Werner von Braun", quote: "We can lick gravity, but sometimes the paperwork is overwhelming."},
	{author: "Werner von Braun", quote: "There is just one thing I can promise you about the outer-space program - your tax-dollar will go further."},
	{author: "Werner von Braun", quote: "The best computer is a man, and it's the only one that can be mass-produced by unskilled labor"},
	{author: "Werner von Braun", quote: "Crash programs fail because they are based on theory that, with nine women pregnant, you can get a baby a month."},
	{author: "Werner von Braun", quote: "It will free man from the remaining chains, the chains of gravity which still tie him to this planet."},
	{author: "Werner von Braun", quote: "For my confirmation, I didn't get a watch and my first pair of long pants, like most Lutheran boys. I got a telescope. My mother thought it would make the best gift."},
	{author: "Werner von Braun", quote: "I have learned to use the word impossible with the greatest caution."},
	{author: "Albert Einstein", quote: "Gravitation is not responsible for people falling in love."},
	{author: "Albert Einstein", quote: "The difference between stupidity and genius is that genius has its limits."},
	{author: "Albert Einstein", quote: "If I can't picture it, I can't understand it."},
	{author: "Albert Einstein", quote: "If only I had known, I should have become a watchmaker."},
	{author: "Albert Einstein", quote: "We already know that the world is far more complex, and strange, and beautiful than we thought."},
	{author: "Albert Einstein", quote: "A person who never made a mistake never tried anything new."},
	{author: "Albert Einstein", quote: "To know is nothing at all; to imagine is everything."},
	{author: "Albert Einstein", quote: "Come with me and . . . think about the electromagnetic theory of light."},
	{author: "Albert Einstein", quote: "Your imagination is your preview of life's coming attractions."},
	{author: "Brooke Sheilds", quote: "Smoking kills. If you're killed, you've lost a very important part of your life."},
	{author: "Barack Obama", quote: "On this Memorial Day, as our nation honors its unbroken line of fallen heroes -- and I see many of them in the audience here today -- our sense of patriotism is particularly strong."},
	{author: "Barack Obama", quote: "I've now been in 57 states -- I think one left to go."}
];      

Three60.testimonials = [
	{author: "Marketing Manager,  Main Line Health", quote: "Three60 Digital Design always delivers! What more can one say about a great design firm?  Okay – I have more – they are creative, resourceful, respectful and affordable. With Three60, we’re confident the project will get done right."}, 
	{author: "John H. Dixon,  Coordinator, Delaware County Keystone Innovation Zone", quote: "Seasoned professionals who provide timely service, counsel and support at a very reasonable price. Three60 works with the customer at the customer’s speed, and on the customer’s timeframe, which is a rare quality in today’s highly competitive marketplace."},
	{author: "John H. Dixon,  Coordinator, Delaware County Keystone Innovation Zone", quote: "Three60’s attention to detail, focus on the customer – regardless of the size of the engagement — and willingness to collaborate set it apart from other firms. They have my strongest endorsement as the Philadelphia region’s premiere web development and graphic design provider."},
	{author: "Susan Brown,  V.P. Senior Care of PA", quote: "My business partner and I hired Three60 Digital Design Company several months ago to create and implement our company website. We were very happy with the outcome. Our website, seniorcareofpa.com looks great and very professional. I would definitely use their services again!"},
	{author: "Mattieu Hoònri,  The Focus Context Group", quote: "I mean this for real; Thank you for doing this!!! We are totally amazed by your work. We could not believe you are whacking it up like this; it’s amazing."},
	{author: "John Masarone,  Big Arrow Up", quote: "I have been using Three60 for the past eight years for consultation, database programming and complex graphic design work. Their pricing has always been fair and delivery is always on time. They understand my company’s needs to the very last detail and often come up with recommendations that I did not think about."},
	{author: "Richard L. Hindt,  President, Lawn Quenchers, Inc.", quote: "Lawn Quenchers would not be where we are in business today without Three60′s unique development ideas. The quick response to our requests for updates and changes to the site have been awesome. We would and have referred your services to anyone looking for creative Web design and exceptional customer service."},
	{author: "Tom Orsato,  General Manager, Delaware Valley Aluminum Corp.", quote: "It’s been a pleasure to work with Owen and company designing & maintaining our website. He’s very good at explaining technical details and asking the right questions to get the desired results. He also helped us design a very effective advertising campaign and interfaces with media providers. We’ve been very happy with all phases of his organization."},
	{author: "John Lerro,  Lerro Candy Company", quote: "Three60′s photography department, in my opinion, is not one of the best, but, rather IS the best. They delivered on time and on budget."},
	{author: "John Lerro,  Lerro Candy Company", quote: "Owen’s honesty and integrity, led me to be able to trust him with the work I needed to be completed. When the job was finished, he was still available to answer any of my questions. It wasn’t about money to Owen. He made sure I was happy, even after he received my payment."},
	{author: "John Lerro,  Lerro Candy Company", quote: "We, at Lerros, have 94 years experience in the candy business and wanted to sell our product online. What I liked about Owen and his team was that they listened to our needs. I wanted some specifics incorporated into the design. Owen said no problem. He took the time to explain the process."},
	{author: "Barry", quote: "Let me be perfectly clear on this point, for the last 8 years Three60 has built websites for people, for all the people. C’mon, ya’ll fired up!Let me be perfectly clear on this point, for the last 8 years Three60 has built websites for people, for all the people. C’mon, ya’ll fired up!"}
]; 

Three60.iphone_accolades = [
	{quote: "<strong>Check out NDTimer!</strong> it's an iPhone/iPod touch application for calculating and timing correct exposures when using Neutral Density(ND) filters"}, 
	{author: "MB1742", quote: "<strong>Almost Perfect</strong> &#x2605; &#x2605; &#x2605; &#x2605; &#x2605; Great alternative to doing the math in my head. Works as advertised. Has a nice UI, lets me stack my polarizer, and the countdown timer for exposures over 30 seconds is a nice touch. Wish it had a bulb mode where custom shutter speeds could be entered to be more useful with night photography."},
	{author: "01f4irider ", quote: "<strong>Great app!</strong> &#x2605; &#x2605; &#x2605; &#x2605; really like this app, especially the feature that allows you to get exposure times for stacked filters. Very cool. The only reason I gave the app 4 stars instead of five is because you are only given a countdown timer for exposures over 30 seconds. And, if this is to be the ND app to end all ND apps then the countdown timer is going to have to go all the way down to at least 1 second (like NDCalc does, an app which I also own). Add that in the next update and I'd be an extremely happy camper. Overall, an excellent app. Thanks guys! "}
];


// fucking IE sucks donkey balls

if (!Array.prototype.map)
{
  Array.prototype.map = function(fun /*, thisp */)
  {
    "use strict";

    if (this === void 0 || this === null)
      throw new TypeError();

    var t = Object(this);
    var len = t.length >>> 0;
    if (typeof fun !== "function")
      throw new TypeError();

    var res = new Array(len);
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in t)
        res[i] = fun.call(thisp, t[i], i, t);
    }

    return res;
  };
}
