Cufon.replace('h2.aquaEco, a#btnSearch_Museum, a#btnSearch_Location, .back a.button, .searchbox a.button');

/* ##########################################################

Footer wordt onder aan het browservenster geplaatst wanneer de content niet het gehele browservenster vult. Bij langere content komt de footer onder de content te staan.

###########################################################*/

/* Geef de ID's van header content en footer */

var contentID = 'wrapper';
var footerID = 'footer';


/* #######################################################*/

function getWindowHeight() {
    var windowHeight = 0;
    if (typeof (window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}

function setFooter() {
    $('.fullAligned').css('height', $(document).height());
    if (document.getElementById) {
        var windowHeight = getWindowHeight();
        if (windowHeight > 0) {

            var footerElement = document.getElementById(footerID);
            //var tmbalkHeight = document.getElementById(tmbalkID)? document.getElementById(tmbalkID).offsetHeight:0;
            //var headerHeight = document.getElementById(headerID)? document.getElementById(headerID).offsetHeight:0;
            var footerHeight = document.getElementById(footerID) ? document.getElementById(footerID).offsetHeight : 0;
            var contentHeight = document.getElementById(contentID) ? document.getElementById(contentID).offsetHeight : 0;

            var totalHeight = footerHeight + contentHeight;

            if (windowHeight - totalHeight >= 0) {

                /*var dHeight = $(document).height();
                $('.fullAligned').css('height',dHeight);*/
                footerElement.style.position = 'absolute';
            } else {


                footerElement.style.position = 'relative';
            }
        }
    }
}

function truncateTxt() {
    var element = $('.museumdetail .data .content');
    var btn = element.next('a.readMore');

    element.removeClass('less');
    var elH = element.height();

    if (elH < 109) {
        btn.hideMe();
    }
    else {
        element.addClass('less');
        btn.showMe();
    }
	//alert($(window).height());
    var originalHeight = $(window).height();
    btn.click(function () {
        //$('.museumdetail .data .content').toggleClass('auto');
		//alert($(window).height());
        var newEl = $('.museumdetail .data .content').height();
        
        if (newEl < 109) {
            $('.museumdetail .data .content').animate({
                height: elH
            }, 'fast', function () {
                $('a.readMore').toggleClass('open');
                setFooter();
                $('.fullAligned').css('height', $(document).height());
                $('.msie6 .fullAligned .bg').css('height', $(document).height());
            });
        }
        else {
            $('.museumdetail .data .content').animate({
                height: '108px'
            }, 'fast', function () {
                $('a.readMore').toggleClass('open');
                setFooter();
                $('.fullAligned').css('height', $(window).height());
                $('.msie6 .fullAligned .bg').css('height', $(window).height());
            });
        }
		setFooter();
        return false;
    });
}

$(document).ready(function () {

    $('body').addClass('img').addClass("js"); // also adding class js for javascript detection
    bgImageTotal = 3;
    randomNumber = Math.round(Math.random() * (bgImageTotal - 1)) + 1;
    $('#wrapper.detailPage').parents('body').addClass('img_detail_' + randomNumber);
    $('#wrapper.home').parents('body').addClass('img_' + randomNumber);
    //$('body.img').addClass('img_5'+ randomNumber);

    // Tweets

    $("#tweets").tweet({
        avatar_size: 44,
        count: 4,
        query: "museumweekend",
        loading_text: "searching twitter..."
    }).bind("loaded", function () {
        $('.tweet_list').innerfade({ speed: 1000, timeout: 5000, type: 'sequence', containerheight: '1em' });
        $(this).find("a").attr("target", "_blank");
    });

    var userName = $('a.jq_UserAnchor').text();
    $('a.jq_UserAnchor').hide();
    $('#dnn_loginMe .row.first').append(userName);

    //$('td.filterElements tr:eq(0), td.filterElements tr:eq(3), td.filterElements tr:eq(4)').hide(); ;

    $('.DNN_HTMLContent').prev('h2.aquaEco').addClass('DNN_HTMLContent');
    $('a#jq_search').click(function () {
        var cityUrl = $('input#cityUrl').val();
        var q = $('input#q').val();
        $(this).attr('href', cityUrl + q);
    });

    $('.backend .columnLeft .ModAuthenticationC').parent('.aquaEcoTitle').addClass('loginBox');
    $('#tabs > ul li:eq(0)').addClass('first');
    $('#tabs > ul li:eq(1)').addClass('second');

    $('#wrapper.backend').parents('body').removeClass('img').addClass('backend');

    $('a.newwindow').click(function () {
        window.open(this.href);
        return false;
    });

    //    var mapFilter = $('#searchmap .jQ_filter');
    //    mapFilter.find('a.btn').click(function () {
    //        if ($('#searchmap .jQ_filter .inner').is(":visible") == true && $('#searchmap .jQ_filter .inner input').is(':checked') == true) {
    //            return false;
    //        } else {
    //            mapFilter.find('.inner').toggle();
    //            mapFilter.find('a.btn').toggleClass('close');
    //        }
    //        return false;
    //    });

    // make it possible to hide filter if one or more chechboxes are checked

    var mapFilter = $('#searchmap .jQ_filter');
    mapFilter.find('a.btn').click(function () {
        mapFilter.find('.inner').toggle();
        mapFilter.find('a.btn').toggleClass('close');
    });

    $('.detail .contentwrapper .museumsearch .searchResults .list .item').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });

    $('input.jq_clearOnFocus').focusin(function () {
        if ($(this).val() == 'plaatsnaam' || $(this).val() == 'museumnaam') {
            $(this).val('');
        }
    });

    if ($('#footer').length >= 1) {
        $(window).resize(function () {
            setFooter();
            $('.fullAligned').css('height', $(document).height());
        });
    }
    if ($('#footer').length >= 1) {
        setFooter();
    }
    $('.fullAligned').css('height', $(document).height());
    $('.msie6 .fullAligned .bg').css('height', $(document).height());

    if ($('#tabs').length > 0) {
        $("#tabs").tabs();
        /*if(bla == bla){
        $("#tabs").tabs("option", "selected", 1);
        }*/
    }
    $('input#q').keydown(function (event) {
        if (event.keyCode == '13') {
            var cityUrl = $('input#cityUrl').val();
            var q = $('input#q').val();
            $(this).attr('href', cityUrl + q);
            window.location = cityUrl + q;
            return false;
        }
    });
    $('input#search_location').keydown(function (event) {
        if (event.keyCode == '13') {
            $('a#btnSearch_Location').trigger('click');
        }
    });
    $('input#search_museum').keydown(function (event) {
        if (event.keyCode == '13') {
            $('a#btnSearch_Museum').trigger('click');
        }
    });

    var getCityName = (function () {
        var val = $('input.initialLocation').val();
        switch (val) {
            case 'Zeeland':
            case 'Noord-Brabant':
            case 'Noord Brabant':
            case 'Noord-brabant':
            case 'Noord brabant':
            case 'noord-Brabant':
            case 'noord Brabant':
            case 'noord-brabant':
            case 'noord brabant':
            case 'Limburg':
            case 'Gelderland':
            case 'Overijssel':
            case 'Drenthe':
            case 'Groningen':
            case 'friesland':
            case 'Friesland':
            case 'flevoland':
            case 'Flevoland':
            case 'Utrecht':
            case 'Zuid-Holland':
            case 'Zuid Holland':
            case 'Zuid-holland':
            case 'Zuid holland':
            case 'zuid-Holland':
            case 'zuid Holland':
            case 'zuid-holland':
            case 'zuid holland':
            case 'Noord-Holland':
            case 'Noord Holland':
            case 'Noord-holland':
            case 'Noord holland':
            case 'noord-Holland':
            case 'noord Holland':
            case 'noord-holland':
            case 'noord holland':
                val = '';
                break;
            default:
                break;
        }
        return val;
    })();
    if (getCityName != '') {
        $('input#search_location').val(getCityName);
    } else if (getCityName == '') {
        $('input#search_location').val('plaatsnaam');
    }

    // move footer to contentwrapper
    $("#footer").appendTo(".contentwrapper");


    // Uitgezet
    //	function registrationPage() {
    //		var PostAdresTabel = $('div.SecurityContent table[id*="ManageUsers_Profile_ProfileProperties"]');
    //		var museumRow = PostAdresTabel.find('span[id*="Museums_Label_label"]').closest('tr');
    //		var telefoonRow = PostAdresTabel.find('span[id*="Telephone_Label_label"]').closest('tr');

    //		telefoonRow.detach();
    //		museumRow.detach();

    //		$(museumRow).appendTo('table[id*="ManageUsers_User_UserEditor_tbl"] tbody');
    //		$(telefoonRow).appendTo('table[id*="ManageUsers_User_UserEditor_tbl"] tbody');
    //		$('<p style="color:#DC006B;">In maart sturen wij u per post affiches en ander promotiemateriaal. <br />Vul daarom hieronder het gewenste postadres in.</p>').insertAfter('[id*="ManageUsers_pnlUser"]');

    //	}
    //	function repositionOnSubmit() {

    //		var $ajaxElement = $('div.SecurityContent')

    //		//what event is fired when content of div is changed?

    //	}
    //	registrationPage();
    //	repositionOnSubmit();



});

