(function($){
	
	window.Shifts = {
		
		opts: {
            fancybox_class: '.fancybox'
		},

		init: function(){
		         
		    var self = this; 
		    
		    // Grab the body class and see if we have a custom function for it
            var klass = 'page_' + document.body.className;
            if(typeof(self[klass]) == 'function'){
                self[klass]();
            }
            
            if($.browser.msie && typeof(Cufon) != 'undefined'){
                self._cufonFixes();
            }
            
		},
		
		_cufonFixes: function(){
		    
		    Cufon.replace('#mid h2, #mid h5', {
                textShadow: '#3C474F 1px 1px'
            });
		    
		},
		
		_setupFancyBox: function(opts){
		    
		    var self = this;
		    
		    var o = opts || {};
		    
            if(typeof($.fn.fancybox) == 'function'){
                $(self.opts.fancybox_class).fancybox(o);
            }
            
		},
		
		page_home: function(){
            
            var self = this;
            
            self._setupFancyBox();

		},
		
		page_contact: function(){
            
            // Setup the validation for the registration form
            if(typeof($.fn.validate) == 'function'){
                $('#contact-form').validate({
                    rules: {
                        contact_email: {
                            email: true
                        }
                    },
                     errorPlacement: function(error, element){
                        var label_txt = error.text();
                        if(label_txt.indexOf('email') !== -1){
                            element.parent().append(error);
                        }
                    }
                });
		    };
		    
		    // Setup the google map
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(52.129093, -106.658084), 15);
            
            var point = new GLatLng(52.129093, -106.658084);
            map.addOverlay(new GMarker(point));
		    
		},
		
		page_pricing: function(){
		    
		    var $bigger_table = $('.pricing-table:hidden');
		    
		    $('.bigger-plan a').click(function(){
		        $bigger_table.toggle();
		    });
		    
		},
		
		page_signup_form: function(){
            
            var self = this;
            
            // Setup the validation for the registration form
            if(typeof($.fn.validate) == 'function'){
                $('#signup-form').validate({
                    rules: {
                        signup_confirm_password: {
                            equalTo: '#signup_password'
                        },
                        signup_email: {
                            email: true
                        }
                    },
                    errorPlacement: function(error, element){
                        var label = error.attr('for');
                        if(label == 'signup_confirm_password' && error.text().indexOf('required') == -1){
                            element.parent().append(error);
                        }
                    }
                });
            }
            
            self._setupFancyBox({
                autoDimensions: false,
                width: 600
            });
		  
		},
		
		page_tour: function(){
		     
		     var self = this;
		     
		     if(typeof($.fn.fancybox) == 'function'){
    		     $(self.opts.fancybox_class).fancybox({
    		          type: 'iframe',
    		          width: 666,
    		          height: 460,
    		          scrolling: 'no'
    		     });
		     }
		     
		},
		
		page_blog: function(){
            
            var self = this;
            
            // Setup placeholder text
            $('#search').placeholder();
            self._setupFancyBox();
		  
		}
		
	};
	
	// When the DOM is ready.. Do it.
	$(function(){
        window.Shifts.init();
	});
	
	// Awesome jQuery plugin madness WOOOHOOOOZ
	$.fn.placeholder = function(opts){
	   
	   var default_opts = {
	       placeholder_class: 'placeholder'
	   };
	   
	   var opts = $.extend({}, default_opts, opts);
	   
	   return this.each(function(){
	       
	       var $t = $(this);
	       var orig_text = 'Search' || this.value;
	       
	       $t.bind('focus blur', function(e){
	       
	           if(e.type == 'focus'){
	               if(this.value == orig_text){
	                   this.value = '';
	                   $t.removeClass(opts.placeholder_class);
	               }
	           }
	           else {
	               if(this.value == ''){
                        this.value = orig_text;
                        $t.addClass(opts.placeholder_class);
                   }
               }
	           
	       });
	       
	   });
	   
	}
		
})(jQuery);




