
$(document).ready(function() {
	DEVONDALE.bugFixes.init();
	DEVONDALE.loginBox.init();
	DEVONDALE.updateForm.init();
	DEVONDALE.swfObject.init();
	DEVONDALE.gallery.init();
});

var DEVONDALE = {

	bugFixes : {
		init : function () {
			if ($.browser.msie) {
				DEVONDALE.bugFixes.ieFixes();
			}
			$('a.open-external').each(function() {
				$(this).click(function(){window.open(this.href);return false;});
			});
		},
		ieFixes : function () {
			$('li:first-child,.section h3:first-child').addClass('first-child');
			$('li:last-child,tr th:last-child,tr td:last-child').addClass('last-child');
		}
	},
	
	loginBox : {
		init : function () {
			$('#login_email').focus(DEVONDALE.loginBox.fieldFocus);
			$('#login_email').blur(DEVONDALE.loginBox.fieldBlur);
			$('#login_password').focus(DEVONDALE.loginBox.fieldFocus);
			$('#login_password').blur(DEVONDALE.loginBox.fieldBlur);
			$('#login_email').blur();
			$('#login_password').blur();
		},
		fieldFocus : function() {
			$(this).removeClass('empty');
		},
		fieldBlur : function() {
			if ($(this).val() == '') {
				$(this).addClass('empty');
			}
		}
	},
	
	updateForm : {
		init : function () {
			$('#user_grocery_buyer').change(function(){
				if ($(this).val() == 'Yes, I am the main grocery buyer in my household.') {
					$('#grocery_shop').show();
				} else {
					$('#grocery_shop').hide();
				}
			});
			$('#user_grocery_buyer').change();
			
		}
		
	},
	
	swfObject : {
		
		init : function() {
			
			var flashvars = { swfpath: '/assets/swf/' };
			var params = { wmode: 'transparent' };
			var attributes = { id: 'flash-cow' };
			swfobject.embedSWF("/assets/swf/cow.swf", "flash-cow", "180", "120", "6.0.0", "/assets/swf/expressInstall.swf", flashvars, params, attributes);
			
			var flashvars = { buttonTarget: '/help' };
			var params = { wmode: 'transparent' };
			var attributes = { id: 'flash-button' };
			swfobject.embedSWF("/assets/swf/button.swf", "flash-button", "195", "195", "6.0.0", "/assets/swf/expressInstall.swf", flashvars, params, attributes);
		
		}
		
	},
	
	
	gallery : {
		
		init : function() {
		
			$('#gallery-thumbnails a').click(function() {
				$('#gallery-image img').attr('src', $(this).attr('href'));
				$('#gallery-image strong').text($(this).attr('title'));
				return false;
			});
	
		}
		
	}
	
	
	

};
