// mouseover kleur cases rechterkolom //
var sCaseEssent = "#aa014c";
var sCaseKraanwater = "#00bbf4";
var sCaseStudentalent = "#e30083";
var sCaseDeltaLloyd = "#00579b";
// --------- //

$(function() {
	$('a.media').media({
		caption: false
	});
});

$(document).ready(function() {

	$("#thumbnails a").live("click", function() {
		$(".modGoogle").css("visibility","hidden")
	});

	$("div:last").live("click", function() {
		$(".modGoogle").css("visibility","visible")
	});

    if ($("#jMonthCalendar").length > 0) {
        $.datepicker.regional['nl'] = { clearText: 'Wissen', clearStatus: '',
            closeText: 'Sluiten', closeStatus: 'Sluiten zonder op te slaan',
            prevText: 'Vorige', prevStatus: 'Laat de vorige maand zien',
            nextText: 'Volgende', nextStatus: 'Laat de volgende maand zien',
            currentText: 'Vandaag', currentStatus: 'Laat de huidige maand zien',
            monthNames: ['JANUARI', 'FEBRUARI', 'MAART', 'APRIL', 'MEI', 'JUNI',
			        'JULI', 'AUGUSTUS', 'SEPTEMBER', 'OKTOBER', 'NOVEMBER', 'DECEMBER'],
            monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun',
			        'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'],
            monthStatus: 'Laat een andere maand zien', yearStatus: 'Laat een ander jaar zien',
            weekHeader: 'Wk', weekStatus: '',
            dayNames: ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
            dayNamesShort: ['Zon', 'Maa', 'Din', 'Woe', 'Don', 'Vri', 'Zat'],
            dayNamesMin: ['ZO', 'MA', 'DI', 'WO', 'DO', 'VR', 'ZA'],
            dayStatus: '', dateStatus: '',
            dateFormat: 'dd/mm/yyyy',
            firstDay: 1,
            initStatus: 'Kies een datum', isRTL: false
        };
        

        $.datepicker.setDefaults($.datepicker.regional['nl']);
    
        //$("#jMonthCalendar").datepicker({});

        updateEvents();

        $("#linkOpenCalendar").toggle(function() {
            $("#jMonthCalendar").slideDown();
            return false;
        }, function() {
            $("#jMonthCalendar").slideUp();
        });

        $("#btnUp").live("click", function() {
            $("#jMonthCalendar").slideUp();
            return false;
        });
    }

    if ($("#thumbnails").length > 0) {
        $("#thumbnails").find("a").overlay({
            target: '#gallery',
            expose: {
                color: '#000',
                opacity: 0.5
            },
            closeOnClick: true
        }).gallery({
            disabledClass: 'inactive'
        });
    }



    $("p:empty").hide();
    $.ifixpng("/images/blank.gif");
    $("img").ifixpng();
    $(function() {
        $.nyroModalSettings({
            minWidth: 230,
            minHeight: 26,
            swf: { // Swf player options if swf type is used.
                wmode: 'opaque'
            },
            padding: 5
        });

    });


    $("#tabber").tabs({
        fx: { height: 'toggle' },
        select: function(e, ui) {
            $("#tabber a").each(function() {
                $(this).css({ backgroundColor: "#1a181b" })
            });
            $(ui.tab).
			animate({
			    backgroundColor: "#555555"
			}, { duration: 200 }).
			animate({
			    backgroundColor: "#303030"
			}, { duration: 400 })
        }
    });

    $("div.scrollable").scrollable({
        size: 3,
        clickable: false,
        easing: "swing"
    });

    $("div.scrollable4").scrollable({
        size: 1,
        clickable: false,
        easing: "swing"
    });

    $("div.scrollable2").scrollable({
        size: 1,
        clickable: false,
        easing: "swing",
        items: ".items2",
        prev: ".prev2",
        next: ".next2",
        onSeek: function() {
            if ($(".next2:eq(0) img[src*='english']").length > 0) {
                if ((this.getIndex() > 0) && (this.getIndex() < this.getPageAmount() - 1)) {
                    $(".next2:eq(0)").find("img").attr("src", "/images/btn_middel_volgende_zwart_english.png");
                    $("img").ifixpng();
                }

                if (this.getIndex() == 0) {
                    $(".next2:eq(0)").find("img").attr("src", "/images/btn_middel_volgende_english.png");
                    $("img").ifixpng();
                }

                if (this.getIndex() == this.getPageAmount() - 1) {
                    $(".next2:eq(0)").find("img").attr("src", "/images/btn_middel_volgende_disabled_english.png");
                    $("img").ifixpng();
                }
            }
            else {
                if ((this.getIndex() > 0) && (this.getIndex() < this.getPageAmount() - 1)) {
                    $(".next2:eq(0)").find("img").attr("src", "/images/btn_middel_volgende_zwart.png");
                    $("img").ifixpng();
                }

                if (this.getIndex() == 0) {
                    $(".next2:eq(0)").find("img").attr("src", "/images/btn_middel_volgende.png");
                    $("img").ifixpng();
                }

                if (this.getIndex() == this.getPageAmount() - 1) {
                    $(".next2:eq(0)").find("img").attr("src", "/images/btn_middel_volgende_disabled.png");
                    $("img").ifixpng();
                }
            }
        }
    });

    $(".modCase").hover(
	    function() {
	        if ($(this).find("img").hasClass("imgLeft")) {
	            bgColor = $(this).find("input.color").val();
	            $(this).stop().animate({ backgroundColor: bgColor }, { duration: 200 });
	            $(this).find(".imgLeft").attr("src", $(this).find(".imgLeft").attr("src").replace(".jpg", "_mo.jpg"));
	        }
	    },
	    function() {
	        if ($(this).find("img").hasClass("imgLeft")) {
	            $(this).stop().animate({
	                backgroundColor: "#000000"
	            }, { duration: 800 });
	            $(this).find(".imgLeft").attr("src", $(this).find(".imgLeft").attr("src").replace("_mo", ""));
	        }
	    }
	);

    $(".modContact").find("input, textarea").focus(function() {
        $(this).stop().animate({
            borderLeftColor: "#dc00ff",
            borderTopColor: "#dc00ff",
            borderRightColor: "#dc00ff",
            borderBottomColor: "#dc00ff"
        }, { duration: 400 })
    });
    $(".modContact").find("input, textarea").blur(function() {
        $(this).stop().animate({
            borderLeftColor: "#282828",
            borderTopColor: "#282828",
            borderRightColor: "#282828",
            borderBottomColor: "#282828"
        }, { duration: 800 })
    });

    $("#frmReactie").validate({
        rules: {
            naam: "required",
            bedrijf: "required",
            //telefoon:  "required",
            vraag: "required",
            email: {
                required: true,
                email: true
            }
        }
    });

    $(".modLogin").find("input, textarea").focus(function() {
        $(this).stop().animate({
            borderLeftColor: "#dc00ff",
            borderTopColor: "#dc00ff",
            borderRightColor: "#dc00ff",
            borderBottomColor: "#dc00ff"
        }, { duration: 400 })
    });
    $(".modLogin").find("input, textarea").blur(function() {
        $(this).stop().animate({
            borderLeftColor: "#282828",
            borderTopColor: "#282828",
            borderRightColor: "#282828",
            borderBottomColor: "#282828"
        }, { duration: 800 })
    });

    $("#frmLogin").validate({
        rules: {
            inpUsername: "required",
            inpPassword: "required"
        }
    });

    jQuery.validator.addMethod("defaultInvalid", function(value, element) {
        return value != element.defaultValue;
    }, "");

    $("#btn_verstuur").click(function() {
        if (!$("#frmReactie").valid()) {
            $.prompt("Niet alle gegevens zijn correct ingevuld. Probeer het opnieuw.");
            return false;
        }
        return true;
    });

    $("#btn_ecenter").click(function() {
        if (!$("#frmLogin").valid()) {
            $.prompt("Niet alle gegevens zijn correct ingevuld. Probeer het opnieuw.");
            return false;
        }
        return true;
    });

    $(".modMensen").hover(
		function() {
		    $(this).
			stop().
			animate({
			    backgroundColor: "#ffffff"
			}, { duration: 200 }).
			find("h2").
			stop().
			animate({
			    color: "#000000"
			}, { duration: 200 })
		},
		function() {
		    $(this).
			stop().
			animate({
			    backgroundColor: "#000000"
			}, { duration: 800 }).
			find("h2").
			stop().
			animate({
			    color: "#ffffff"
			}, { duration: 800 })
		}
	);

    $(".modCaseOverzicht").hover(
		function() {
		    $(this).find(".imgLeft").attr("src", $(this).find(".imgLeft").attr("src").replace(".jpg", "_mo.jpg"));

		    $(this).
			stop().
			animate({
			    backgroundColor: "#ffffff"
			}, { duration: 10 }).
			find("h2").
			stop().
			animate({
			    color: "#000000"
			}, { duration: 10 })
		},
		function() {
		    $(this).find(".imgLeft").attr("src", $(this).find(".imgLeft").attr("src").replace("_mo", ""));
		    if ($(this).hasClass("caseOverzichtEssent")) { $(this).stop().animate({ backgroundColor: sCaseEssent }, 200) }
		    if ($(this).hasClass("caseOverzichtKraanwater")) { $(this).stop().animate({ backgroundColor: sCaseKraanwater }, 200) }
		    if ($(this).hasClass("caseOverzichtStudentalent")) { $(this).stop().animate({ backgroundColor: sCaseStudentalent }, 200) }
		    if ($(this).hasClass("caseOverzichtDeltaLloyd")) { $(this).stop().animate({ backgroundColor: sCaseStudentalent }, 200) }
		    $(this).find("h2").stop().animate({ color: "#ffffff" }, { duration: 800 });
		}
	);


    $("#frmReaction").validate({
        rules: {
            Name: "required",
            Email: "required",
            Reaction: "required"
        }
    });

    $("#frmReaction").find("#Submit").click(function() {
        if ($("#Reaction").val() == "je reactie")
            $("#Reaction").val("");
        if ($("#frmReaction").valid()) {
            $("#frmReaction #Submit").fadeOut();
            var randomnumber = Math.floor(Math.random() * 100001);
            var send = $.post("/Ajax/saveReaction.aspx?randomnumber=" + randomnumber,
                    {
                        Name: $("#Name").val(),
                        Email: $("#Email").val(),
                        Id: $("#Id").val(),
                        Type: $("#Type").val(),
                        Reaction: $("#Reaction").val()
                    },
                    function(data) {
                        if (data == "true") {

                            $("#frmReaction").fadeOut();
                            $("#cntReactionThanks").fadeIn();
                            var currenturl = $("#Redirect").val();
                            $(this).oneTime(3000, function() {
                                if (currenturl != "" && currenturl != undefined)
                                    document.location = currenturl;
                                else
                                    document.location = "/";
                            });
                        }
                        else {
                            $("#frmReaction #Submit").fadeIn();
                            $("#cntReactionError").fadeIn();
                        }
                    }
                );
            return false;
        }
    });

    $("#showMoreTweets").live("click", function() {
        var lastActive = $(".twitterGroup:visible:last").attr("rel");
        var nextActive = parseInt(lastActive) + 1;
        if ($(".twitterGroup[rel='" + nextActive + "']").length > 0) {
            $(".twitterGroup[rel='" + nextActive + "']").addClass("twitterBusy").slideDown();
            $(this).oneTime(2000, function() {
                $(".twitterGroup[rel='" + nextActive + "']").removeClass("twitterBusy");
                $(".twitterGroup[rel='" + nextActive + "']").find("li").fadeIn("slow");
            });
        }
        else {
            $(this).fadeOut().remove();
        }
        return false;
    });

    //$("img[rel]").overlay({ absolute: true, expose: '#fff', effect: 'apple' });
    $("img[rel]").overlay({
        absolute: false,
        expose: 'transparent',
        effect: 'apple'
        //        onLoad: function() {
        //            $(".modGoogle").css("visibility", "hidden");
        //        },
        //        onClose: function() {
        //            $(".modGoogle").css("visibility", "visible");
        //        }
    });

    //    $("#test").click(function() {
    //    $("img[rel='#1']").overlay({ 
    //        effect: 'apple',
    //        onLoad: function() {
    //            player.load();
    //        },
    //        onClose: function() {
    //            player.unload();
    //        } 
    //        }).load();
    //    });

    /*
    $(".switchMiddel").click(function() {
    var whichMiddel = $(this).parent().prevAll().length + 1;
    $(".modCaseMiddel").hide();
    $(".modCaseMiddel:eq(" + whichMiddel + ")").show();
    return false;
    });
    */
});

