// GLOBS 

var windoww = $(window).width();
var windowh = $(window).height();
var u = 875;
var lim = u * -2;
var ml = 0;

// LISTENERS

$(document).ready(function(){
    accSlider();
    setContactMap();
    setFormStuff();
    fadeIt();
    fancyBaby();
    IE6Warning();
    setBgFt();
});

$(window).scroll(function(){
    windoww = $(window).width();
    windowh = $(window).height();
    setBgFt();
});

$(window).resize(function(){
    windoww = $(window).width();
    windowh = $(window).height();
    setBgFt();
});

// FUNCTIONS

function accSlider(){

    $('#right').css('visibility', 'hidden');
    $('#lka_btn').addClass('active');
    
    $('#lka_btn').removeAttr('href').css('cursor', 'pointer').click(function(){
        ml = 0;
        $('#container #aanbod ul li a').removeClass('active');
        $('#lka_btn').addClass('active');
        slideRange();
    });
    $('#lkw_btn').removeAttr('href').css('cursor', 'pointer').click(function(){
        ml = u * -1;
        $('#container #aanbod ul li a').removeClass('active');
        $('#lkw_btn').addClass('active');
        slideRange();
    });
    $('#lbw_btn').removeAttr('href').css('cursor', 'pointer').click(function(){
        ml = lim;
        $('#container #aanbod ul li a').removeClass('active');
        $('#lbw_btn').addClass('active');
        slideRange();
    });
    $('#left').removeAttr('href').css('cursor', 'pointer').click(function(){
        ml -= u;
        slideRange();
    });
    $('#right').removeAttr('href').css('cursor', 'pointer').click(function(){
        ml += u;
        slideRange();
    });
}

function slideRange(){
    if (ml > lim) {
        $('#right').css('visibility', 'visible');
    }
    else {
        $('#left').css('visibility', 'hidden');
    }
    $('#wrapper #slidable').animate({
        'margin-left': ml + 'px'
    });
    if (ml < 0) {
        $('#left').css('visibility', 'visible');
    }
    else {
        $('#right').css('visibility', 'hidden');
    }
    $('#wrapper #slidable').animate({
        'margin-left': ml + 'px'
    });
    if (ml == 0) {
        $('#right').css('visibility', 'hidden');
        $('#left').css('visibility', 'visible');
        $('#container #aanbod ul li a').removeClass('active');
        $('#lka_btn').addClass('active');
    }
    if (ml == lim) {
        $('#left').css('visibility', 'hidden');
        $('#right').css('visibility', 'visible');
        $('#container #aanbod ul li a').removeClass('active');
        $('#lbw_btn').addClass('active');
    }
    if (ml == u * -1) {
        $('#container #aanbod ul li a').removeClass('active');
        $('#lkw_btn').addClass('active');
    }
}

function setBgFt(){
    var bh = $('body').height();
    var df = windowh - bh;
    $('body').css('padding-bottom', df + 'px');
    
    if ($(window).height() + $(window).scrollTop() == $(document).height()) {
        $('#footer').css('text-indent', '0px');
    }
    else {
        $('#footer').css('text-indent', '-9999px');
    }
}


function setContactMap(){

    if ($('#gmap').length) {
        var cdc = new google.maps.LatLng(44.918481, 0.5235216);
        var stylez = [{
            featureType: "all",
            elementType: "all",
            stylers: [{
                hue: "#699015"
            }, {
                saturation: 0
            }, {
                lightness: 0
            }, {
                gamma: 0.5
            }]
        }];
        
        var mapOptions = {
            zoom: 12,
            center: cdc,
            disableDefaultUI: true,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            navigationControl: true
        };
        map = new google.maps.Map(document.getElementById("gmap"), mapOptions);
        
        var styledMapOptions = {
            map: map,
            name: "CdC"
        }
        
        var cdcMapType = new google.maps.StyledMapType(stylez, styledMapOptions);
        
        map.mapTypes.set('CdC', cdcMapType);
        map.setMapTypeId('CdC');
        
        var image = 'gfx/marker.png';
        var marker = new google.maps.Marker({
            position: cdc,
            map: map,
            title: "Chateau de Corail",
            icon: image
        });
        
        google.maps.event.addListener(marker, 'click', function(){
            window.location.href = 'http://maps.google.be/maps?f=q&source=s_q&hl=nl&q=24140+Queyssac,+Frankrijk';
        });
        
    }
}

function setFormStuff(){
	
		
    var va = [];


    $('.textfield').each(function(){
    	
		va.push($(this).val());
		
        var origval = $(this).val();
        $(this).focusin(function(){
            if ($(this).val() == origval) {
                $(this).val('');
            }
        });
        $(this).focusout(function(){
            if ($(this).val() == "" || $(this).val() == origval) {
                $(this).val(origval);
            }
        });
        
    });
	
	$('#reserveer').click(function(){

        var validated = true;
        
        $('.textfield').each(function(){
        
            if ($(this).val() == "" || $.inArray($(this).val(), va) != -1) {
                $(this).addClass('emptyfield');
                validated = false;
            }
            else {
                $(this).removeClass('emptyfield');
            }
        });
        
        
        if (validated == true) {
            $('#frmReserveer').submit();
        }
    });
}


function fadeIt(){
    $('#aanbod').hide().fadeIn('slow');
}

function fancyBaby(){
    $('#gallery a, #ligging_tn a').fancybox();
}


//IE6 is golden <3

function IE6Warning(){

    if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) < 7) {
		$('#oldIE').html("<h3>We're sorry. You are using Internet Explorer 6. This browser is inferior, old and unsafe. You want to vote? Click here to update to a modern browser, and a better surfing experience.</h3>");
        $('#oldIE').css('cursor', 'pointer').fadeIn();
        $('#oldIE').click(function(){
            top.location.href = "http://www.browserchoice.eu";
        });
        $('*').css('overflow', 'hidden');
    }
}

