﻿/// <reference path="jquery-1.4.1.min.js" />
/// <reference path="components.js" />

$(function () {
    $("a[rel='external']")
        .live('click', function (e) {
            e.preventDefault();
            window.open($(this).attr('href'));
        });
});

// Fancy Panels
$(function () {
    $(".fancy-panel")
        .each(function () { $(this).fancyPanel(); });
});

// Homepage
$(function () {
    var $homepage = $("#homepage-content");
    var $signupTeaser = $homepage.find("#setup-event-title-panel");
    var $signupTeaserEventTitle = $signupTeaser.find("#setup-event-title-event-title");
    $signupTeaserEventTitle
        .watermark("e.g. Cheese & Wine Tasting Night");
    $signupTeaser
        .find("form")
            .submit(function (e) {
                e.preventDefault();
                $("#signup-event-details-event-title")
                    .val($signupTeaserEventTitle.val())
                    .change();
                $signupTeaser
                    .closest(".fancy-panel-slider-inner")
                        .animate({ marginLeft: '-900px' }, 300, 'linear', function()
                        {
                            $("#signup-event-details-event-slug").focus();
                        });
            });
});

// Login
$(function () {
    $("#login-panel #security-panel-email-address")
        .focus();
});

// Signup
$(function () {
    $("#signup-panel")
        .find("#security-panel-email-address")
            .focus()
        .end()
        .find(".login-or-signup input[type=radio]")
            .change(function () {
                $(this).closest("fieldset").find(".error").slideUp();
                var ul = $(this).closest("ul");
                var isExistingUser = (ul.find("input:radio:checked").val() == 'true');
                var div = ul.find(".new-user div");
                if (isExistingUser) div.show('slow');
                else div.hide('slow');
            })
        .end()
        .find("input[type=radio]")
            .each(function () {
                this.checked = false;
            });
});

// Setup - Step 1
$(function () {
    $("#signup-event-details-event-slug")
        .urlSlug($("#signup-event-details-event-title"));
});

// Sellers
$(function () {
    $("ul.management-tasks li")
        .click(function (e) {
            e.preventDefault();
            document.location = $(this).find("a:first").attr('href');
        });
});

$(function () {
    $("textarea.wysiwyg").wysiwyg();
});
