function wrapCufon() {
    jQuery("h1, h2, h3").not(jQuery(".articlelistblock h3")).each(function () {
        var t = jQuery(this);
        var cufon = jQuery(".cufon cufoncanvas, .cufon canvas", t);
        cufon.wrap('<span class="cufonwrap"></span>')
    });
}

function makeButton(button, not) {
    jQuery(button).not(jQuery(not)).each(function () {
        var button = this;
        var extraClass = "";
        if (button.type != 'hidden') {
            if (button.className != "") {
                extraClass = "wrapper" + button.className;
            }
            jQuery(button).wrap('<span class="candywrapper ' + extraClass + '"></span>');
            jQuery(button).css('color', jQuery(button).css('color'));
        } else {
            jQuery(button).css('display', 'none');
        }
    });
}

function wrapEvents() {
    jQuery('.eventdetail .tabs li').each(function () {
        var liElement = this;
        var tekst = "";
        if (document.all) {
            tekst = liElement.innerText;
        } else {
            tekst = liElement.textContent;
        }

        liElement.innerHTML = "<span>" + tekst + "</span>";

    });
}

function changeForm() {
    jQuery('.surveycontainer .q_multipleresponse').each(
		function () {

		    var t = this;
		    var newDiv = jQuery('<div class="checkboxes">');
		    var spanText = jQuery('.question-text', t);
		    var getTables = jQuery('table', t);
		    var getSelect = jQuery('select', t);
		    var breakIt = jQuery('br', t);
		    var element = new Array;
		    var type = new Array;
		    var aantalChilds;

		    if ((getTables.length + getSelect.length) == 0) {
		        breakIt.remove();
		        aantalChilds = t.childNodes.length;

		        for (var x = 0; x < aantalChilds; x++) {
		            if (t.childNodes[x].tagName == 'INPUT') {
		                element[x] = t.childNodes[x];
		                type[x] = t.childNodes[x].tagName;
		            }

		            if (t.childNodes[x].tagName == "LABEL") {
		                element[x] = t.childNodes[x];
		                type[x] = t.childNodes[x].tagName;
		            }
		        }

		        for (var x = 0; x < aantalChilds; x++) {
		            if (element[x] == 'object');
		            {
		                newDiv.append(element[x]);
		            }
		            if (type[x] == 'LABEL') {
		                newDiv.append(jQuery('<br>'));
		            }
		        }

		        spanText.after(newDiv);
		    }
		}
	);
}

function makeHeight() {
    jQuery('#tl_left, #tl_right, #topright_footer').each(function () {
        var vlak = this;

        if (jQuery('.block-output', vlak).length > 0) {
            jQuery(vlak).addClass('bannerheight');
        }
    });
}

function getThirdElement() {
    jQuery('.searchresultsblock').each(function () {
        var counter = 0;
        var block = this;
        jQuery('.event', block).each(function () {
            var liElement = this;
            counter++;
            if (counter % 3 != 0) {
                jQuery(liElement).addClass('marginevent');
            }
        });
    });
}

function clixmaster() {
    if (jQuery('.mm_wysiwyg_container').length > 0) {
        jQuery('#tlr_header, #tlr_footer').hide();
    }
}

function makeHover() {
    jQuery('.tab-container li').mouseover(function () { jQuery(this).addClass('hover'); }).mouseout(function () { jQuery(this).removeClass('hover'); });
}

