﻿
    $(document).ready(function(){
        $('#pwd').bind('keypress', function(e) {
            var code = (e.keyCode ? e.keyCode : e.which);
             if(code == 13) {
               Login($('#usr').val(),$('#pwd').val())
             }
            });
            
            
            
        $(window).scroll(function(e) {
            //alert('scroll '+$(window).scrollTop());
            $('#newPopup').css('top',10+$(window).scrollTop()+'px');
            $('#TagList').css('top',100+$(window).scrollTop()+'px');
            });
            
        });
    
    function Login(usr, pwd)
    {
        $.ajax({
            type: "POST",
            url: "/ZoeAnthistle.asmx/Login",
            data: "{userName:'"+usr+"',password:'"+pwd+"'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                if(msg=='SUCCESS')
                {
                    $('.loggedout').addClass('hidden');
                    $('.loggedin').removeClass('hidden');
                    $('#cred').addClass('hidden');
                    $('#loginResult').html('');
                    $('.userName').html('logged in as: '+usr);
                    window.location.reload();
                }
                else
                {
                    $('#loginResult').html(msg);
                    
                }
            }
          });
    }
    
    function i_iv(imageId)
    {
        //Image_IncrementViews
        $.ajax({
            type: "POST",
            url: "/ZoeAnthistle.asmx/Image_IncrementViews",
            data: "{imageId:"+imageId+"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {}
          });
    }
    
    function Logout()
    {
        $.ajax({
            type: "POST",
            url: "/ZoeAnthistle.asmx/Logout",
            data: "{}", //userName:'"+usr+"',password:'"+pwd+"'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
              $('.loggedin').addClass('hidden');
              $('.loggedout').removeClass('hidden');
              $('#cred').addClass('hidden');
              window.location.reload();
            }
          });
    }
    
    function PopupOne(imageId, num)
    {
        Popup(imageId, num);
        i_iv(imageId);
    }
    
    function NewPopup(el)
    {
        Popup ($('#'+el.id).attr('ImageId'), $('#'+el.id).attr('imagenum'));
        i_iv($('#'+el.id).attr('ImageId'));
    }
    
    function Popup(imageId, num)
    {
        $("div#newPopup").html($("div#slideshow_orig").html());
    
        $("div.slideshow").cycle({ 
            fx:     'fade', 
            speed:  'slow', 
            timeout: 0, 
            next:   'img.next', 
            prev:   'img.prev',
            startingSlide:num
        });
        
        $('#newPopup').fadeIn();
        
        //get tagselector
        $('#TagList').html('');
        //var imageId = parseInt($('#'+el.id).attr('ImageId'),10); 
        //ShowTags(imageId);
    }
    
    function ClosePopup()
    {
        $('#newPopup').fadeOut();
        $('#TagList').html('');
    }
