$(document).ready(function() {


$('#contactform').validate() ;

$('#promo').promoanimator() ;

/*
 * GOOGLE MAPS OVERLAY
 */
 
$('body').append('<div id="maps_overlay" style="display:none;" /><div id="maps_window" style="display:none;"><div id="maps_window_close"><div id="maps_window_close_button" style="opacity:0;filter:alpha(opacity=0) ;">Fenster schließen</div></div><div id="maps_window_content" /><img src="img/loader.gif" id="map_loader" alt=""/><div id="map_load_msg">Bitte etwas Geduld, die Karte wird für Sie geladen.</div></div>') ;


/*

http://maps.google.de/maps?f=q&source=s_q&hl=de&geocode=&q=55129+Hechtsheim+Alte+Mainzer+Str.+13&aq=&sll=51.151786,10.415039&sspn=30.340044,52.954102&ie=UTF8&hq=&hnear=Alte+Mainzer+Stra%C3%9Fe+13,+Hechtsheim+55129+Mainz,+Rheinland-Pfalz&ll=49.961305,8.280505&spn=0.007558,0.012928&z=17



*/


// src="http://maps.google.de/maps?f=q&amp;source=s_q&amp;hl=de&amp;geocode=&amp;q=Alte+Mainzer+Str.+13,+55129+mainz&amp;output=embed"

$('#maps_window_close_button').click(function() {

	$('#maps_overlay').stop(true).delay(200).animate({opacity: 0}).queue(function() {
		$('#maps_overlay').css('display', 'none') ;
		//alert($('#maps_overlay').css('display')) ;
	}) ;
	
	
	
	if($.browser.msie && $.browser.version == 7)
	{
		$('#maps_window').css({display: 'none'}) ;
	}
	else
	{
		$('#maps_window').stop(true).animate({opacity: 0}).queue(function() {
			$('#maps_window').css('display', 'none') ;
			$('#maps_window_content').html('') ;
		}) ;
	}
	

}) ;

$('#maps_overlay').click(function() {
	$('#maps_window_close_button').trigger('click') ;
}) ;


$('.map_link').click(function() {

	var url = $(this).attr('href') ;
	var opening = $(this).parent('span').parent('td').siblings('td.opening').children('span').html() ;
	
	$('#map_loader').css({display: 'none'}) ;
	$('#map_load_msg').css({display: 'none'}) ;
	
	$('#maps_overlay').stop(true).css('display', 'block').animate({opacity: 0.4}) ;
	$('#maps_window').stop(true).css('display', 'block') ;
	
	if($.browser.msie && $.browser.version == 7)
	{
	}
	else
	{
		$('#maps_window').animate({opacity: 1}) ;
	}

	$('#maps_window').queue(function() {
		
		
	$('#maps_window_close_button').delay(200).animate({opacity: 1}) ;
	
	/* GOOGLE MAPS JS API */ 
	geocoder = new google.maps.Geocoder();
	geocoder.geocode({'address': url}, function(results, status) {
	
		var myOptions = {
			zoom: 16,
			center: results[0].geometry.location,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById("maps_window_content"), myOptions);
		
		var icon = new google.maps.MarkerImage('img/map_marker.png',
		      new google.maps.Size(78, 93), // This marker is 20 pixels wide by 32 pixels tall.
		      new google.maps.Point(0,0), // The origin for this image is 0,0.
		      new google.maps.Point(35, 92)); // The anchor for this image is the base of the flagpole at 0,32.
		
		
		var shadow = new google.maps.MarkerImage('img/map_shadow.png', // The shadow image is larger in the horizontal dimension
		      new google.maps.Size(94, 83), // while the position and offset are the same as for the main image.
		      new google.maps.Point(0,0),
		      new google.maps.Point(33, 77));
		
		
		
		var marker = new google.maps.Marker({
			position: results[0].geometry.location, 
			map: map,
			icon: icon,
			shadow: shadow,
			title:"Werner's Backstube"
		});
		
		var infowindow = new google.maps.InfoWindow({
		    content: '<strong>Öffnungszeiten:</strong><br/>'+opening
		});
		
		google.maps.event.addListener(marker, 'click', function() {
		  infowindow.open(map,marker);
		});

	});
	/* END GOOGLE MAPS JS API */ 
	
	
	
	}) ;
		

	return false ;
}) ;



/*
 * IMAGEWRAP
 */


$('#maincol p img').each(function() {
	$(this).css({width: '530px', height: '350px'}).wrap('<div class="imagewrap" />') ;
}); 
$('.imagewrap').prepend('<div class="desc" />') ;

$('.imagewrap').each(function() {
	
	if($(this).children('img').attr('alt') == '')
	{
		$(this).children('.desc').css({display: 'none'}) ;
	}

	$(this).children('.desc').append($(this).children('img').attr('alt')) ;
}) ;


/*
 * OVERLAY
 */

/*$('.product .desc_overlay').hover(function() {

	$(this).stop(true).animate({opacity:1}, 200);

}, function() {

	$(this).stop(true).animate({opacity:0}, 400);

}) ;*/

	
$('.accordion').accordion({ 
	collapsible: true,
	active: false,
	autoHeight: false,
	changestart: function(event, ui) {
		ui.newHeader.children('span.bullet').css('background-position', 'top') ;
		ui.oldHeader.children('span.bullet').css('background-position', 'bottom') ;
		
	},
	change: function() {
		$(window).trigger('resize');
	}
});


	//alert('hier') ;
	$(window).resize(function() {
		
		//alert('win:'+$(window).height()) ;
		//alert('wrap:'+($('#wrapper').height()+100)) ;
		if($('#wrapper').height()+250 >= $(window).height()) // war 193
		{
			//alert('rel') ;
			$('#footer').css('position', 'relative') ;
		}
		else
		{
			//alert('abs') ;
			$('#footer').css('position', 'absolute') ;
		}
	
	}) ;
	
	setTimeout(function() {
	    $(window).trigger('resize') ;
	}, 200) ;

}) ;


/*$(document).ready(function() {
	
	
	//alert('hier') ;
	$(window).resize(function() {
		
		//alert('win:'+$(window).height()+'wrap:'+$('#wrapper').height()) ;
		//alert('wrap:'+($('#wrapper').height()+250)) ; // war 193
		if($('#wrapper').height()+200 >= $(window).height())
		{
			//$('#footer').css('position', 'relative') ;
			//alert('relative') ;
			
			$('#footer').css('bottom', 'auto') ;
			$('#footer').css('top', ($('#wrapper').height()+100)+'px') ;
		}
		else
		{
			//alert('absolute') ;
			//$('#footer').css('position', 'absolute') ;
			$('#footer').css('top', 'auto') ;
			$('#footer').css('bottom', '0px') ;
		}
	
	}) ;
	
	$(window).trigger('resize') ;

}) ;*/
