// In case we forget to take out console statements. IE becomes very unhappy when we forget. Let's not make IE unhappy
/*if(typeof(console) === 'undefined') {
	var console = {}
	console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
}*/

function my_hallo(){
	alert('hallo');
}

function init_weinFlow(){
	$(document).ready(function(){
		setTimeout(function() {var weinFlow=new ContentFlow('weinFlow',{reflectionHeight:0.05,maxItemHeight:325}).init();},200);
		// var weinFlow=new ContentFlow('weinFlow',{reflectionHeight:0.05,maxItemHeight:325}).init();
	});
}

function init_kundenFlow(){
	$(document).ready(function(){
		var kundenFlow=new ContentFlow('kundenFlow',{reflectionHeight:1,scaleFactor:1.5,maxItemHeight:192}).init();
	});
}
function init_gmap(){
	window.setTimeout(function(){
		var myOptions = {zoom:10,center:new google.maps.LatLng(49.06841, 7.979190000000017),mapTypeId: google.maps.MapTypeId.ROADMAP};
		map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		marker = new google.maps.Marker({map: map, position: new google.maps.LatLng(49.06841, 7.979190000000017)});
		infowindow = new google.maps.InfoWindow({content: "<b>Weingut Heinz & Thomas Beck</b><br>Rotackerweg 27<br>76889 Oberotterbach"});
		google.maps.event.addListener(marker, "click", function(){infowindow.open(map,marker);});infowindow.open(map,marker);
	},300);
}
function do_some_bottle_animation(event){
	if ($(event.target).parent().is('.menu-item-92')){ // home?
		$('#article').removeClass('right_to_bottle');
		$('#menu').animate({'margin-left' : '373px'}, 1000, 'swing', function() {
			// menu animation complete
			fade_the_article_in(event);
			
		}); // end menu animation
	}
	else {
		$('#article').toggleClass('right_to_bottle');
		$('#menu').animate({'margin-left' : ($('#menu').css('margin-left')=='0px')?'800px':'0px'}, 1000, 'swing', function() {
			// menu animation complete
			fade_the_article_in(event);
			
		}); // end menu animation
	}
//	console.log($(event.target).parent().attr('id'));
}

function do_some_other_bottle_animation(event){
	if ($(event.target).parent().is('.menu-item-92')){
		$('#article').removeClass('right_to_bottle');
		$('#header h1').fadeIn();
		$('#menu').animate({'margin-left' : '373px'}, 1000, 'swing', function() {
			// menu animation complete
			fade_the_article_in(event);
		}); // end menu animation
	}
	else{
		$('#menu').animate({'margin-left' : '0px'}, 1000, 'swing', function() {
			// menu animation complete
			$('#article').addClass('right_to_bottle');
			fade_the_article_in(event);
			
		}); // end menu animation
	}
}

function fade_the_article_in(event){
	$('#article').fadeIn('slow', function() {
		// article fadeIn complete
		if ($(event.target).parent().is('.menu-item-67')){init_weinFlow();}
		if ($(event.target).parent().is('.menu-item-176')){init_kundenFlow();}
		if ($(event.target).parent().is('.menu-item-47')){init_gmap();}
		if ($(event.target).parent().is('.menu-item-92')){
			$('#header h1').fadeIn(); //home
		} else {
			$('#header h1').fadeOut(); // not home
		}
//		console.log($(event.target).parent().is('.menu-item-92'));
	//	try{init_kundenFlow();}
	//	catch(e){console.log(e);}
	//	try{init_weinFlow();}
	//	catch(e){console.log(e);}
		
	});// end fadeIn
}
$(document).ready(function() {
	// header verschwinden lassen nach dem ersten click
	//$('a').click(function(event) {
		//$('#header h1').fadeOut();
	//});
	// wenn startseite: Flasche in die mitte
//	if ($('body').hasClass('home')){$('#menu').css('margin-left', '373px');$('#article').toggleClass('right');};
	// Verhalten der Flasche mit menue
	$('#menu a').click(function(event) {
		//prevent default behaviour
		event.preventDefault();
		// article fade out
		$('#article').fadeOut('slow', function() {
			// fadeOut done now load new article
			$('#article').load(event.target+' #inner', function() {
				// load complete
				do_some_bottle_animation(event);
			}); // end load
		}); // everything done
	}); //end click

	// Verhalten der links im footerbereich
	$('#menu-fuszeile a, #menu-flaschenmenu-1 a').click(function(event) {
		//prevent default behaviour
		event.preventDefault();
		$('#article').fadeOut('slow', function() {
			$('#article').load(event.target+' #inner', function() {
				// load complete
				do_some_other_bottle_animation(event);
			}); // end load
		}); // everything done
	}); //end click
	
	// Wenn "Anfahrt" gmap initialisieren
	if (location.href.match('anfahrt')){init_gmap();}

	// Sidebar maniputation
	$('#sb_toggle').click(function(event) {
		$('#sidebar').toggleClass('hidden');
	});
	
	//bubblefix on i-pad
	//if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
/*	$(".bubble_handle").live('click', function(event){
		$(event.target).find('.bubble').css('display', 'block');
		alert($(event.target).find('.bubble').innerHTML);
		console.log($(event.target));
		console.log("touch started");
	});
	$(".bubble_handle").live('touchend', function(){
		console.log("touch ended");
	});
*/

}); // ende von domReady
//Cufon.replace('header h1');
