$(document).ready(function() {

    $('.twitter').hover(
		function() {
		    var imgsrc = this.src;
		    if (!imgsrc) imgsrc = '';
		    if (imgsrc.indexOf('_on.png') == -1) {
		        imgsrc = imgsrc.replace('.png', '_on.png');
		        this.src = imgsrc;
		    }
		},
		function() {
		    var imgsrc = this.src;
		    imgsrc = imgsrc.replace('_on.png', '.png');
		    this.src = imgsrc;
		}
	);

    //homepage overlay
    $('#home-overlay').find('a').each(function() {
        return hs.htmlExpand(this, { contentId: 'my-content-homepage', width: '660', outlineType: null, targetY: 'menu', targetX: 'menu 160px', allowWidthReduction: true, wrapperClassName: 'my-homepage' })
    });

    //Hoofdnavigatie mouseovers
    $("#menu li:not(#menu li li)").hover(
		function() {
		    var imgsrc = $(this).find('img').attr("src")
		    if (imgsrc.indexOf('-on.gif') == -1) {
		        imgsrc = imgsrc.replace('.gif', '-on.gif');
		        $(this).find('img').attr('src', imgsrc);
		    }
		    if ($(this).find('ul').size() > 0) {
		        $('body').addClass('bg-subnav');
		        $('.breadcrumb').hide();
		    };

		    $(this).addClass('hover');
		},
		function() {
		    var thisclass = $(this).attr("class")
		    if ($(this).attr('class').indexOf('active') == -1) {
		        var imgsrc = $(this).find('img').attr("src").replace('-on.gif', '.gif');
		        $(this).find('img').attr('src', imgsrc);
		    }
		    $('body').removeClass('bg-subnav');
		    $(this).removeClass('hover')
		    $(this).parent().attr('class', '');
		    $('.breadcrumb').show();
		}
	);

    //Banners mouseovers
    $(".businessclubs li").hover(
		function() { $(this).attr('class', 'active'); },
		function() { $(this).attr('class', ''); }
	);

    //tabs. worden getoond op de homepage en op nieuws
    $(".tab").click(function() {
        //close all
        $("#newscategories .tab").each(function() {
            $(this).removeClass('tab-act');
            $(this).removeClass('tab-hover');

            var curId = $(this).attr("id");
            $('#' + curId + '_items').css("display", "none");
        });
        //zet de huidige tab op actief
        $(this).addClass('tab-act');
        var curId = $(this).attr("id");
        $('#' + curId + '_items').css("display", "inline");
    }
	);

    //Tabs mouseovers
    $(".tab").hover(
		function() {
		    if ($(this).attr("class").indexOf('act') == -1) {
		        $(this).attr('class', 'tab tab-hover');
		    }
		},
		function() {
		    if ($(this).attr("class").indexOf('act') == -1) {
		        $(this).attr('class', 'tab');
		    }
		}
	);

    //Banners mouseovers
    $(".newslist li").hover(
		function() {
		    if ($(this).attr('class').indexOf('noborder') > -1) {
		        $(this).attr('class', 'noborder act');
		    } else {
		        $(this).attr('class', 'act');
		    }
		},
		function() {
		    if ($(this).attr('class').indexOf('noborder') > -1) {
		        $(this).attr('class', 'noborder');
		    } else {
		        $(this).attr('class', '');
		    }
		}
	);

    $(".showborder li").hover(
		function() { $(this).addClass('act'); },
		function() { $(this).removeClass('act'); }
	);

    //Agenda mouseovers
    $(".agenda li").hover(
		function() { $(this).attr('class', 'act'); },
		function() { $(this).attr('class', ''); }
	);

    //Fotos mouseovers
    $(".photos div").hover(
		function() { $(this).attr('class', 'act'); },
		function() { $(this).attr('class', ''); }
	);

    //Fotos mouseovers
    $(".items div").hover(
		function() { $(this).attr('class', 'act'); },
		function() { $(this).attr('class', ''); }
	);


    $("#btn-showMenu").click(function() {
        if ($(".showMenu").css("display") == 'none') {
            $(".showMenu").slideDown("slow");
            var imgsrc = $(this).attr("src").replace('.png', '-off.png');
            $(this).attr('src', imgsrc);
        } else {
            $(".showMenu").slideUp("slow");
            var imgsrc = $(this).attr("src").replace('-off.png', '.png');
            $(this).attr('src', imgsrc);
            if ($("#forgotPass").css("display") == 'block') {
                $("#showForgotPass").show();
                $('#lbl-forgotpass').hide();
                $("#forgotPass").hide();
            }
        }

    }
	);
    $("#showForgotPass").click(function() {
        $(this).hide();
        $('#lbl-forgotpass').show();
        $("#forgotPass").slideDown("slow");
        return false;
    }
	);

    //Paging mouseovers
    $("td.page").hover(
		function() {
		    $(this).attr('class', 'hover');
		},
		function() {
		    $(this).attr('class', '');
		}
	);

    $(".btnOrange").hover(
		function() { $(this).addClass('act'); },
		function() { $(this).removeClass('act'); }
	);

    var registerIsSliding = false;
    $(".register .open").add(".register .title a").click(function() {
        //click staat op het pijltje, zoek hiervan de bovenliggende listitem
        var obj = ($(this).closest('li'));
        //Check of deze listitem al op active staat of al aan het sliden is
        if ($(obj).attr("class") != 'act' && !registerIsSliding) {
            //huidige functie wordt uitgevoerd. deze mag pas weer uitgevoerd worden als de huididige functie klaar
            registerIsSliding = true;
            //verwijder de class 'act' van alle listitems
            $(".register li").removeClass('act');
            //en zet de huidie listitem op class 'act'
            $(obj).addClass('act');
            //zet alle profielen op display none
            $('.showProfile').hide();

            //verberg alle sluitknoppen
            $('.close').hide();
            //toon de sluitknop
            $(obj).find('.close').show();

            //wijzig het pijltje
            //Zoek naar alle afbeeldingen binnen de div met class open
            var arrow = ($('.open').find('img'));
            //zet de afbeeldingen op btn-closeprofile ipv openprofile
            if (arrow.attr('src')) {
                var imgsrc = (arrow.attr('src').replace('close', 'open'));
                $(arrow).attr('src', imgsrc);

                //dit is het pijltje binnen het listitem, die moet op closeprofile worden gezet
                arrow = ($(obj).find('.open').find('img'));
                //zet de afbeeldingen op btn-openprofile ipv closeprofile
                imgsrc = (arrow.attr('src').replace('open', 'close'));
                $(arrow).attr('src', imgsrc);
                //animeer de profieldetails en geef een seintje als de functie klaar is, zodat hij weer uitgevoerd kan worden
                $(obj).find('.showProfile').slideDown("slow", function() { registerIsSliding = false });
            } else {
                return true;
            }
        }
        return false;
    }
	);
    $(".register .close a").click(function() {
        $(".register li").removeClass('act');
        $('.showProfile').hide();
        $('.close').hide();
        //wijzig het pijltje
        //Zoek naar alle afbeeldingen binnen de div met class open
        var arrow = ($('.open').find('img'));
        //zet de afbeeldingen op btn-closeprofile ipv openprofile
        var imgsrc = (arrow.attr('src').replace('close', 'open'));
        $(arrow).attr('src', imgsrc);

        $('.email').show();
        return false;
    }
	);

    //Banners mouseovers
    $(".tabs div").hover(
		function() {
		    if ($(this).attr("class") != 'act') {
		        $(this).addClass('hover');
		    }
		},
			function() { $(this).removeClass('hover'); }
	);
})