function onAfter(curr, next, opts) {
	var index = $(this).parent().children().index(this);
	$('#middelScrollDown')[index == 0 ? 'hide' : 'show']();
	$('#middelScrollUp')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}

function updateEvents() {
    var randomnumber = Math.floor(Math.random() * 100001);
    var selectedevent = $("#selectedEvent").val();
    $.ajax({
        url: "/Ajax/GetEvents.aspx?randomnumber=" + randomnumber,
        data: "",
        dataType: "json",
        success: function(calendarEvents) {
            $("#jMonthCalendar").datepicker({
                // [rows, columns] if you want to display multiple calendars.                         
                //numberOfMonths: [1, 1],
                showCurrentAtPos: 0,
                beforeShowDay: function(date) {
                    for (i = 0; i < calendarEvents.length; i++) {
                        if (date.getMonth() == calendarEvents[i][0] - 1
                          && date.getDate() == calendarEvents[i][1]
                          && date.getFullYear() == calendarEvents[i][2]) {
                            var classname = "pink";
                            if (calendarEvents[i][3] == selectedevent) {
                                classname += " selected";
                            }
                            //[disable/enable, class for styling appearance, tool tip]
                            return [true, classname, "" + calendarEvents[i][3] + ""];
                        }
                    }
                    return [false, ""]; //enable all other days
                },
                onSelect: function(dateText, inst) {
                    var selectedDay = parseInt(dateText.split('/')[0]);
                    var name = $("#jMonthCalendar").find("a:contains('" + selectedDay + "')").parent().attr("title");
                    if (name != "") {
                        document.location = "/zeilen/evenementen/" + name;
                    }
                }

            });
        }
    });
}
