﻿// JScript File

function IllustratorsGallery()
{
    this.initialize = function(letter)
    {                
        this.Browse(letter);
    }
    
    this.Browse = function(browseBy)
    {
        $("#SearchBox").val('');
        var alphas = $(".searchAlpha a[class=on]");   
        alphas.removeClass("on");    
        $("#"+browseBy).addClass("on");
        this.renderEvents(browseBy);
    }
    
    
    this.renderEvents = function(term)
    {
        $.getJSON('Ajax/GetIllustratorGallery.aspx', {action:"browse", browseBy:term}, 
        function (data) 
        {
            var Results = $("#Results").html("").get(0);
            
            if(data.Error)
            {
                $(Results).html("No illustrators found");
            }
            else
            {
                var ill = "";
                $.each(data.Head, function (i, item){
                    if(item.DisplayName.Length > 0)
                        ill += "<a href='Illustrators-Gallery.aspx?i="+item.EncodedUserID+"'>"+item.DisplayName+"</a>";
                    else
                        ill += "<a href='Illustrators-Gallery.aspx?i="+item.EncodedUserID+"'>"+item.FirstName + " " + item.LastName+"</a>"; 
                   
                });
                $(Results).html(ill);
            }
        } );

    }
        
    this.Search = function()
    {    
        var query = $("#SearchBox").val();
        var alphas = $(".searchAlpha a[class=on]");   
        alphas.removeClass("on");    
        
        
        $.getJSON('Ajax/GetIllustratorGallery.aspx', {action:"search", search:query}, 
        function (data) 
        {
            var Results = $("#Results").html("").get(0);
            
            if(data.Error)
            {
                $(Results).html("No illustrators found");
            }
            else
            {
                var ill = "";
                $.each(data.Head, function (i, item){
                    if(item.DisplayName.Length > 0)
                        ill += "<a href='Illustrators-Gallery.aspx?i="+item.EncodedUserID+"'>"+item.DisplayName+"</a>";
                    else
                        ill += "<a href='Illustrators-Gallery.aspx?i="+item.EncodedUserID+"'>"+item.FirstName + " " + item.LastName+"</a>"; 
                   
                });
                $(Results).html(ill);
            }
        } );       
    }
    
    this.SearchKeyPress = function(e)
    {
        var code;
	    if (!e) var e = window.event;
	    if (e.keyCode) code = e.keyCode;
	    else if (e.which) code = e.which;
	    if(code == 13)
	    {
	        this.Search();
	        return false;
	    }
	    return true;
    }
}

var IllustratorsGallery = new IllustratorsGallery;
