//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'
	};
	sectionColour = buttonColours[$('#content > div').attr('id')];

	$('.rollover').hover(function() {
		// On Mouseover
		oldSrc = $(this).attr('src');
		$(this).attr('src', oldSrc.replace('_off', '_over'));
	},
	function() {
		// On Mouseout
		$(this).attr('src', oldSrc);
	});

	// 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').click(function(){
		$(this).parents('li').toggleClass('open').find('.answer').toggle();
		$(this).parents('li').siblings().removeClass('open').find('.answer').hide();
		return false;
	});
	
	$('.dropAccordeon h3, .dropAccordeon .btn').click(function(){
		$(this).parents('li').toggleClass('open').find('.answer').slideToggle();
		$(this).parents('li').siblings().removeClass('open').find('.answer').slideUp();
		return false;
	});
	
	
	
	//Add border to last left_nav item
	var temp = $('#left_nav .level1');
	temp.eq(temp.length - 1).addClass('bottom');
	
	//tab behaviour
	$( ".cnt_" + $('.tabnav li.on').attr('id') ).show().siblings().hide();
	
	$('.tabnav li').click(function(){
		$(this).addClass('on').siblings().removeClass('on');
		$( ".cnt_" + $(this).attr('id') ).show().siblings('div').hide();
	});
	
	$('.betterSelect').betterSelect();
});

$(window).bind("load",function(){
	$('a.button').each(function(){
		$(this).css({width: $(this).children('img')[0].width, visibility: "visible"});
	});
});

var redi = function(){
	window.location = arguments[0];
}