//PRELOAD IMAGES-------------------------------------------------------------------------------------------
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}


$(function() {

    //Strip HTML - AWESOME!
    //.replace(/<\/?[^>]+>/gi, '')
    jQuery.fn.stripTags = function() { return this.replaceWith(this.html().replace(/<\/?[^>]+>/gi, '')); };


    //No enter - allow only clicks to submit form
    $('input:not(textarea)').live('keypress', function(e) {
        if (e.which == 13) return false;
        if (e.which == 13) e.preventDefault();
    });



    //PrettyPhoto
    $("a[rel^='prettyPhoto']").prettyPhoto();

    // linkscrubber
    $("a").bind("focus", function() { if (this.blur) this.blur(); });


    // Scroll to top
    $('a[href=#top]').click(function() {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });

    //Column Item Shifts
    var holder = $('.col00Top').html();
    $('.col00Top').html('');
    $('.col01:first').prepend(holder);
    $('.col00Top:first').remove();

    holder = $('.col01Top').html();
    $('.col01Top').html('');
    $('.col02:first').prepend(holder);
    $('.col01Top:first').remove();

    //Remove duplicate author linkage
    try {
        $('.checkDup').each(function(i, e) {
            var aParent = $(this);
            var uniqueHREFs = {};
            var aArr = [];

            var $matrixTable = aParent,
        $matrixTableChildren = $matrixTable.children().detach();

            $matrixTableChildren.each(function(i, e) {
                var $this = $(this),
            HREF = $this.attr('href');

                if (typeof uniqueHREFs[HREF] !== 'undefined') {
                    if (!$this.hasClass('customAuthor'))
                        $this.remove();
                }
                else {
                    aArr = aArr.concat($this.get());
                    uniqueHREFs[HREF] = true;
                }
            });

            $matrixTable.html(aArr);
            try {
                $matrixTable.find('a:not(:last)').after(', '); //Add seperator
            } catch (Error) { }
        });
    } catch (Error) { }

    //Remove broken images
    //    $('img').live('error', function() {
    //        $(this).css('border', '1px solid #ff0000');
    //        $(this).remove();
    //    });

    //Remove broken images
    $('img').each(function(i, e) {
        $(e).error(function() {
            $(this).remove();
        });

        if ($(e).attr('src') != null) {
            if ($(e).attr('src') == "")
                $(e).remove();
        }
        else
            $(e).remove();
    });

});

//Author linkage fix

function checkLinkingAuthors() {
    $(function() {
        $('.auLS1').each(function(i, e) {
            $(e).attr('href', $(this).attr('href').toString().replace(/ /gi, '').replace(/%20/gi, ''));
        });

        $('.auLS0').each(function(i, e) {
            $(e).attr('href', 'javascript:void(0);');
            $(e).css('text-decoration', 'none');
            $(e).css('cursor', 'default');
        });
    });

}

