﻿$(document).ready(function () {
    var timeUp = setTimeout('hintStart();', 5000);
    $("#HintBox").click(function () {
        $("#HintBox_Body").show(1000, function () {
            $("#HintBox").css('cursor', 'default');
            $("#close").show(500);
        });
    });
    $("#close").click(function () {
        $("#HintBox").fadeTo(1000, 0, function () {
            $("#HintBox").remove();
        });
    });
    var opacity = 0.65, toOpacity = 0.8, duration = 250;
    //set opacity ASAP and events
    $('#HintBox').css('opacity', opacity).hover(function () {
        $(this).fadeTo(duration, toOpacity);
        $("#Tip").fadeTo(duration, toOpacity);
    }, function () {
        $(this).fadeTo(duration, opacity);
        $("#Tip").fadeTo(duration, opacity);
    });

    $('.closeButtom').click(function toggleList() {
        $('.MessageBox').animate({ 'height': 'toggle', 'opacity': 'toggle' }, 1000);
        $('.rel').delay(1000).animate({ 'opacity': 'toggle', 'visibility': 'toggle' }, 1000);
        $('.rel').css('height', '1px');
        $('.rel').css('width', '1px');
    });
});

function Rss(type) {
    var lan = 'Persian';
    if ($('.lan').text() == 'true') {
        lan = 'English';
    }
    $('.rel').css('height', '100%');
    $('.rel').css('width', '100%');
    $('.rel').animate({ 'opacity': 'toggle', 'visibility': 'toggle' }, 1000);
    $('.MessageBox').css('left', (($(window).width() / 2) - 235) + 'px');
    $('.MessageBox').css('top', (($(window).height() / 2) - 200) + 'px');
    $('.MessageBox').delay(1000).animate({ 'height': 'toggle', 'opacity': 'toggle' }, 1000);
    $('#rssLink2').attr('href', 'http://persiangulfcup.org/xml/' + lan + '_' + type + '_News.xml');
    $('#rssLink1').attr('href', 'RssReader.aspx?type=' + type);
}

function goTo(page) {
    document.location.href = page;
}

function hintStart() {
    var temp = $('.appPath').text();
    var temp2 = $('.lan').text();
    $('#HintBox').ajaxError(function (e, jqxhr, settings, exception) {
    });

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: '../services/UserServices.asmx/GetMyHint',
        dataType: "json",
        data: '{"pageAddress":"' + temp + '","IsEn":"' + temp2 + '"}',
        success: function (result) {
            var obj = jQuery.parseJSON(result.d);
            if (obj != null) {
                if (obj.Body != '') {
                    if (obj.Title != '') {
                        $("#HintBox_Title").html('<NOBR>' + obj.Title + '</NOBR>');
                    } else {
                        $("#HintBox_Title").html('?');
                    }
                    $("#HintBox_Body").append(obj.Body);
                    $("#HintBox").fadeTo(2000, 0.65);
                }
            }
        },
        error: function (e) {

        }
    });
};
