﻿// General JS's used across the site
var isLettoPage = false;

$(function () {
    // Popup text above flags in header menu
    $('.bubble').each(function () {
        var trigger = $('.trigger', this);
        var popup = $('.popup', this);
        $(trigger.get(0)).mouseover(function () {
            popup.css({
                top: -24,
                right: 5,
                display: 'inline-block',
                zIndex: 50
            }).animate({
                top: -30,
                opacity: 1
            },
            200);
            return false;
        }).mouseout(function () {
            popup.css({
                zIndex: -10,
                opacity: 0,
                display: 'none'
            });
            return false;
        });
    });

    // Add JS tag to payment link
    addJsTagToPaymentLink();
});

function addJsTagToPaymentLink() {
    $("a[href*='payment.aspx?']").each(function() { 
        var link = $(this).attr('href') + "&" + "js=1";
        $(this).attr('href',link); 
    });
    
    $("a[href*='payment.aspx']:not([href*='payment.aspx?'])").each(function(){
        var link = $(this).attr('href') + "?" + "js=1";
        $(this).attr('href',link); 
    });
}

/* Folding menu*/
/***************/
function foldOutLettoMenu(time) {
    if ($(".fold-menu .links").is(":hidden"))
    {
        $(".fold-menu .links").css({'background-color': '#fcf5dc'}).slideDown(time);
        $(".fold-menu .header a").toggleClass('expanded');
    } else {
        $(".fold-menu .links").slideUp(time);
        $(".fold-menu .header a").toggleClass('expanded');
    }
}

$('.fold-menu .header')
.hover(function () {
    $(this) //hover in
        .addClass('pretty-hover')
        .css({'color': '#E50000'});
}, function () {
    $(this) //hover out
        .removeClass('pretty-hover')
        .css({'color': '#3B382D'}); }
)
.click(function () {
    foldOutLettoMenu(300);
    return false;
});

//Remove html tags from quicksearch when search button is clicked
$('.searchButton').click(function () {
    var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
    $('.sidebar_searchfield').val($('.sidebar_searchfield').val().replace(regexp, ""));
});

// Unobtrusive popup for library posts
$('A[rel="librarypostpopup"]').click(function () {
    popWindow($(this).attr('href'), 700, 500);
    return false;
});