$(function() {
    var aniSpd01 = 800;
    var aniSpd02 = 500;
    var aniSpd03 = 100;
    var aniSpd04 = 1500;

    // FocusBlock Expanda
    $('.focusBlockExpanda').live('click', function(e) {
        e.preventDefault();
        var trigger = $(this).parent('.trigger:first');
        var content = $(this).parent('.trigger:first').next('.focusBlockContent:first');

        $(this).parent('.trigger:first').next('.focusBlockContent:first').find('.muNogMorePop').hide(); //muNogMore Popups hide
        $(this).parent('.trigger:first').next('.focusBlockContent:first').find('.muNogMore').addClass('spHeaderExpandLrg').removeClass('spHeaderContractLrg'); //muNogMore Popups Style Contract

        if (!content.is(':animated')) {
            if (trigger.hasClass('active'))
                content.slideDown(aniSpd01, 'swing', function() { trigger.removeClass('active'); setSH(); });
            else
                content.slideUp(aniSpd01, 'swing', function() { trigger.addClass('active'); setSH(); });
        }
    });

    // SpecialProjects Expanda
    $('.SpecialProjectsAccordion:not(.spHeaderContract)').live('click', function(e) {
        e.preventDefault();
    });
    $('.SpecialProjectsAccordion:not(.spHeaderContract)').live('mouseover', function(e) {
        e.preventDefault();
        var trigger = $(this);
        var content = $(this).next('.SpecialProjectsAccordionContent:first');

        if (!$('.SpecialProjectsAccordionContent').is(':animated')) {
            $('.SpecialProjectsAccordionContent').hide('fast');
            $('.SpecialProjectsAccordion').addClass('spHeaderExpand');
            $('.SpecialProjectsAccordion').removeClass('spHeaderContract');

            content.slideDown(aniSpd01, 'swing', function() {
                $('.SpecialProjectsAccordionContent').removeClass('spHeaderContract');

                if (content.find('img:first').attr('src') == '/images/loader3.gif') {
                    content.find('img:first').attr('src', content.find('img:first').attr('alt'));

                    content.find('img:first').attr('alt', '');
                    content.find('img:first').attr('style', '');

                    window.setTimeout(function() { content.find('img:first').attr('width', '300'); }, 500)
                }

                trigger.addClass('spHeaderContract');
                trigger.removeClass('spHeaderExpand');
            });
        }
    });

    //Featured Articles (HomePage Slideshow)
    var muFSS;
    var muFSScurIndex = 0;
    var muFSSmaxIndex;
    var activeContent = $('.carouselInnerText');
    var showActiveContentContainer = $('#muFeaturedSlideshow .carouselInnerText:first');
    var bgContainer = $('#muFeaturedSlideshow .carouselStoryImage:first');

    $('.carouselStory:first').addClass('activeSlide');

    showActiveContentContainer.html($('#muFeaturedSlideshow .carouselStoryContent:first').html()); //onLoad
    bgContainer.css('background-image', $('#muFeaturedSlideshow .carouselStoryContent:first').css('background-image')); //onLoad
    activeContent.fadeIn(aniSpd02, function() {
        if ($.browser.msie) {
            this.style.removeAttribute("filter");
        }
    });

    $('#muFeaturedSlideshow .carouselStory').live('click', function(e) {
        if (!activeContent.is(':animated')) {
            activeContent.fadeOut(aniSpd03);
            e.preventDefault();
            $(this).addClass('activeSlide');
            muFSScurIndex = $(this).index();
            $('.carouselStory').removeClass('activeSlide');
            $(this).addClass('activeSlide');
            bgContainer.css('background-image', $(this).find('.carouselStoryContent:first').css('background-image'));
            showActiveContentContainer.html($(this).find('.carouselStoryContent:first').html());
            activeContent.fadeIn(aniSpd02, function() {
                if ($.browser.msie) {
                    this.style.removeAttribute("filter");
                }
            });
        }
    });

    $('#muFeaturedSlideshow .carouselStory').live('mouseover', function(e) {
        $('#muFeaturedSlideshow .carouselStory').removeClass('carouselStoryActive');
        if (!activeContent.is(':animated'))
            $(this).addClass('carouselStoryActive');

    });

    $('#muFeaturedSlideshow .carouselStoryActive').live('mouseout', function(e) {
        $(this).removeClass('carouselStoryActive');
    });

    if ($('#muFeaturedSlideshow').length > 0) {
        $('#muFeaturedSlideshow .carouselStory').click(function(e) {
            if (!activeContent.is(':animated')) {
                activeContent.fadeOut(aniSpd03);
                e.preventDefault();
                $(this).addClass('activeSlide');
                muFSScurIndex = $(this).index();
                $('.carouselStory').removeClass('activeSlide');
                $(this).addClass('activeSlide');
                bgContainer.css('background-image', $(this).find('.carouselStoryContent:first').css('background-image'));
                showActiveContentContainer.html($(this).find('.carouselStoryContent:first').html());
                activeContent.fadeIn(aniSpd02, function() {
                    if ($.browser.msie) {
                        this.style.removeAttribute("filter");
                    }
                });
            }
        });

        setmuFSSinterval();

        $('#muFeaturedSlideshow').mouseenter(function(e) {
            window.clearInterval(muFSS);
        });
        $('#muFeaturedSlideshow').mouseleave(function(e) {
            setmuFSSinterval();
        });

    }
    function setmuFSSinterval() {
        muFSSmaxIndex = $('#muFeaturedSlideshow .carouselStory').length;
        muFSS = window.setInterval(function() {

            muFSScurIndex++;
            if (muFSScurIndex >= muFSSmaxIndex)
                muFSScurIndex = 0;

            $('#muFeaturedSlideshow .carouselStory:eq(' + muFSScurIndex + ')').trigger('click');


        }, 5000);
    }

    //Tooltip (Slider)
    $('.sliderTooltip .icon').live('mouseenter', function(e) {
        $(this).next('.sliderTooltip .tooltip').show();
    });
    $('.sliderTooltip .icon').live('mouseleave', function(e) {
        $(this).next('.sliderTooltip .tooltip').hide();
    });

    //Nog-More Popup
    $('.muNogMore').live('click', function(e) {
        var muNogMoreContent = $(this).parent().find('.muNogMorePop:first');
        var heightPerItem = 41;
        if ($.browser.msie && $.browser.version <= 7) heightPerItem = 42;
        var popUpNegMarg = '-' + parseInt($(this).parent().find('.muNogMoreCount').length) * heightPerItem + 'px';
        muNogMoreContent.css('margin-top', popUpNegMarg);
        e.preventDefault();

        if (!muNogMoreContent.is(':animated')) {
            if (muNogMoreContent.css('display') != 'block')
                muNogMoreContent.slideDown(aniSpd02, 'easeInOutExpo', function() { $(this).next('.muNogMore:first').removeClass('spHeaderExpandLrg').addClass('spHeaderContractLrg'); });
            else
                muNogMoreContent.slideUp(aniSpd02, 'easeInOutExpo', function() { $(this).next('.muNogMore:first').addClass('spHeaderExpandLrg').removeClass('spHeaderContractLrg'); });
        }
    });

    //NormalExpanda
    $('.muExpanda').live('click', function(e) {
        e.preventDefault();
        var muExpandaContent = $(this).next('.muExpandaContent:first');

        if (!muExpandaContent.is(':animated')) {
            $(this).parents('.muTopSContainer:first').find('.muExpandaContent').slideUp(aniSpd02, 'easeInOutExpo', function() { $(this).parents('.muTopSContainer:first').find('.muExpanda').removeClass('spHeaderContractAddOn'); });

            if (muExpandaContent.css('display') != 'block')
                muExpandaContent.slideDown(aniSpd02, 'easeInOutExpo', function() { $(this).prev('.muExpanda:first').addClass('spHeaderContractAddOn'); });
            else
                muExpandaContent.slideUp(aniSpd02, 'easeInOutExpo', function() { $(this).prev('.muExpanda:first').removeClass('spHeaderContractAddOn'); });
        }
    });

    //Edit Top Navigation DropDowns ***********************
    var newHTML = "";
    var maxWidth = 500;
    var maxHeight = 0;
    var splitOpen = "<div class='mainSubNavRow'>";
    var splitClose = "<div class='clearfix' style='clear:both;'></div></div>";
    var splitSep = "<div class='clearfix tpSep' style='clear:both; height:4px; width:860px; background-color:#000;'></div>";

    $('.muTopNavDropdown').each(function(i, e) {
        var iWidth = 0;


        $(this).find('.mainSubNavRowItem').each(function(ii, ee) {
            if (iWidth > maxWidth) {
                iWidth = 0;
                $(ee).prev('.mainSubNavRowItem:first').css('border-right', '0px');
                $(ee).before(splitSep);
            }
            iWidth += $(ee).width();


            if ($(ee).height() > maxHeight)
                maxHeight = $(ee).height();
        });
        $(e).find('.mainSubNavRowItem').css('height', maxHeight + 'px');
    });

    $('.muTopNavDropdown').css('visibility', 'visible');
    $('.muTopNavDropdown').css('display', 'none');




    //Top Navigation
    $('#nav>li').mouseenter(function(e) {
        var muTopNavItem = $(this);
        var muTopNavItemLink = $(this).find('a:first');
        var muTopNavDropDown = $(this).find('.muTopNavDropdown:first');

        if ($.browser.msie && $.browser.version <= 7) {
            //muTopNavDropDown.css('margin-left','-'+muTopNavItemLink.width() + 23+'px');
        }

        $('#nav>li>a').removeClass('muTopNavActive');

        if (!muTopNavDropDown.is(':animated')) {
            if (muTopNavDropDown.css('display') != 'block') {
                $('.muTopNavDropdown').hide();
                //muTopNavDropDown.fadeIn(aniSpd03, function() { $('#nav>li>a').removeClass('muTopNavActive'); muTopNavItemLink.addClass('muTopNavActive'); });
                muTopNavDropDown.show();
                $('#nav>li>a').removeClass('muTopNavActive');
                muTopNavItemLink.addClass('muTopNavActive');
            }
        }
    });

    $('.headerTopSection,.col00,.col01,.col02,.col03').mouseenter(function(event) {
        $('.muTopNavDropdown').hide();
        $('#nav>li>a').removeClass('muTopNavActive');
    });

    $('.muTopNavDropdown').mouseleave(function(event) {
        $(this).hide();
        $('#nav>li>a').removeClass('muTopNavActive');

    });

    //Top Navigation DropDown Fixes
    $('.muTopNavDropdown').each(function(i, e) {
        if ($(e).find('.mainSubNavRowItem').length == 0) $(e).remove();
        $(e).find('.tpSep').prev('.mainSubNavRowItem:first').css('border-right', '0px');
        $(e).find('.mainSubNavRowItem:last').css('border-right', '0px');
        $(e).find('.mainSubNavRow:last').removeClass('mainSubNavRow').addClass('mainSubNavRowLast');
    });

    //Upload Photo
    $('.imgU,.imgUF').click(function() {
        $('.ifCImgPreview').hide();
        $('#ifCImg').fadeIn(aniSpd01, function() {
            if ($.browser.msie) {
                this.style.removeAttribute("filter");
            }
        });
        window.frames['ifImgCrop'].setHeight();
    });

    //Clear Photo
    $('.imgUC').click(function() {
        $('#ifCImg').fadeOut(aniSpd01);
        $('#ctl00_PageContent_hdnImagePath').val('');
    });

    //Category linkage
    $('.fCheckBoxListClick').click(function(e) {
        e.preventDefault();

        var btn = $(this);
        var cCnt = btn.next('.fCheckBoxList:first');
        if (!cCnt.is(':animated')) {
            if (cCnt.css('display') != 'none') {
                cCnt.slideUp(aniSpd01, function() {
                    btn.html(btn.html().toString().replace(/\-/gi, '+'));
                });
            }
            else {
                cCnt.slideDown(aniSpd01, function() {
                    btn.html(btn.html().toString().replace(/\+/gi, '-'));
                });
            }
        }
    });

    //Category linkage maximum
    $('.fCheckBoxList input').click(function(ee) {
        var maxCnt = 0;
        var maxChk = 5;
        $(this).parents('.fCheckBoxList:first').find('input').each(function(i, e) {
            if ($(e).is(':checked'))
                maxCnt++;
        });

        if (maxCnt >= maxChk) {
            $(this).parents('.fCheckBoxList:first').find('input').each(function(i, e) {
                if (!$(e).is(':checked'))
                    $(e).attr("disabled", "disabled");
            });

        }
        else {
            $(this).parents('.fCheckBoxList:first').find('input').each(function(i, e) {
                $(e).removeAttr("disabled");
            });
        }
    });

    //Calendar DatePicker
    $('.muDatePickerClick').click(function(e) {
        e.preventDefault();

        var btn = $(this);
        var cCnt = btn.prev('.muDatePickerContainer:first');
        if (!cCnt.is(':animated')) {
            if (cCnt.css('display') != 'none') {
                cCnt.hide();
            }
            else {
                cCnt.show();
            }
        }
    });

    //Comments
    $('.postComment').click(function(e) {
        e.preventDefault();

        if ($('.nicEdit-main:last').text() == "") {
            $('.nicEdit-main:last').css('border', '1px solid #ff0000');
            return false;
        }
        else {
            $.ajax({
                type: 'POST',
                url: '/PostComment/' + new Date().getTime(),
                data: 'cI=' + escape($("#ctl00_PageContent_hdnI").val()) + '&t=' + encodeURIComponent($('.nicEdit-main:last').html()),
                success: function(r) {
                    $('#cP').fadeOut(1000, function() {
                        $('.cPres').html("Dankie vir jou kommentaar | Thank you for your comment.");
                        $(this).remove();
                    })
                },
                error: function(r) { alert("Error has occurred, please try again."); }
            });
        }

    });

    //Clear top search on doc read
    $('#ctl00_txtTopSearchF').val('');

    //hide Article
    $('.myProfileE:not(.fPe)').live('click', function(e) {
        e.preventDefault();
        var eId = $(this).attr('id');
        var eI = $(this).attr('id').toString().replace('eI_', '');
        var eIa = eI.split('_');

        $.ajax({
            type: 'POST',
            url: '/hideArticle/' + new Date().getTime(),
            data: 'i=' + escape(eIa[0]) + '&u=' + escape(eIa[1]) + '&l=' + escape(eIa[2]),
            success: function(r) {
                if (r != "") {
                    $('#' + eId).parents('.pAItem:first').fadeOut(500, function() {
                        $('#pLArticle').html(r);
                    });
                }
            },
            error: function(r) { alert("Error has occurred, please try again."); }
        });
    });

    try {
        $('.dLast:last').html($('.dLast:last').html().replace('&nbsp;|&nbsp;', ''));
    }
    catch (Error) { }

    //Remove Comment
    $('.myCommentD:not(.fPe)').live('click', function(e) {
        e.preventDefault();
        var eId = $(this).attr('id');
        var eI = eId.toString().replace('cmI_', '');
        var eIa = eI.split('_');
        $.ajax({
            type: 'POST',
            url: '/removeComment/' + new Date().getTime(),
            data: 'cI=' + escape(eIa[0]) + '&cU=' + escape(eIa[1]),
            success: function(r) {
                if (r != "") {
                    $('#' + eId).parents('.commentBlock:first').fadeOut(500, function() {
                    });
                }
            },
            error: function(r) { alert("Error has occurred, please try again."); }
        });
    });

    //Article Image Captions
    //setCaptions();

    //Social Clicks
    $('.socC').click(function(e) {
        e.preventDefault();
        var extraInfo = "LitNet - "
        var type = $(this).find('img:first').attr('alt');
        $.ajax({
            type: 'POST',
            url: '/CaptureS',
            data: 't=' + escape(type) + '&cID=' + $('#ctl00_PageContent_hdnI').val(),
            success: function(r) { },
            error: function(r) { }
        });

        var url = encodeURIComponent(window.location);
        var text = encodeURIComponent(extraInfo + $('.socH:first').text());

        if (type == "Twitter") {
            window.open("http://twitter.com/intent/tweet?original_referer=" + url + "&text=" + text + "&url=" + url, "_blank", "width=800, height=400");
        }
        else if (type == "Tumblr") {
            window.open("http://www.tumblr.com/share/link?url=" + url + "&name=LitNet&description=" + text, "_blank", "width=800, height=400");
        }
        else if (type == "Digg") {
            window.open("http://digg.com/submit?url=" + url, "_blank", "width=800, height=400");
        }
        else if (type == "Reddit") {
            window.open("http://www.reddit.com/submit?url=" + url + "&title=" + text, "_blank", "width=800, height=400");
        }
        else if (type == "Stumble Upon") {
            window.open("http://www.stumbleupon.com/submit?url=" + url + "&title=" + text, "_blank", "width=800, height=400");
        }
    });

    $('div.closed').each(function(ii, ee) {
        $(ee).find('.trigger:first').addClass('active');
    });

    //Links to target blank
    $('.rssLinks a').each(function(ii, ee) {
        $(ee).attr('target', '_blank');
    });

    //Custom Hovers
    $('.muCHov').hover(function(e) {
        $(this).find('*:first').animate({ 'margin-top': '8px', opacity: 1 }, { duration: aniSpd02, queue: false, easing: 'easeOutCirc' }, function() { });
    },
    function(e) {
        $(this).find('*:first').animate({ 'margin-top': '0px', opacity: 0.6 }, { duration: aniSpd02, queue: false, easing: 'easeOutCirc' }, function() { });
    });

    $('.muCHov2').hover(function(e) {
        $(this).find('*:first').animate({ 'margin-top': '3px', opacity: 1 }, { duration: aniSpd03, queue: false, easing: 'easeOutCirc' }, function() { });
    },
    function(e) {
        $(this).find('*:first').animate({ 'margin-top': '0px', opacity: 0.6 }, { duration: aniSpd03, queue: false, easing: 'easeOutCirc' }, function() { });
    });

    //Top Ad Counter
    $('.aTopAd').live('click', function(e) {

        var eId = $(this).attr('id');
        var eI = eId.toString().replace('tA_', '');

        $.ajax({
            type: 'POST',
            url: '/UpdateA/' + new Date().getTime(),
            data: 'aI=' + escape(eI),
            success: function(r) { },
            error: function(r) { }
        });

    });

    //Page Ad Counter
    $('.aXvCH').live('click', function(e) {

        var eId = $(this).attr('id');
        var eI = eId.toString().replace('pBa_', '');
        var eIa = eI.split('_');

        $.ajax({
            type: 'POST',
            url: '/pbUpdateA/' + new Date().getTime(),
            data: 'aI=' + escape(eIa[0]),
            success: function(r) { },
            error: function(r) { }
        });

    });




    checkTopNavDropScroller();
});
//Top Nav Scroller
function checkTopNavDropScroller() {
    var tnHeaderH = $('#TopNav').position().top * 0.8;
    var tnWindowH = $(window).height();
    var tnCheckH = tnWindowH - tnHeaderH;

    $('.muTopNavDropdown').css('max-height', tnCheckH + 'px');
    $('.muTopNavDropdown').css('overflow-y', 'auto');
    $('.muTopNavDropdown').css('overflow-x', 'hidden');
}

