$(document).ready(
	function()
	{
		if ($.browser.version.charAt(0) < 7 && $.browser.msie){$("#mainnav li, #subnav li").hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});}
		//doFlash();
         
        doMap();
        bindTabs();
        
        doTellaFriend();
        
        $().piroBox({
			my_speed: 400, //animation speed
			bg_alpha: 0.1, //background opacity
			slideShow : false, // true == slideshow on, false == slideshow off
			slideSpeed : 4, //slideshow duration in seconds(3 to 6 Recommended)
			close_all : '.piro_close,.piro_overlay'// add class .piro_overlay(with comma)if you want overlay click close piroBox
    	});
        
        $(".linkSubmit").click(function(e){
            e.preventDefault();
            $(this).parents().submit();            
        });
	}
);

function doMap()
{
    var coordinaten = $(".mapsCoordinateLong").html();
    
    if(coordinaten == null | coordinaten == ""){
        $("#googleMaps").css("display", "none");
    }else{
        //var coordinatenSplit = coordinaten.split(',');
        var map;
        var titel       = $("h1").html();
        //var geocoder    = new google.maps.Geocoder();
        
        var corLong     = $(".mapsCoordinateLong").html();
        var corLat      = $(".mapsCoordinateLat").html();
        
        var latlng      = new google.maps.LatLng(corLat,corLong);
        var myOptions = {
            zoom: 13,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        
        map = new google.maps.Map(document.getElementById("googleMaps"), myOptions);
        
        //google.maps.event.trigger(map, 'resize');
        
        infowindow = new google.maps.InfoWindow({
            content: "loading..."
        });
        
        var marker = new google.maps.Marker({
            position:   new google.maps.LatLng(corLat,corLong), 
            map:        map, 
            title:      titel,
            icon:       '/gfx/tmpl/map_marker.png' /*,
            html:       '<div class="infowindowContent">'+
                            '<div class="siteNotice"></div>'+
                            '<h1 class="firstHeading">Apenheul</h1>'+
                            '<div class="bodyContent">'+
                                '<p>Apeldoorn</p>'+
                            '</div>'+
                          '</div>' */
        });
        
        
        
        google.maps.event.addListener(marker, "click", function () {
            infowindow.setContent(this.html);
            infowindow.open(map, this);
        });
        
        
    }        
    
}


function bindTabs()
{
    $(".tab-navigation li a").click(
		function(e)
		{
			e.preventDefault();
            
            $(this).parent().parent().children().removeClass("active");
            $(this).parent().addClass("active");
            
            $(".tab-content").removeClass("active");
            $($(this).attr("href")).addClass("active");
            
            if($(this).attr("href") == "#tab_algemeen")
            {
                doMap();
            }
		}
	);
}

function doTellaFriend()
{
    //Uitlijnen    
    $("#btn-tell-a-friend").click(function(e){
        e.preventDefault();
        positioningModal();
        $("#tell-a-friend-modal").fadeIn(200);
        $(".modal-bg").fadeIn(200);  
    });
    
    $(".modal-bg,.modal-close").click(function(){
        $(".modal-content-wrapper").fadeOut(100);
        $(".modal-bg").fadeOut(100);  
    });

}

function positioningModal()
{

    $(".modal-bg").css("width",$(window).width());
    $(".modal-bg").css("height",$(window).height());
    
    nwLeft = ($(window).width() / 2) - ($(".modal-content-wrapper").width() / 2);
    $(".modal-content-wrapper").css("left", nwLeft);
    
}
