/*

	-- -- -- -- -- -- --
	sjog v1: Javascript File
	last edit: 10 december 08
	-- -- -- -- -- -- --

	File Contents: JQuery Functions
	
*/


$(document).ready(function () {

    $(".inset").wrap("<span class='insetWrapper'></span>");

    /******************* =LI HREF */

    $("#services li").click(function () {
        window.location = $(this).find("a").attr("href"); return false;
    });

    $.fn.increaseFontsize = function (size, speed, easing, callback) {
        return this.animate({ fontSize: size }, speed, easing, callback);
    };

    $('a.increase').click(function () {
        jQuery('p').increaseFontsize(16, 800);
    });

    $('a.decrease').click(function () {
        jQuery('p').increaseFontsize(13, 800);
    });

    $('ul#primaryNav > li').mouseover(function () {
        $(this).addClass('hover');
    });
    $('ul#primaryNav > li').mouseout(function () {
        $(this).removeClass('hover');
    });

    $('.ecard-length-msg').show();
    charactersRemaining($('.ecard-msg-field'), 125);
    $('.ecard-msg-field').keydown(function () {
        charactersRemaining(this, 125);
    });
    $('.ecard-msg-field').keyup(function () {
        charactersRemaining(this, 125);
    });

    $('#primaryNav > li').mouseover(function () {
        var el = $(this).find('ul');
        if (el) {
            var pageright = $("#outerWrapper").position().left + 1000;
            var right = 0 + el.position().left + 507;

            if ((pageright - right) < 0) {
                var newpos = (pageright - right) - 28;
                var css = "margin-left: " + newpos + "px !important";
                $(this).find('ul').attr("style", css);
            }
        }
    });


    /******************* =NO CONFLICT 
	
    jQuery.noConflict(); var $j = jQuery;*/

});

function charactersRemaining(field, max) {
    var max = 125;
    var txt = $(field).val();
    txt = jQuery.trim(txt);

    if (txt.length > max) {
        $(field).val(txt.substring(0, max));

    } else {
        var suffix = " characters remaining";
        var remaining = (max - txt.length);
        if (remaining == 1) {
            suffix = " character remaining";
        }

        $('.ecard-length-msg').text(remaining.toString() + suffix);
    }
}