//Article Image Captions
function setCaptions() {
    $(function() {
        if ($('.cleanMuEdit').length > 0) {
            $('.cleanMuEdit img').each(function(i, e) {
                if ($(e).attr('alt') != '') {
                    //$(e).wrap('div'); //Can't wrap, IE looses image
                    $(e).after('<div width="' + $(e).css('width') + '" align="' + $(e).attr('align') + '" style="width:' + $(e).css('width') + '; float:' + $(e).css('float') + '; padding:0px 10px 10px 10px !important; text-align:left; font-size:10px; color:#666; clear:both; ">' + $(e).attr('alt') + '</div>')
                }
            });
        }
        //if ($('#muEditor').length > 0) {

        //            $('#muEditor img').each(function(i, e) {
        //                if ($(e).attr('alt') != 'undefined') {
        //                    if ($(e).attr('alt') != '') {
        //                        //$(e).next('.imgCap:first').remove();
        //                        //$(e).wrap('div'); //Can't wrap, IE looses image
        //                        //$(e).after('<p contentEditable="false" unselectable="true" class="imgCap" width="' + $(e).css('width') + '" align="' + $(e).attr('align') + '" style="width:' + $(e).css('width') + '; float:' + $(e).css('float') + '; padding:0px 10px 10px 10px !important; text-align:left; font-size:10px; color:#666; clear:both; -moz-user-edit: none;">' + $(e).attr('alt') + '</p>')
        //                        if ($(e).next().hasClass('imgCap'))
        //                            $(e).next('.imgCap:first').text($(e).attr('alt'));
        //                        else
        //                        $(e).after('<p class="imgCap" width="' + $(e).css('width') + '" align="' + $(e).attr('align') + '" style="width:' + $(e).css('width') + '; float:' + $(e).css('float') + '; padding:0px 10px 10px 10px !important; text-align:left; font-size:10px; color:#666; clear:both;">' + $(e).attr('alt') + '</p>')
        //                    }
        //                }
        //            });
        //            //$('.imgCap').attr('readonly', true);

        //}


    });
}