function mOn(obj) {
	var ext = obj.src.slice(-3)
	if(obj.src.indexOf('-on.'+ ext)==-1){
		obj.src=obj.src.replace('.'+ ext,'-on.'+ ext)
	}
}
function mOut(obj) {
	var ext = obj.src.slice(-3)
	obj.src=obj.src.replace('-on.'+ext,'.'+ext)
}

function getQ(id, selector) {
    var q = '';
    var i = 0;
    $('#' + id).find('input').each(function() {
        if (i > 0) { q += '&' }
        i++;
        q += $(this).attr('name') + '=' + $(this).val();
    })
    return q
}

function loginUser(path, id) {
    $.ajax({
        type: "POST",
        url: path + 'Users/Login/',
        data: getQ(id, 'input'),
        dataType: "html",
        success: function(html) {
            if (html == 'OK') {
                location.reload();
            } else {
                $('#' + id + '-result').html(html);
            }
        }
    });
}

function passwordUser(path, id) {
    $.ajax({
        type: "POST",
        url: path + 'Users/SendPassword/',
        data: getQ(id, 'input'),
        dataType: "html",
        success: function(html) {
            $('#'+ id +'-result').html(html);
        }
    });
}

function printme() {
    var objOut = document.getElementById("output");
    var out = objOut.innerHTML;

    var wh = window.open("", "wh", "width=640px,height=480px,scrollbars=yes");
    wh.document.open();
    var outputhead = '<link href="' + PROJECT_URL + 'content/css/print.css" rel="stylesheet" type="text/css">';
    var output = '<html><head>' + outputhead + '</head><body>' + out + '</body></html>';
    output += '<' + 'script type="text/javascript">';
    output += 'setTimeout("window.print()",50);';
    output += '</' + 'script>';
    wh.document.writeln(output);
    wh.document.close();
}

function ifOpen(obj, selector) {
    //reset all
    $(selector + ' input').each(function() {
        $('#'+this.id + '_cont').css('display', 'none');
    })
    if ($(selector + ' input:checked').val() == obj.value) {    
        $('#'+ obj.id + '_cont').css('display', 'block');
    } else {
        $('#' + obj.id + '_cont').css('display', 'none');
    }
}

function MouseOver(obj) {
    obj = document.getElementById(obj)
    if (obj) {
        if (obj.src.indexOf('_on') > -1) {
            obj.src = obj.src.replace('_on.png', '.png')
        } else {
            obj.src = obj.src.replace('.png', '_on.png')
        }
    }
    obj.src = obj.src.replace('_on.png', '.png')
}



//Bereken van de hoogte van het Iframe, en de hoogte van het meegegeven object hierop aanpassen
function calcFrameHeight(framePage, iframeID) {
    try {
        if (navigator.userAgent.indexOf("MSIE") > -1) {
            /* IE */
            var FramePageHeight = document.getElementById(framePage).scrollHeight + 60;
            parent.document.getElementById(iframeID).style.height = FramePageHeight;
        }
        else {
            /* andere browser */
            var FramePageHeight = document.getElementById(framePage).scrollHeight + 60 + "px";
            parent.document.getElementById(iframeID).style.height = FramePageHeight;
        }
        return false;
    }
    catch (err) {
        return false;
    }
}
//einde brekenen hoogte iFrame

