﻿var carouselDisplay = 6;
jQuery.noConflict();

jQuery(document).ready(function ($) {
    // Open links with rel="external" in new windows
    $("a[rel='external']").click(function () {
        return !window.open($(this).attr("href"));
    });

    //css tweaks
    //subnavigation length
    var size = 38 * ($("#subNavigation ul.semiperm li").size() - $("#subNavigation ul.semiperm li ul li").size());
    $(".subNavigationMenu").padding({ bottom: size });
    var mediaHeight = $("#mediaPanels").height();
    if (mediaHeight > $("#subNavigation").height()) {
        $("#subNavigation").attr('style', 'height: ' + mediaHeight + 'px');
    }
    //page titles
    $('#mediaPanels .panel').each(function (index) {
        var hidden = false;
        if ($(this).attr('style') == 'display: none') {
            hidden = true;
            $(this).attr('style', '');
        }

        var text = $(this).find('.text');
        if (text.find('.title').height() > 60) {
            var newBottom = text.find('.title').height() - 56;
            text.attr('style', 'overflow:visible; bottom: ' + newBottom + 'px');
            var newHeight = text.find('.title').height() + 18;
            text.find('.titleBackground').attr('style', 'height: ' + newHeight + 'px');
        }
        if (text.find('.description').height() > 70) {
            var newBottom = text.find('.description').height() - 61;
            text.attr('style', 'overflow:visible; bottom: ' + newBottom + 'px');
            var newHeight = text.find('.description').height() + 47;
            text.find('.background').attr('style', 'height: ' + newHeight +'px');
        }

        if (hidden) {
            $(this).attr('style', 'display: none');
        }
    });
});

function getParameterByName(url, name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(url);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

//submit form on return
function checkSubmit(e, form) {
    if (e && e.keyCode == 13) {
        jQuery('#' + form).submit();
    }
}