function setCaptionSingle(cItem) {
    $(function() {

        var e = cItem;

        if ($(e).attr('alt') != 'undefined') {
            if ($(e).attr('alt') != '') {
                if ($(e).next().hasClass('imgCap')) {
                    $(e).next('.imgCap:first').text($(e).attr('alt'));
                    $(e).next('.imgCap:first').attr('align', $(e).attr('align'));
                    $(e).next('.imgCap:first').css('float', $(e).css('float'));
                    $(e).next('.imgCap:first').css('width', $(e).css('width'));
                }
                else
                    $(e).after('<p class="imgCap" width="' + $(e).css('width') + '" align="' + $(e).attr('align') + '" style="width:' + $(e).css('width') + '; float:' + $(e).css('float') + '; padding:0px 10px 10px 10px !important; text-align:left; font-size:10px; color:#666; clear:both;">' + $(e).attr('alt') + '</p>')
            }
        }


    });
}

//Cookie Methods

function setSH() {
    try {
        var alliDs = "";
        $('.focusBlockContent').each(function(ii, ee) {
            var iD = $(ee).parents('.muSortableItem:first').attr('id').replace("muSortID_", "");
            if ($(ee).css('display') == "none") {
                alliDs += "," + iD + ",";
            }
        });
        writeCookie("lnSh", alliDs.replace(/,,/gi, ","), "20");
    }
    catch (Error) { }
}

