jQuery(function() {
  theSite.fire();
});

var theSite = (function($, undefined) {
  return {
    fire: function() {
      // this just calls every method in theSite.init
      for (var i in theSite.init) {
        theSite.init[i]();
      }
    },
    init: {

		// Initiate Slideshow
		initSlideshow: function() {
			var $slideshow = $('.slideshow');
			if ($slideshow.length) theSite.slideshow( $slideshow );
		},
		initFormToggle: function() {
			var $connecttextbox = $('#connect-textbox');
			if ($connecttextbox.length) theSite.formValueToggle( $connecttextbox );
		}
    },
   	slideshow: function($slideshow) {
		
		$('.slideshow').cycle({
			fx: 'scrollHorz',
			pager: '#slideshowNav',
			pagerAnchorBuilder: function(index, el) {
				return '<a href="#">' + (index+1) + '</a>';
			},
			speed:  'fast',
			autostop:        1,     // true to end slideshow after X transitions (where X == slide count) 
			autostopCount:   11,
			timeout: 8000
		});
    },
	formValueToggle: function($connecttextbox) {

	    $connecttextbox.focus(function() {
	        if (this.value == this.defaultValue){
	            this.value = '';
	        }
	        if(this.value != this.defaultValue){
	            this.select();
	        }
	    });
	    $connecttextbox.blur(function() {
	        if (this.value == ''){
	            this.value = this.defaultValue;
	        }
	    });
	},
    utilities: {
		// you can package code together with related methods like so
		// this would be theSite.utilities.trim(str)
		trim: function(str) {
		  return $.trim(str);
		},
		makeUpper: function(str) {
		  return str.toUpperCase();
		},
		/*********
		switch an image by changing the src name from 'off' to 'on' and vice versa
		*********/
		toggleImage: function(obj) {
			// The image is currently in the OFF state
			if (obj.src.indexOf('-off.') < 0)
			{
			obj.src = obj.src.replace('-on', '-off');
			}
			// The image is currently in the ON state
			else
			{
			obj.src = obj.src.replace('-off', '-on');
			}
		}
    }
  }
})(jQuery);

