﻿$(document).ready(function () {
    /////////////////////////////SURVEY///////////////////////////////////////////////
    surveyarr = [
['Does your company have an eLearning strategy?<br />', 'yn'],
['Have you considered mLearning?<br />', 'yn'],
['Good eLearning is all down to good instructional design<br />', 'tf']
];
    var sindex = Math.ceil(Math.random() * surveyarr.length);
    $('.survey').attr('id', sindex);
    $('.survey').after(surveyarr[sindex - 1][0]);
 
    function submitSurvey(question, answer) {

        datar = "{'response':'" + answer + "','surveyid':'" + question + "'}";
        $.ajax({
            type: "POST",
            url: "/survey.asmx/SaveSurvey",
            data: "" + datar + "",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                for (x in msg)
                    $("#survey").html(msg[x]);
              //  sTimer = window.setTimeout(function () {
                   // $('#survey').hide();
                    //window.clearTimeout(timer);
               // }, 3000);
            }


        });

    }
  //  var sTimer;
    //sTimer = window.setTimeout(function () {
     //   $('#survey').show().animate({ height: "30px" }).animate({ height: "27px" }, "fast");
      //  window.clearTimeout(timer);
 //   }, 2000);

  
        if (surveyarr[sindex - 1][1] == 'yn'){
            $('.option:eq(0)').attr('id', 'yes').append('<img src="/images/yes_btn.png" \/>&nbsp;'); $('.option:eq(1)').attr('id', 'no').append('<img src="/images/no_btn.png" \/>');
            }
        else{
            $('.option:eq(0)').attr('id', 'true').append('<img src="/images/true_btn.png" \/>&nbsp;'); $('.option:eq(1)').attr('id', 'false').append('<img src="/images/false_btn.png" \/>');
    }



    $('.option').bind('click', function () {
        submitSurvey($(this).parent().find('.survey').attr('id'), $(this).attr('id'))

    });

    //////////////////////////////////////////////////////////////////////////////////
    var open = false;
    var timer;
    $('input').focus(function () {
        window.clearTimeout(timer);
    });
    $('input').blur(function () {

        timer = window.setTimeout(function () {
            $('#search').animate({ marginTop: "-45px" }, "fast");
            open = false;
        }, 7000);
    });
    $('#searchButton').click(function () {

        if (!open) {
            $('#search').animate({ marginTop: "-4px" }).animate({ marginTop: "-10px" }, "fast");
            window.clearTimeout(timer);
            timer = window.setTimeout(function () {
                $('#search').animate({ marginTop: "-55px" }, "fast");
                open = false;
            }, 7000);
            open = true;
        }
        else {
            window.clearTimeout(timer);
            $('#search').animate({ marginTop: "-55px" }, "fast");
            open = false;
        }

    });
 
    if ($('#slider').length > 0)
        $('#slider').nivoSlider({ effect: 'random', pauseTime: 10000 });
});

function mypopup(url) {
    leftVal = Math.floor((screen.width-500 ) / 2);
    topVal = Math.floor((screen.height - 300) / 2);
    mywindow = window.open("" + url + "", "mywindow", "location=0,status=0,scrollbars=0,  width=500,height=300,left=" + leftVal + ",top=" + topVal + "");
} 