function writeCookie(name, value, days) {
    var date, expires;
    if (days) {
        date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    } else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";

}
function readCookie(name) {
    var i, c, ca, nameEQ = name + "=";
    ca = document.cookie.split(';');
    for (i = 0; i < ca.length; i++) {
        c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) == 0) {
            return c.substring(nameEQ.length, c.length);
        }
    }
    return '';
}



//Clears Empty Array Elements
function cleanArr(arr, deleteValue) {
    if (arr != undefined) {
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] == deleteValue) {
                arr.splice(i, 1);
                i--;
            }
        }
    }
    return arr;
};

//Archive Archive All clicks
$('.arcSet').live('click', function() {
    $(this).parents('.searchShowText:first').find('.arcSet').removeClass('Set');
    //$(this).parents('.searchShowText:first').find('.showASResults').removeClass('showASResults');
    $(this).addClass('Set');
});

function showContentRel(cID) {
    $(function() {
        var topVal = "";
        topVal = $('.allC' + cID).parents('.muPageItemRef:first').find('.Set:first').text();
        if (topVal == "alles" || topVal == "all" || topVal == "")
            topVal = 0;
        else
            topVal = parseInt(topVal);

        if ($('.allC' + cID).css("display") == "block") {
            $('.allC' + cID).slideUp(1000, function() {
                $('.arcCli' + cID + ' img:first').attr('src', '/Images/buttons/btn_search_results.jpg');
            });
        }
        else {
            $('.showSearchDrop').slideUp(500);
            $('.showASResults').find('img:first').attr('src', '/Images/buttons/btn_search_results.jpg');
            showContent(cID, topVal);
        }
    });
}

