var GR = {
	init: function(){
		$("#menu-main").accordion({
			event: "click",
			active: $("#menu-main li.current-menu-parent").index(),
			navigation: true,
			clearStyle: true,
			autoHeight: false
		});

		$("#menu-main li a").live("click", function(){
			if (!$(this).next("ul").size())
				window.location = $(this).attr("href");
		});

		$("#slideshow").cycle({
			timeout: 8000,
			random: true,
			after: GR.resizeImageCol()
		});		

		// ordne alle Links der Galerie einer Gruppe zu
		$("#gallery a").attr("rel", "GalGroup");

		$("a[rel=GalGroup]").fancybox({
			"overlayColor"		: "#520e44",
			"overlayOpacity"	: "0.9",
			"transitionIn"		: "fade",
			"transitionOut"		: "fade",
			"titlePosition"		: "over",
			"titleFormat"			: function(title, currentArray, currentIndex, currentOpts){
				var thisTitle = $("#gallery a").eq(currentIndex).find("img").attr("alt");
				return '<span id="fancybox-title-over">' + (thisTitle.length ? thisTitle : '') + '</span>';
			}
		});

		$("#gallery.anfahrt").before('<ul id="anfahrt-nav">').cycle({
			timeout:	0,
			pager:		"#anfahrt-nav",
			fx:				"fade",
			speed:		700,
			pagerAnchorBuilder:	function(idx, slide){
				return '<li>&gt; ' + $(slide).attr("alt") + '</li>';
			}
		});
		
		// IE pseudo class :last-child work arround
		$("#content #left article:last-child").css({ borderBottom: "0 none" });
		$("#content #left article div img:last-child").css({ padding: "15px 0 0 0" });
		
		GR.resizeImageCol();
	},

	initNoMSIE: function(){
		$("aside img, #content #left #gallery a img").hover(function(){
    	$(this).css({ opacity: ".8"});
		}, function(){
 	  	$(this).css({ opacity: "1"});
  	});
	},
	
	initMSIE7: function(){
		$("div.wrapSide, div#content #right div").css({ position: "absolute" });
	},

	resizeImageCol: function(){
		$("div#content #right, div#content #right div").css({ height: 0 }).css({ height: $("#wrap").height() + "px !important" });
	},
	
	loadMap: function(){
		if ($("#map").size() && GBrowserIsCompatible()){
			var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallZoomControl());
			map.enableContinuousZoom();
			map.enableDoubleClickZoom();
			map.setCenter(new GLatLng(51.19881661851783, 13.79007339477539), 13);

			var info='<div style="height: 175px;"><strong>Galerie Refugium</strong><br/>Hauptstraße 3<BR>01458 Medingen<br /><img src="http://galerie-refugium.de/relaunch/wp-content/themes/gr/layout/images/galerie-aussenansicht.jpg" width="125" /><br /><a target="_blank" href="http://maps.google.de/maps?f=d&source=s_q&hl=de&geocode=&q=Hauptstra%C3%9Fe+3++01458+Medingen&aq=&sll=51.151786,10.415039&sspn=32.299052,52.119141&ie=UTF8&hq=&hnear=Hauptstra%C3%9Fe+3,+Medingen+01458+Ottendorf-Okrilla,+Bautzen,+Sachsen&ll=51.190587,13.792734&spn=0.018827,0.045061&z=14&iwloc=A&daddr=Hauptstra%C3%9Fe+3,+01458+Ottendorf-Okrilla">Anfahrtsroute planen</a></div>';

			var point = new GLatLng(51.18326, 13.79007);
			var marker = new GMarker(point);
			GEvent.addListener(marker, "click", function(){
				marker.openInfoWindowHtml(info);
			});
			map.addOverlay(marker);
			marker.openInfoWindowHtml(info); 
		}
	}
	
}

$(document).ready(function(){
	if (!$.browser.msie)
		GR.initNoMSIE();
	
	if ($.browser.msie)
		if (parseInt($.browser.version, 10) == 7)
			GR.initMSIE7();
	
	GR.init();
	GR.loadMap();
});

$(window).resize(function(){
	GR.resizeImageCol();
});
