﻿(function($) {

    /**
    * Checks whether a certain element exists.
    *
    * @name     exists
    * @author   Rudy S. Dahbura
    * @type     jQuery
    * @example  $('#myelement').exists();
    *
    */
    $.fn.exists = function() {
        return this.length > 0;
    }

    /**
    * Returns outer HTML.
    *
    * @name     outerHtml
    * @author   Rudy S. Dahbura
    * @type     jQuery
    * @example  $('#myelement').outerHtml();
    *
    */
    $.fn.outerHtml = function() {
        return $('<div />').append(this).html();
    }

    /**
    * Preloads images.
    *
    * @name     preloadImages
    * @author   Rudy S. Dahbura
    * @type     jQuery
    * @example  $.preloadImages('img1', 'img2', 'img3');
    *
    */
    $.fn.preloadImages = function() {
        for (var i = 0; i < arguments.length; i++) {
            $('<img />').attr('src', arguments[i]);
        }
    }

    /**
    * Resets selected option of a select tag.
    *
    * @name     removeSelected
    * @author   Rudy S. Dahbura
    * @type     jQuery
    * @example  $.removeSelected();
    *
    */
    $.fn.removeSelected = function() {
        return this.each(function() {
            if (this.tagName == 'SELECT') {
                $('option:selected', this).removeAttr('selected');
            }
        });
    }

})(jQuery);

$(function() {
    $("#menu a[href='" + location.pathname + "']").parent().addClass("current");
    $("a.sc-link[href^=http]").click(function() {
        window.open($(this).attr("href"));
        return false;
    });
});
