﻿
$(document).ready(function() {

    $("a[href='#']").live("click", function(e) {
        e.preventDefault();
    });

    // Track External Link Clicks
    $("a.external").live("click", function(e) {
        e.preventDefault();
        var destUrl = $(this).attr("href").split('://', 2)[1];
        _gaq.push(['_trackEvent', 'external', destUrl]);
        window.open('http://' + destUrl);
    });

    $("a.ad").live("click", function() {
        var destUrl = $(this).attr("href").split('://', 2)[1];
        _gaq.push(['_trackEvent', 'advertisement', destUrl]);
    });

    // Setup Facebox
    if (authenticated == 1) {
        $('a[rel*=facebox], a[rel*=authFacebox]').facebox({
            loadingImage: '/Content/facebox/loading.gif',
            closeImage: '/Content/facebox/closelabel.gif'
        });
    } else {
        $('a[rel*=facebox]').facebox({
            loadingImage: '/Content/facebox/loading.gif',
            closeImage: '/Content/facebox/closelabel.gif'
        });

        $('a[rel*=authFacebox]').addClass("loginRequired").click(function(e) {
            window.location = "/Account.aspx/Login?ReturnUrl=" + location.href;
            e.preventDefault();
        });
    }


    $('a.faceboxClose').live("click", function(e) {
        $.facebox.close();
    });

    var tooltipDefaults = {
        className: "tooltip",
        cornerRadius: 5,
        orient: "above",
        width: 175,
        arrowHeight: 7,
        arrowInset: 15,
        region: "#tooltipDemo"
    }

    $(".calloutLink").click(function(e) {
        e.preventDefault();
    })
    .hover(function() {
        $(this).callout($.extend({}, tooltipDefaults, {
            content: $(this).attr('href'),
            region: 'body',
            width: 300,
            cornerRadius: 8,
            className: 'callout'
        }));
    }, function() {
        $(this).closeCallout();
    });

    jQuery.validator.setDefaults({
        success: "valid"
    }); ;

    $.timeEntry.setDefaults({
        spinnerImage: '/Content/timeEntry/spinnerUpDown.png',
        spinnerSize: [15, 20, 0],
        spinnerBigSize: [30, 32, 0],
        spinnerIncDecOnly: true
    });
});

function setupForm(formId)
{
    // Setup validate
    $(formId).validate();
}

function renderResourceInfo(item) {
    return "<li class='item'><strong><a href='" +
            item.url + "'>" + item.name + "</a></strong><br/>" +
            "<div class='rating_outer_sm'><div class='rating_inner' style='width: " + item.rating * 16 + "px;' ></div></div></li>";
}

function logEvent(id, type, data) {
    $.ajax({
      url: "/Resource.aspx/LogEvent",
      type: "POST",
      data: ({
        id : id,
        type : type,
        data: data
        })
    });
}