function showContent(cID, cTop) {
    $(function() {
        if (!$('.allC' + cID).is("animated")) {
            $('.allC' + cID).before("<div class='aSLoading'><img src='/images/loader3.gif' alt=''/><br/>Loading...</div>");
            $('.allC' + cID).prev('.aSLoading:first').slideDown(500);
            $.ajax({
                type: 'POST',
                url: '/ArchiveGet/' + cID + '/' + cTop,
                data: 's=' + $("#ctl00_PageContent_txtSearch").val() + '&f=' + $('#ctl00_PageContent_hdnFilter').val(),
                success: function(r) {
                    if ($('.allC' + cID).css("display") == "none") {
                        $('.allC' + cID).prev('.aSLoading:first').slideUp(1000, function() { $(this).remove(); });
                        $('.allC' + cID).html(r).slideDown(1000, function() {
                            $('.arcCli' + cID + ' img:first').attr('src', '/Images/buttons/btn_search_results_o.jpg');

                            checkLinkingAuthors();
                        });
                    }


                },
                error: function(r) { }
            });
        }
    });

}

var cPopTop = '';
var cPopLeft = '';

function showCalC(selectedDate) {
    $(function() {

        $.ajax({
            type: 'POST',
            url: '/Data/GetCalendarResults.aspx?' + new Date().getTime(),
            data: 'dt=' + escape(selectedDate),
            success: function(r) {
                $('#cPopUp').html(r);
                setCalendarPopUpValues();
            },
            error: function(r) { alert("Error has occurred, please try again."); }
        });


    });
}

