var _isLogin = true;
//
function getLog()
{
	return {path : window.location.href, url : window.location.href,  itemId : p_itemId, sectionType : p_sectionType};
}


function sendToFriendMessage() {
    _loader(true);
    //
    if (($('#sf2').val() + '').length < 5) return;
    //
    $.ajax({ type: 'POST', url: '/sendtofriend', data:
	 {
	     userName: $('#sf3').val(),
	     userEmail: $('#sf1').val(),
	     friendEmail: $('#sf2').val(),
	     Message: $('#sf4').val(),
	     url: window.location.href
	 }, success: function (data) { _loader(false); }
    });
}



$(document).ready(function () {





    ///////

    jQuery.extend(jQuery.easing,
		{
		    custom: function (x, t, b, c, d) {
		        var s = 1.70158; var p = 0; var a = c;
		        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
		        if (a < Math.abs(c)) { a = c; var s = p / 4; }
		        else var s = p / (2 * Math.PI) * Math.asin(c / a);
		        return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
		    }
		});
    //


    var friendMail = $('#friend-box-mail');
    var friendShadow = $('#friend-box-shadow');
    if (friendMail.css('display') != null) {
        setInterval(function () {
            $(friendMail).animate({ top: '-5px' }, 600, 'custom', function () {
                $(friendMail).animate({ top: '0px' }, 300)
            });
            $(friendShadow).animate({ opacity: 0.5 }, 600, 'custom', function () {
                $(friendShadow).animate({ opacity: 1 }, 300)
            });
        }, 1500);
    }
        
     ////////////////////////////////
    if ($('#send-friend-btn') != null) {
        $('#send-friend-btn').click(function () {
            sendToFriendMessage();
        //    closeTopBox();
        });
    }




    $('.upper-arrow').click(function () {
        if (_isLogin) {
            $('#upper').css({ 'height': '160px' });
            $('#upper2').css({ 'height': '0px' });
        } else {
            $('#upper').css({ 'height': '0px' });
            $('#upper2').css({ 'height': '160px' });
        }
        _isLogin = !_isLogin;
    });

    $("#whiteboardmarquee").marquee({ yScroll: "bottom", pauseSpeed : 7000 });
    //
    $('#whiteboard-click').click(function () {
        var w = $('#whiteboard-addcomment').css('width') == '50px' ? '855px' : '50px';
        $('#whiteboard-addcomment').animate({ "width": w }, "slow");

    });

    $('#whiteboard-input').keydown(whb);
    $('#whiteboard-input').keyup(whb);

    function whb() {
        var n = 140 - $('#whiteboard-input').val().length;
        $('#whiteboard-counter').html(n);
        if (n < 1) {
            var s = $('#whiteboard-input').val();
            s = s.slice(0, 140);
            $('#whiteboard-input').val(s)
        }
    }


    $('#whiteboard-btn').click(function () {

        var s = $('#whiteboard-input').val();

        if (s.length > 2) {
            _loader(true);
            $('#whiteboard-addcomment').animate({ "width": "50px" }, "slow");
            $.ajax({ type: 'POST', url: '/blackboard/post', data: { message: s }, success: function (data) {

                if ((data + '').length > 10) {
                    $('#whiteboardmarquee').html(data);
                    $("#whiteboardmarquee").marquee({ yScroll: "bottom" });
                }
                _loader(false);
            }
            });
        }
    });

    $('#signin-botton').click(function () {
        var _s = _isLogin ? '2' : '';
        var h = $('#upper' + _s).css('height') == '0px' ? '160px' : '0px';
        $('#upper' + _s).animate({ "height": h }, 'slow');
    });
    $('.footer-poll-arrow').click(function () {
        var b = $(this).attr('id') == 'footer-poll-arrow-top' ? '-=' : '+=';
        $('#footer-poll-container').animate({ scrollTop: b + '75px' }, 'fast');
    });
    //
    if ($('#footer-poll-size').height() < 40)
        $('#footer-box-poll-left').remove();
    //
    var bb = true;
    if ($.browser.msie)
        var bb = parseInt($.browser.version) > 7;
    //
    if (bb) {
        $('#footer-poll-container input[type=radio]').prettyCheckboxes();
        //


        $("#footer-poll-container form").submit(function () {

            if ($('#footer-poll-size input:radio:checked').val() == undefined) {

                alert('لطفا یکی از جواب ها را انتخاب نمایید');
                return false;
            } else {

                _loader(true);
                $.ajax({ type: 'POST', url: '/poll/vote', data: { pollAnswerId: '' + $('#footer-poll-size input:radio:checked').val() }, success: function (data) {
                    $('#footer-poll-container').html(data);
                    _loader(false);
                }
                });
            }

            return false;
        });
    }
    //
    //
    var so = new SWFObject("/content/swf/lg.mpm", "lgmpm", "1", "1", "9", "#880000");
    so.write("lg");
});

function _loader(b)
{
	var l = $('#inner');
	if(b)
		l.fadeIn();
	else
		l.fadeOut();
}

function ValidateAlert() {
    var validationMessage = $("#signup-validation-message").html();
    if (validationMessage != null && validationMessage.trim() != "") {
        alert(validationMessage);
    }
    else {
        alert("ثبت نام انجام شد. لطفا برای تایید حساب کاربری، ایمیل خود را چک کنید.");
    }
}
