/* Copyright (C) Tim Portner (mail@timportner.de) */
$(document).ready(function () {
    startUp();
    $(".nojs").removeClass("nojs");
    $("body").append("<div id='timer'></div>");
    var timer = $("#timer");

    $("#nav ul li ul li:first-child a").css({ "border-top": "none" });
    $("#partner img").hover(function () { $(this).animate({ opacity: 0.5 }, 400) }, function () { $(this).animate({ opacity: 1.0 }, 600); });
});

 
// AK -->
// Function called to set click event listeners  AND  implement the plugin init functions
function startUp() {
    $('#info div.calendar span[title],#sidebar a[title],#sidebar span[title],table.tblTurniere a[title]').tooltip({ track: true, delay: 0, showURL: false, showBody: "", fade: 250 });
    $("a.anmelden").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'hideOnContentClick': false, 'overlayShow': true, 'frameWidth': 402, 'frameHeight': 355, 'overlayColor': "#000" });

    $(".bigbox p.month_nav a").live("click", function (e) { 
        var link = $(this); var box = $(".bigbox .ajax_calendar"); box.addClass("load");
        box.load(link.attr('href'), function () { box.removeClass("load"); startUp(); });  
		return false;
    });


    //
    //
	// Update the jQuery ajax load() method for ie     -->
    $("#sidebar p.month_nav a").live("click", function (e) {
        var link = $(this); 
		var cal = $(".tunieruebersicht");
		var sidebar = $("#sidebar .ajax_calendar");
		
		//Replace, cause we want the main_content to replace with ajax, not the sidebar!! 
		var action = link.attr("href").replace("glc_calender", "ajax");
        cal.addClass("load"); 
		sidebar.addClass("load");


		cal.load(action , function () { 
			cal.removeClass("load"); 
			sidebar.load(link.attr("href") , function () { 
				sidebar.removeClass("load"); 
				startUp(); 
			});
		 });		
        return false;
    });    
	// <-- End Update 
	//
	//   
	

    $("#sidebar p.kw_nav a[href]").live("click", function (e) {  
	    //alert($(this)+" CLICKED"); 
        var link = $(this); var sidebar = $("#sidebar .ajax_calendar");
        sidebar.addClass("load"); sidebar.load(link.attr("href"), function () { sidebar.removeClass("load"); startUp(); });
        return false;
    });
} 

// <-- AK

function slideSwitch() {
    var $active = $('#teaser .headers img.active');
    if ($active.length == 0) $active = $('#teaser .headers img:last');
    var $next = $active.next("img").length ? $active.next("img") : $('#teaser .headers img:first');
    $active.addClass('last-active');
    $active.animate({ opacity: 0.0 }, 3000);
    $next.css({ opacity: 0.0 }).addClass('active').animate({ opacity: 1.0 }, 3000, function () { $active.removeClass('active last-active') })
};

function loadGalleryNav() {
    var $items = $(".head_birdiecard").find("img").length; var $lnkitem = "";
    $(".head_birdiecard img").each(function (i) { $lnkitem += "<li><a href='javascript:;' rel='" + i + "'>" + i + "</a></li>" });
    $(".head_birdiecard .ulitem").html("<ul>" + $lnkitem + "</ul>");
};


	
function googlemapsLoader() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(50.556086, 7.185217), 13);
		var point1 = new GPoint(7.185217,50.556086);
		var windowHtml = "<div class='small' style='width: 250px'><strong>Golf- und Landclub Bad Neuenahr-Ahrweiler</strong><br />Grosser Weg 100<br />53474 Bad Neuenahr-Lohrsdorf<br />Telefon: 0 26 41 / 95 09 50<br />Fax: 0 26 41 / 9 50 95 95<form name='search_route' method='get' action='http://maps.google.de/' target='_blank'><input name='saddr' type='text' id='saddr' value='Ihre Adresse'><input name='daddr' type='hidden' id='daddr' value='Großer Weg, 53474 Bad Neuenahr-Ahrweiler, Deutschland'><input type='submit' name='Submit' value='Route berechnen'></form><p><br class='clear' /></p></div>";
		var beck = new GMarker(point1);
		GEvent.addListener(beck, "click", function() {beck.openInfoWindowHtml(windowHtml)});
		map.addOverlay(beck);
		map.openInfoWindowHtml(map.getCenter(), windowHtml);
	}
}
