var imagePath = '/wp-content/themes/jebens/images/'
var wochentage = Array('sonntag','montag','dienstag','mittwoch','donnerstag','freitag','samstag');

var petitFours = Array('petitfours','pariser_fours','obst_fours','spezial_fours','eclairs','spezial_fours2');
var tortenklassiker = Array('schwaki','marzipantorte','cointreautorte','champagnertorte','sachertorte');
var catering = Array('catering1','catering3','catering6','catering7','catering11','catering13','catering17','catering20');
var produkte;
var current = 0;


$(document).ready(function(){
	
	// Menü Dropdown
	$('#menu').superfish();
	
	// Produktübersicht
	uebersichtMouseOver();
	
	
	// Wochenkarte
	$('#wochenkarte dd').hide().prev().click(function(){
		var classTmp = $('#wochenkarte .active').attr('class');
		if (classTmp) {
			$('#wochenkarte .active').attr('class',classTmp.substr(0,classTmp.indexOf(" "))).next().slideUp(300);
		}
		$(this).addClass('active').next().slideDown(300);
	});
	
	// aktuellen Tag anzeigen
	today=new Date();
	thisDay=today.getDay();
	$('#wochenkarte .'+wochentage[thisDay]).addClass('active').next().slideDown(300);
	
	// von Produktübersicht zur richtigen Torte
	updateBackground();
	
	
	// Weiter/Zurück Buttons
	switch ($('#main').attr('class')) {
		case 'tortenklassiker':
		case 'petit-fours':
		case 'catering':
			$('#content').prepend('<p id="nextprev"><a class="prev" href="#"><img alt="Zur&uuml;ck" src="'+imagePath+'prev.gif"/></a> &nbsp; <a class="next" href="#"><img alt="Weiter" src="'+imagePath+'next.gif"/></a></p>');
			updatePrevNextButtons();
			break;
	}
	
	$('#nextprev a').bind('click', function() {
		updateBackground($(this).attr('href').substr(1));
		updatePrevNextButtons();
		$(this).blur();
		return false;
	});
	
	
	$('#pdf a').bind('click',function(){
		$(this).blur();
		return false;
	});
});

var uebersichtMouseOver = function() {
	$('.produktuebersicht a img').bind('mouseover', function(){
		$(this).animate({width: '192px', height: '90px'},300);
	}).bind('mouseout', function(){
		$(this).animate({width: '180px', height: '80px'},150);
	});
};


var updateBackground = function(imageName) {
	changeBackground = false;
	var produktCat = $('#main').attr('class');
	switch(produktCat){
		case 'tortenklassiker':
			produkte = tortenklassiker;
			changeBackground = true;
			break;
		case 'petit-fours':
			produkte = petitFours;
			changeBackground = true;
			break;
		case 'catering':
			produkte = catering;
			changeBackground = true;
	}
	if (changeBackground){
		if (imageName){
			imageTmp = imageName;
		} else {
			imageTmp = document.URL.split("#")[1];
		}
		if (imageTmp){
			$('#main').css('background', 'url('+imagePath+imageTmp+'.png) no-repeat left');
			for (i = 0; i < produkte.length;i++){
				if (produkte[i] == imageTmp){
					current = i;
				}
			}
		}
	}
};

var updatePrevNextButtons = function() {
	if (current == 0){
		prev = produkte.length - 1;
	} else {
		prev = current - 1;
	}
	if (current == produkte.length - 1){
		next = 0;
	} else {
		next = current + 1;
	}
	$('#nextprev a.prev').attr('href','#'+produkte[prev]);
	$('#nextprev a.next').attr('href','#'+produkte[next]);
}


var test = function(menu_id) {
	setTimeout(function(){
		if (currentSubMenu != menu_id) {
			$('#'+menu_id, this.parent).fadeOut(200);
		}
	}, 300);
};