// Any jquery calls common to admin and frontend
$(function () {
    //Used for Textbox placeholder values
    $('input[type=text]').focus(function () {
        if ($(this).val() == $(this).attr('placeholder') && $(this).attr('placeholder') != '') {
            $(this).val('');
        }
    });
    $('input[type=text]').blur(function () {
        if ($(this).val() == '' && $(this).attr('placeholder') != '') {
            $(this).val($(this).attr('placeholder'));
        }
    });
});

function checkScrollPos(elementname, itemCount, dir, offset, posName) {
    var posElement = document.getElementById(posName);
    var element = $('#' + elementname);
    var left = '';

    if (posElement.value == '') {
        left = element.css('left');
        left = left.substring(0, left.indexOf('px'));
    }
    else {
        left = posElement.value;
    }

    if (left >= 0 && dir > 0)
    { return false; }
    else {
        if (left < (offset * itemCount) && dir < 0) {
            return false;
        }
        else {
            posElement.value = left - (offset * dir);

            $(function () {
                $("#" + elementname).animate({ left: '' + posElement.value }, 500, function () { });
            });
        }
    }
}

function MoveScroller(elementname, value, posName) {
    var posElement = document.getElementById(posName);
    posElement.value = -value;
    $(function () {
        $("#" + elementname).animate({ left: '' + posElement.value }, 500, function () { });
    });
}

function jtoggle(clientID, action, obj) {
    var divToToggle = $('#' + clientID);
    switch (divToToggle.css('display')) {
        case 'none':
            divToToggle.css('display', 'block');
            break;
        case 'block':
            divToToggle.css('display', 'none');
            break;

    }
}

function fadeAndRemove(clientID, timeout) {
    setTimeout(function () {
        $("#" + clientID).fadeOut("slow", function () {
            $("#" + clientID).remove();
        });

    }, timeout);
}
