//On Document.Ready
$(function() {

	// On Document.ready()
	var oldSrc = "";
	buttonColours = {
		'careers': '#FFA01A',
		'investors': '#6C0D00',
		'contact': '#4BAEE9',
		'company_information': '#4BAEE9',
		'butcher': '#1875af',
		'baker': '#ec540f',
		'pastamaker': '#2b7e30',
		'contact_us': '#2db3d8',
		'mme': '#ffb10a'
	};
	sectionColour = buttonColours[$('#content > div').attr('id')];

	$('.rollover').hover(function() {
		// On Mouseover
		oldSrc = $(this).attr('src');
		$(this).attr('src', oldSrc.replace('_off', '_over').replace('-off', '-on'));
	},
	function() {
		// On Mouseout
		$(this).attr('src', oldSrc);
	});
	
	$('p + p,p + h2,ul + p').css('margin-top', '14px');
	
	$('input[type=text]').addClass('textfield');

	// Set .bottomtout to fix some padding issues.
	var touts = $('#right_touts .tout');
	touts.eq(touts.length - 1).addClass('bottom_tout');
	/*
	//Oh munchkin, It's alive!
	$('a.button').hover(function(){
		$(this).css({backgroundColor: sectionColour});
	}, function(){
		$(this).css({backgroundColor: 'black'});		
	});
	
	//Benjamin button
	$('a.button.reverse').hover(function(){
		$(this).css({backgroundColor: 'black'});
	}, function(){
		$(this).css({backgroundColor: sectionColour});		
	});
	*/
	$('.accordeon .bottom, .accordeon .datum > a, .accordeon .number').css('cursor', 'pointer').click(function(){
		$(this).parents('li').toggleClass('open').find('.answer').slideToggle();
		//$(this).parents('li').siblings().removeClass('open').find('.answer').hide();
		return false;
	});
	
	$('.dropAccordeon h3, .dropAccordeon .btn').css('cursor', 'pointer').click(function(){
		$(this).parents('li').toggleClass('open').find('.answer').slideToggle();
		//$(this).parents('li').siblings().removeClass('open').find('.answer').slideUp();
		return false;
	});
	
	//Please put your hands together and welcome the amazing tabular zebra
	$('table#management_team tbody tr').css("cursor", "pointer").filter(':even').css('background-color', '#f8f8f8');
	
	//Add border to last left_nav item
	var temp = $('#left_nav a:visible');
	temp.eq(temp.length - 1).addClass('bottom');

	/*
	$('a.button').each(function(){
		$(this).css({width: $(this).children('img')[0].width, height: $(this).children('img')[0].height, visibility: "visible"});
		$(this).css('visibility', 'visible');
	});
	*/
	var backButton = $(".middle #button_back");  // save on $() calls
	//var buttonHeight = parseInt(backButton.css("padding-top").replace("px","")) + parseInt(backButton.css("padding-bottom").replace("px","")) + backButton.height();
	var heightFix = parseInt(backButton.parent().height() - backButton.outerHeight()) /2;
	backButton.css({"margin-top":heightFix});
	
	//make the whole tout clickable
	$('#right_touts .tout, #right_touts .cc_tout').css('cursor', 'pointer').each(function(){
		var anchor = $("a", this);
		$(this).children('.tout_content').click(function(){
			if(anchor.attr('target') == '_blank'){
				window.open(anchor.attr('href'));
			} else {
				window.location = anchor.attr('href');
			}
			return false;
		}).hover(toutHoverOn($('a > img', this)), toutHoverOff($('a > img', this)))
	});
	
	//make all the category touts clickable
	$('.product_list-px200 li:not(.noclick), .product_list li:not(.noclick), #board.region, .mini_tout').each(function(){
		if($('select, input, textarea', this).length == 0){
			$(this).css('cursor', 'pointer').click(function(){
				var anchor = $('a', this);
				if(anchor.attr('target') == '_blank'){
					window.open(anchor.attr('href'));
				} else {
					window.location = anchor.attr('href');
				}
				return false;
			}).hover(toutHoverOn($('a > img', this)), toutHoverOff($('a > img', this)))
		}
	});
});

var toutHoverOn = function(img){
	if(img.attr('src') != null) {
		if(img.attr('src').indexOf('on') != -1){	
			img.attr('src', img.attr('src').replace('-on', '-off'));
		} else if(img.attr('src').indexOf('off') != -1) {
			img.attr('src', img.attr('src').replace('-off', '-on'));
		}
	}
};

var toutHoverOff = function(img){
	if(img.attr('src') != null) {
		if(img.attr('src').indexOf('on') != -1){	
			img.attr('src', img.attr('src').replace('-on', '-off'));
		} else if(img.attr('src').indexOf('off') != -1) {
			img.attr('src', img.attr('src').replace('-off', '-on'));
		}
	}
}

var redi = function(){
	window.location = arguments[0];
}
/* ADDED BY JOHN... VIRTUAL KITCHEN + FAQ SECTION STARTS
*********************************************************/

var closeVirtualKitchen = function(){
	$('#virtualKitchenFlash').hide();
}

$(document).ready(function(){
	$('#virtualKitchenPop').bind('click',function() {
	
		$('#virtualKitchenFlash').css('position','absolute').css('zindex','1000');	
		var top1 = '0';
		var left1 = '-8px';
	
		$('#virtualKitchenFlash').css('top',top1).css('left',left1);
		$('#virtualKitchenFlash').css('_top',top1).css('_left',left1);
		$('#food_safety').css('height','564px'); // make this div bigger to push down the footer
		$('#virtualKitchenFlash').show();
		
	});	
	
	/* FAQ PAGES TAB SECTION
	******************************************************************/
	$('#faq_sec_btn').click(function(){
		$('#faq_sec').show();
		$('#faq_all').hide();
		$('#faq_sec_btn').removeClass('tab_section_not_selected').addClass('tab_section_selected');
		$('#faq_all_btn').removeClass('tab_all_selected').addClass('tab_all_not_selected');
	});
	
	$('#faq_all_btn').click(function(){
		$('#faq_all').show();
		$('#faq_sec').hide();
		$('#faq_sec_btn').removeClass('tab_section_selected').addClass('tab_section_not_selected');
		$('#faq_all_btn').removeClass('tab_all_not_selected').addClass('tab_all_selected');
	});
	

});	
/* ADDED BY JOHN... VIRTUAL KITCHEN + FAQ SECTON ENDS
*********************************************************/