function PrintThisEvent() {
    var win = window.open();

    win.document.writeln("<html>");
    win.document.writeln("<head>");
    win.document.writeln("<title>Afdrukken evenement</title>");

    win.document.writeln("<script language='javascript' type='text/javascript'>window.print();</script>");

    win.document.writeln("");
    win.document.writeln("<style>body { font-family:Arial; font-size:12px; line-height:18px; } </style>");
    win.document.writeln("<style>.registrationlink, .calender{ display:none; }</style>");
    win.document.writeln("<style>.field div, .field ul { clear:left; } </style>");
    win.document.writeln("<style>.field label { font-weight:bold; float:left; width:140px; padding-right:5px; } </style>");
    win.document.writeln("<style>.startdatetime .name { display:inline; }</style>");
    win.document.writeln("<style>.pricelist { margin-top:10px; }</style>");
    win.document.writeln("<style>.cufonwrap { display: none; }</style>");
    win.document.writeln("<style>.logo { margin-bottom:20px; }</style>");
    win.document.writeln("<style>h1 { color:#144192; font-weight:bold; font-size:25px; line-height:24px; margin:10px 0 20px; } </style>");
    win.document.writeln("<style>h2 { color:#000; font-weight:bold; font-size:16px; line-height:24px; margin-bottom:8px; } </style>");
    win.document.writeln("<style>.tabheader { font-size:20px;} </style>");
    win.document.writeln("<style>h3, h4, h5, h6 { color:#003399; font-weight:bold; font-size:12px; line-height:16px; margin:0px; padding:0px; } </style>");
    win.document.writeln("");

    win.document.writeln("</head><body>");

    jQuery('#logo img').each(function () {
        var logo = this;
        win.document.write('<div class="logo"><img src="' + logo.src + '" alt=""/></div><hr/>');
    });


    jQuery('.eventdetail h2').not(jQuery('.eventdetail .detail h2')).each(function () {
        var header = this;
        win.document.writeln("<h1>" + checkCufon(header) + "</h1>");
    });

    var Detail = jQuery('.reedeventdetailblock');
    win.document.writeln(Detail[0].innerHTML);

    jQuery('.eventdetail .tabs li span').each(function () {
        var tab = this;
        var Header = tab.innerHTML;

        win.document.writeln("<h2 class='tabheader'>" + Trim(Header) + "</h2>");

        switch (Trim(Header.toLowerCase())) {
            case "informatie":
                var info = jQuery('.eventdetail .detail .information');
                win.document.writeln(info[0].innerHTML);
                break;
            case "programma":
                var info = jQuery('.eventdetail .detail .program');
                win.document.writeln(info[0].innerHTML);
                break;
            case "inschrijven":
                var info = jQuery('.eventdetail .detail .personality');
                win.document.writeln(info[0].innerHTML);
                break;
            case "sprekers":
                var info = jQuery('.eventdetail .detail .review');
                win.document.writeln(info[0].innerHTML);
                break;
            case "contact":
                var info = jQuery('.eventdetail .detail .press');
                win.document.writeln(info[0].innerHTML);
                break;
            case "sponsorinfo":
                var info = jQuery('.eventdetail .detail .sponsors');
                win.document.writeln(info[0].innerHTML);
                break;
            case "downloads":
                var info = jQuery('.eventdetail .detail .downloads');
                win.document.writeln(info[0].innerHTML);
                break;
            case "u ontmoet":
                var info = jQuery('.eventdetail .detail .youwillmeet');
                win.document.writeln(info[0].innerHTML);
                break;
            case "Links":
                var info = jQuery('.eventdetail .detail .links');
                win.document.writeln(info[0].innerHTML);
                break;
            case "Partners":
                var info = jQuery('.eventdetail .detail .partners');
                win.document.writeln(info[0].innerHTML);
                break;
            case "Exposure":
                var info = jQuery('.eventdetail .detail .exposure');
                win.document.writeln(info[0].innerHTML);
                break;
            case "Doelgroep":
                var info = jQuery('.eventdetail .detail .audience');
                win.document.writeln(info[0].innerHTML);
                break;
            case "Historie":
                var info = jQuery('.eventdetail .detail .history');
                win.document.writeln(info[0].innerHTML);
                break;
        }
    });

    win.document.writeln("<hr/></body></html>");

    if (navigator.appName != "Netscape") {
        win.location.reload(true);
    }
   
    win.close();
}

function checkCufon(element) {
    var headerTekst = "";
    jQuery('cufontext', element).each(function () {
        var cufontekst = this;
        headerTekst = headerTekst + cufontekst.innerHTML;
    });

    return headerTekst;
}

