/**
 * imulus.interface.js
 *
 */


Imulus.Interface = function(){
  var Interface = this;

  Interface.init = function(){
    this.forms.init();
  };

  Interface.forms = {
    init : function(){
      this.build();
      this.style();
      this.observe();
    },

    build : function(){
      if (!elementSupportsAttribute('input', 'placeholder')) { // Add placeholder for search box
        $('input[placeholder]').each(function(index) {
          var currentValue = $(this).val($(this).attr("placeholder"));
          $(this).addClass('inactive');

          $(this).focus(function() {
            if ($(this).val() === $(this).attr("placeholder")) {
              $(this).val("").removeClass('inactive');
            }
          });

          $(this).blur(function() {
            if ($(this).val() === "") {
              $(this).val($(this).attr("placeholder")).addClass('inactive');
            }
          });
        });
      }

			$('#nav li a').corner('5px');
			

			new Imulus.Slideshow();
    },

    style : function(){
      $("#main table tbody tr:nth-child(even)").addClass("even"); // Zebra stripe tables
    },

    observe : function(){
			$('#view-demo').click(function(event) {
				event.preventDefault();
				window.open('/demo/','Demo','location=0,status=0,scrollbars=0,width=680,height=524');
			});
	
			if ($('body').hasClass('download')) {

				function runDownload() {
					var downloadLink = $('#content #start-download').attr('href');
					window.location.href=downloadLink;
				}
				
				function endCountdown() {
					runDownload();
				}

				function handleTimer() {
				  if(count === 0) {
					  $('#countdown span').html(count);
				    clearInterval(timer);
				    endCountdown();
				  } else {
				    $('#countdown span').html(count);
				    count--;
				  }
				}

				var count = 3;
				var timer = setInterval(function() { handleTimer(count); }, 1000);		
				
			};
    }
  }

  Interface.init();
};