function closeCalC() {
    $(function() {
        $('#cPopUp').fadeOut(500, function() {
            $('iframe#ifCalendar').contents().find('*').removeClass('dbDate').addClass('BACKdefault');
        });
    });
}

function setCalendarPopUpValues() {
    $(function() {
        try {
            var sPop = $('#cPopUp');
            var sIframe = $('iframe#ifCalendar');
            var sItem = sIframe.contents().find('.dbDate:first');

            cPopTop = (sIframe.position().top + sItem.position().top) + 'px';
            cPopLeft = (sIframe.position().left + sItem.position().left - sPop.width()) + 'px';

            sPop.css('top', cPopTop);
            sPop.css('left', cPopLeft);
            sPop.fadeIn(500, function() {
                if ($.browser.msie) {
                    this.style.removeAttribute("filter");
                }
            });
        }
        catch (Error) { }
    });
}

window.onresize = function() {
    setCalendarPopUpValues();
    checkTopNavDropScroller();
};

window.onscroll = function() {
    setCalendarPopUpValues();
    checkTopNavDropScroller();
};

function removeDuplicateElement(arrayName) {
    var newArray = new Array();
    label: for (var i = 0; i < arrayName.length; i++) {
        for (var j = 0; j < newArray.length; j++) {
            if (newArray[j] == arrayName[i])
                continue label;
        }
        newArray[newArray.length] = arrayName[i];
    }
    return newArray;
}

//Add Search feature to dropdown
function addSearch(ddlRef) {
    $(function() {

        var ddl = $(ddlRef);
        var txtSBoxRef = ddlRef + 'Search';

        ddl.before('<div>Search:<br/><input type="text" id="' + txtSBoxRef + '" style="width:100px;"/><br/><br/></div>');

        $('#' + txtSBoxRef).live('keyup', function(e) {
            if ($(txtSBoxRef).val() != "") {
                ddl.find('option').each(function(i, e) {
                    if (!$(e).text().indexOf($(txtSBoxRef).val()) > -1)
                        $(e).hide();
                    else
                        $(e).show();
                });
            }
        });

    });
}


$(function() {


    checkLinkingAuthors();

    //Fix Funny Chars
    //    $('.checkDup').find('a').each(function(i, e) {
    //        var cIa = e;
    //        var newAhtml = decodeURI($(cIa).html().toString());
    //        $(cIa).html(newAhtml);
    //    });
});