function Trim(value) {
    value = value.replace(/^\s+/, '');
    value = value.replace(/\s+$/, '');
    return value;
}

function emptyFields(){
    jQuery('.sr_footer .reedeventdetailblock').each(function () {
        var block = this;
        jQuery('.banners', block).each(function () {

            var element = this;
            if (Trim(element.innerHTML) == "") {
                jQuery(block).hide();
            }
        });
    });
}

function hideComponent() {
	if(jQuery('.mm_wysiwyg_container').length==0) {
		jQuery('.relateditemsblock').each(function() {
			var block = this;
			jQuery('ul',block).each(function() {
				var content = this;
				if(Trim(content.innerHTML)=="") {
					jQuery(block).hide();
				}
			});
		});
	}
}

function clickFactuurAdres() {
    jQuery('.eventregistrationblock .confirm .selection').click(function () {
        var block = this;
        jQuery('input', block).each(function () {
            inputwaarde = this;
            if (inputwaarde.checked) {
                if (inputwaarde.value != "other") {
                    jQuery('.eventregistrationblock .deliveryaddress').hide();
                }
            }
        });
    });
}

function replaceLabel() {
    jQuery('#centerright, #contentBottom .right').each(function () {
        var block = this;
        jQuery('.searchblock .input-text', block).attr('value', '');
        if (jQuery('.searchblock label', block).length > 0) {
            jQuery('.searchblock label', block)[0].innerHTML = "Bijvoorbeeld naam congres of ..."
        }
        jQuery('.searchblock .input-text', block).focus(function () {
            jQuery('.searchblock label', block).hide();
        });

        jQuery('.searchblock .input-text', block).blur(function () {
            if (jQuery('.searchblock .input-text', block).attr('value').length <= 0) {
                jQuery('.searchblock label', block).show();
            }
        });
    });
}

function moveScriptDown() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }
    jQuery('#sciptbottom').css('bottom', (scrOfY * -1) + 'px');
}

function mostViewed() {
    jQuery('ul li:last').addClass('last');
}

function addClass() {
    jQuery('.relateditemsblock').each(function () {
        var block = this;
        jQuery('div.resultlink:last', block).addClass('lastresultlink');
        jQuery('div.event:last', block).addClass('lastevent');
    });
}

function removeTags() {
    jQuery('.relateditemsblock ul div').not(jQuery('.relateditemsblock ul div div')).each(function () {
        var liElement = this;
        var anchors = jQuery('.tags a', liElement);
        if (anchors.length > 0) {
            jQuery(anchors[0]).before(jQuery('<span>Tags: </span>'));
        }
        if (anchors.length > 6) {
            var x = anchors.length - 1;
            while (x > 5) {
                jQuery(anchors[x]).remove();
                x--;
            }
        }
    });
}

function checkheight() {
    var left = jQuery('#contenttop .eventdetail .detail');
    var right = jQuery('#detailinfo');
    if (left.length > 0 && right.length > 0) {
        if (jQuery(left[0]).height() < jQuery(right[0]).height()) {
            jQuery(left[0]).css('min-height',jQuery(right[0]).height());
        }
        if (navigator.appName.indexOf("Internet") > 0) {
            jQuery(left[0]).css('height', jQuery(right[0]).height());
        }
    }
}

emptyFields();
clickFactuurAdres();
makeButton('.linkblock input, .linklistblock input, .button-container input, #topleft .button-container a, .searchresultsblock .pages .previous');
makeButton('.searchresultsblock .pages .next, .paging .previous, .paging .next, .eventdetail .button-container a, .addperson a', '#sl_right .paging .previous, #sl_right .paging .next, #sl_right .pages .previous, #sl_right .pages .next');
makeButton('.objectbasketblock .button-container a, .reedeventdetailblock .registrationlink a, .htmlblock .back');
jQuery("input[value='Wissen']").hide();
changeForm();
makeHeight();
clixmaster();
getThirdElement();
wrapEvents();
makeHover();
wrapCufon();
addClass();
replaceLabel();
hideComponent();
removeTags();
checkheight();
