// JavaScript Document

$(document).ready(function() {

    Cufon.replace('#menu a.replc', { hover: true });
    Cufon.replace('.lblbig h1');
    Cufon.replace('.lbl660 h2');
    Cufon.replace('.lbl640g h2');
    Cufon.replace('.lbl640 h2');
    Cufon.replace('.lbl300g h2');
    Cufon.replace('.lbl300 h2');
    Cufon.replace('.blankwidebalk h1');
    Cufon.replace('.lbldarkgrey320 h2');
    Cufon.replace('.lbldarkgrey300 h2');
    Cufon.replace('#homebox_bedrijfsprofiel h2')
    $('.filterbox').jqTransform();
    $('.form').jqTransform();

    //$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  

    $("ul.topnav .sub").mouseover(function() {

        //Following events are applied to the subnav itself (moving subnav up and down)  
        $(this).find(".subnav").show(); //Drop down the subnav on click  

        $(this).parent().hover(function() {
        }, function() {
            $(this).find(".subnav").hide(); //When the mouse hovers out of the subnav, move it back up  
            $(this).addClass("selected");
        });

        //Following events are applied to the trigger (Hover events for the trigger)  
    }).hover(function() {
        $(this).find("a").addClass("selected"); //On hover over, add class "subhover"  
    }, function() {  //On Hover Out  
        $(this).find("a").removeClass("selected"); //On hover out, remove class "subhover"  
        $(this).find(".subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up  
    });

    $("ul.topnav .nonsub").mouseover(function() {

        //Following events are applied to the trigger (Hover events for the trigger)  
    }).hover(function() {
        $(this).find("a").addClass("nonsubselected"); //On hover over, add class "subhover"  
    }, function() {  //On Hover Out  
        $(this).find("a").removeClass("nonsubselected"); //On hover out, remove class "subhover"  
    });

    // custom easing called "custom"
    $.easing.custom = function(x, t, b, c, d) {
        var s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    }

    $(".display").scrollable({
        easing: 'swing',
        circular: true,
        size: 1,
        clickable: false,
        speed: 1500,
        onBeforeSeek: function(event, index) {
            /*var allkeys = [];
            for (var key in event) {
            if (event.hasOwnProperty(key)) {
            allkeys.push(key + " = " + event[key]);
            }
            }
            if (++showcount < 3) { 
            alert(allkeys); 
            }*/
            if (!($('#datablock' + index).hasClass('first'))) {
                $('.scroller .textoverlay').fadeIn('slow', function() {
                    $('.scroller .content').hide();
                    $('#datablock' + index).find('.content').show();
                    $('.scroller .textoverlay').fadeOut('slow');
                })
                $('.scroller #datablock0').removeClass('first');
            }
        },
        onSeek: function(event, index) {

        }
    }).autoscroll({ interval: 7000 });


    $(".homebox .blankwidebalk a").hover(function() {
        if (!$(this).hasClass("active")) {
            $(this).addClass("hover");
        }
    }, function() {
        if (!$(this).hasClass("active")) {
            $(this).removeClass("hover");
        }
    });


    $(".homebox .blankwidebalk a").click(function() {
        //homebox_
        $(".homebox .blankwidebalk a").each(function() {
            $(this).removeClass("active");
            $(this).removeClass("hover");

            var className = "homebox_" + $(this).attr("class").replace("sprites", "").replace("active", "").replace(' ', '');
            //if (className && className.length > 0) { className = className.trim(); }
            if (!$("#" + className).hasClass("hidden")) {
                $("#" + className).addClass("hidden")
            }
        });

        var className = "homebox_" + $(this).attr("class").replace("sprites", "").replace("active", "").replace(' ', '');
        $(this).addClass("active");
        if ($('#' + className).hasClass("hidden")) {
            $('#' + className).removeClass("hidden");
        }

        return false;
    });

    $(".SpotlightBox .greywidebalk a").click(function() {
        //homebox_
        $(".SpotlightBox .greywidebalk a").each(function() {
            $(this).removeClass("active");
            $(this).removeClass("hover");

            var className = "SpotlightBox_" + $(this).attr("class").replace("sprites", "").replace("active", "").replace(' ', '');
            if (!$("#" + className).hasClass("hidden")) {
                $("#" + className).addClass("hidden")
            }
        });

        var className = "SpotlightBox_" + $(this).attr("class").replace("sprites", "").replace("active", "").replace(' ', '');
        $(this).addClass("active");
        if ($('#' + className).hasClass("hidden")) {
            $('#' + className).removeClass("hidden");
        }

        return false;
    });

    // custom easing called "custom"
    $.easing.custom = function(x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    }



    $(".scrollable").scrollable({ easing: 'custom', speed: 2000, circular: true });

    $('.HelpButtons a').click(function() {
        var link = this.href;
        var title = this.title;
        _gaq.push(['_trackEvent', title, , link]);
    });

});

function resetTeamFoto(id){
	grayscale.reset( $('#img_'+id) );
	$('#bar_'+id).removeClass("whitebar");
	$('#bar_'+id).addClass("transbar");
	
	$('#function_'+id).removeClass("function");
	$('#function_'+id).addClass("functionMO");
	
}

function grayscaleTeamFoto(id){
	grayscale( $('#img_'+id) );
	$('#bar_'+id).removeClass("transbar");
	$('#bar_'+id).addClass("whitebar");
	
	$('#function_'+id).removeClass("functionMO");
	$('#function_'+id).addClass("function");
}

function openTeamProfile(o) {

	return hs.htmlExpand(o, { contentId: 'my-content', objectType: 'iframe', captionEval: '', width: 480, wrapperClassName: 'titlebar', align : 'center' });
}

function openVacancyContacPerson(o) {
	return hs.htmlExpand(o, { contentId: 'my-content', objectType: 'iframe', captionEval: '', width: 430, wrapperClassName: 'titlebar', align: 'center', preserveContent: true });
}

function openForm(o) {
  return hs.htmlExpand(o, { contentId: 'my-content', objectType: 'iframe', captionEval: '', width:780, wrapperClassName: 'titlebar', align: 'center'});
}

function openBlog(id, prefix) {
    // close all items with this prefix.
    $('.' + prefix).hide();
    // open item with id specified.
    $('#' + prefix + '-' + id).show();
}

function getCases(form,cont,deselect) {
    setTimeout("getCasesHandler('" + form + "','" + cont +"','" + deselect + "')", 100);
}

function getCasesHandler(form,cont,deselect){
    deSelect(deselect);
    var obj = document.getElementById(form)    
    $.ajax({
        type: "GET",
        url: PATH_LANG + "xml/GetCases",
        data: $(obj).serialize(),
        success: function(theResponse) {
            //$(form).hide();
            $("#" + cont).html(theResponse);            
        }
    });
}

function deSelect(name) {
    if (name != '') {
        $('input[id ^=' + name + ']').each(function() {
            $(this).attr('checked', '');
            $(this).prev().removeClass("jqTransformChecked");
            $(this).prev().addClass("jqTransformUnChecked");
        });
    }

}

function setChecked(form,cont,el,name1,name2) {
    deSelect(name1);
    deSelect(name2);    
    $('#' + el).attr('checked', 'checked');
    $('#' + el).prev().addClass("jqTransformChecked");
    getCases(form, cont, '');

    return false;
  }

  function initialize() {
    var myLatlng = new google.maps.LatLng(52.0642355, 5.3740888);
    var myOptions = {
      zoom: 16,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("MapContainer"), myOptions);
    
    var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: "Tuindorpweg 23, Maarn"
    });   
  }

  function contactForms(Option) {
    if (Option == 'CallMe') { // CALLME openen
      if ($("#contactContainer").hasClass("none")) { // als de box op display none staat;

        $("#CallMeBtn").removeClass("close")
        $("#CallMeBtn").addClass("open")

        $("#MessageBtn").removeClass("open")
        $("#MessageBtn").addClass("close")
        
        $("#MessageContainer").removeClass("block")
        $("#MessageContainer").addClass("none")

        $("#contactContainer").removeClass("none")
        $("#contactContainer").addClass("block")


      }
    } else if (Option == 'Message') {
    if ($("#MessageContainer").hasClass("none")) { // als de box op display none staat;

      $("#CallMeBtn").removeClass("open")
      $("#CallMeBtn").addClass("close")

      $("#MessageBtn").removeClass("close")
      $("#MessageBtn").addClass("open")

      $("#contactContainer").removeClass("block")
      $("#contactContainer").addClass("none")
      
        $("#MessageContainer").removeClass("none")
        $("#MessageContainer").addClass("block")
      }
    }
  }
