Movie search layout tweaks with cookie persistence This works as intended, but was wondering if there is a more efficient way of coding this.

if (window.location.href.indexOf('/search/') &gt;= 0) {
    switch ($.cookie("Layout")) {
        case "Poster":
            $("link:first").attr("href", "../css/list.css");
            break;
        case "Description":
            $("link:first").attr("href", "../css/desc.css");
    }
    $(function () {
        $(".Poster").click(function () {
            $("link:first").attr("href", "../css/list.css");
            $.cookie("Movie_Layout", "Poster", {
                expires: 365,
                path: '/media/search',
                secure: true
            });
            $('.content-genre, .searchresults').hide().delay(75).fadeIn(275);
            window.scrollTo(0, 0);
        });
        $(".Description").click(function () {
            $("link:first").attr("href", "../css/desc.css");
            $.cookie("Movie_Layout", "Description", {
                expires: 365,
                path: '/media/search',
                secure: true
            });
            $('.content-genre, .searchresults').hide().delay(75).fadeIn(275);
            window.scrollTo(0, 0);
        });
    });
} else {
    switch ($.cookie("Layout")) {
        case "Poster":
            $("link:first").attr("href", "css/list.css");
            break;
        case "Description":
            $("link:first").attr("href", "css/desc.css");
    }
    $(function () {
        $(".Poster").click(function () {
            $("link:first").attr("href", "css/list.css");
            $.cookie("Movie_Layout", "Poster", {
                expires: 365,
                path: '/media',
                secure: true
            });
            $('.content-genre, .searchresults').hide().delay(75).fadeIn(275);
            window.scrollTo(0, 0);
        });
        $(".Description").click(function () {
            $("link:first").attr("href", "css/desc.css");
            $.cookie("Movie_Layout", "Description", {
                expires: 365,
                path: '/media',
                secure: true
            });
            $('.content-genre, .searchresults').hide().delay(75).fadeIn(275);
            window.scrollTo(0, 0);
        });
    });
}
This seems a bit simpler (in terms of code repeating)

var Layout = {
    'Poster': {
        href: 'css/list.css'
    },
        'Description': {
        href: 'css/desc.css'
    }
};

function setLink(file, pathFix) {
    $('link:first').attr('href', pathFix + file);
}

$(function () {
    var currentPathFix = '',
        initialLayout = $.cookie("Layout");
    if (window.location.href.indexOf('/search/') &gt;= 0) {
        currentPathFix = '../';
    }
    setLink(Layout( initialLayout ), currentPathFix );
    $.each(Layout, function (key, item) {
        $('.' + key).click(function () {
            setLink(item.href, currentPathFix);
            $.cookie("Movie_Layout", key, {
                expires: 365,
                path: '/media/search',
                secure: true
            });
            $('.content-genre, .searchresults').hide().delay(75).fadeIn(275);
            window.scrollTo(0, 0);
        });
    });
});