function supportsSVG() {
  return !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect;
}

var citizen = citizen || {};
citizen.home = function(){
	
	var _carouselTimer;
	
	var self = {
		
		currentSlide: 1,
		
		init : function(){
	
			citizen.main.debug('# [home init]');
			
			_carouselTimer = setInterval( "citizen.home.nextSlide()", 14000 );
			
			$('#carousel ul').fadeIn( 1000 );
			
			$('#carousel #carousel-nav li').click( function(e){
				
				clearInterval( _carouselTimer );
				
				var n = e.target.id.substr(13,1);
				
				self.goToSlide( Number(n) );
				
				_carouselTimer = setInterval( "citizen.home.nextSlide()", 14000 );
				
			});
			
			// Get Blog Posts
 /*     parseRSS('http://citizenry.tumblr.com/rss',function(data){
      	//var first_two_sents = new RegExp("([^\.?!]+[\.?!]){2}");
        for (var i = 0; i < 2; i++) {
          var post = data.entries[i];
          var posted = new Date(post.publishedDate);
          var content = $('<div/>').html(post.content);
          var sentences;
          content.find('p').each(function(){
          	if ($(this).text().length >= 20) {
          		//sentences = first_two_sents.exec($(this).text())[0];
          		sentences = $(this).text().split(' ').slice(0,14).join(' ') + '...';
          		return false;
          	}
          });
          if (sentences != null) {
          	$("#leaders ul li:eq(1)").append('<strong>' + post.title + '</strong><p>'+sentences+' <a href="'+post.link+'" class="gray">Read More</a></p>');
          }
        }
      });*/


			
			// SVG support or not?
			if (($.browser.webkit || ($.browser.mozilla && $.browser.version > '2')) && supportsSVG()) {
				$("#flipper").html('<iframe src="clock.html" width="125" height="75" scrolling="no" frameborder="0"></iframe>');
			} else {
				$.getScript("http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js",function(){
					var flashvars = {};
					var params = {
						menu: "false",
						wmode: "transparent",
						scale: "default"
					};
					var attributes = {
						id: "flash",
						name: "flash"
					};
					swfobject.embedSWF("./media/flash/clock.swf", "flash", "125", "75", "8.0.0","./media/flash/expressInstall.swf", flashvars, params, attributes);
				});
			}
		},
		
		nextSlide : function(){
			
			if( self.currentSlide < 4 ){
			
				self.goToSlide( self.currentSlide + 1 );
				
			}else{

				self.goToSlide( 1 );				
				
			}
			
		},
		
		goToSlide : function( n ){
			
			self.currentSlide = n;
			
			$('#carousel ul').animate( {left:(-1024*(n-1))},{duration: 2000,easing:'easeInOutQuart'});
			
			$('#carousel #carousel-active').animate({opacity:0}, 1000, function(){ $('#carousel #carousel-active').css('left',String(934+(21*(n-1)))+'px') }).animate({opacity:1}, {duration: 1000});
			
		},
		
		launchEcosystems : function( n ){
				window.open('media/images/converging-mobile-ecosystems.jpg','terms','left=20,top=20,width=1200,height=765,toolbar=0,resizable=1,menu=0,scrollbars=0,status=0');
		}
		
	}
	
	return self;

}();
citizen.main.queue(citizen.home.init);
