﻿function swapArtists(name)
{
    document.getElementById("GalleryList").innerHTML = "<img src='images/ajax_loading_sq.gif' />";
    switch(name)
    {
    case "668": document.getElementById("artistSelector").className = "tabs_box tb_current"; break;
    case "669": document.getElementById("artistSelector").className = "tabs_box tb_comedy"; break;
    case "670": document.getElementById("artistSelector").className = "tabs_box tb_other"; break;
    default: break;
    }
    Photos.GetArtistDataSet(name,pribrandid,publicgallery,privategallery,swapArtist_Postback);
}

function swapArtist_Postback(response)
{
    try 
    {
        var ds = response.value;
	    if(ds!=null && typeof(ds) == "object" && ds.Tables!=null) 
	    {
	        var s = new Array();
	        var name = "";
	        //s[s.length] = "<div class='content'>";
	        if(ds.Tables[0].Rows.length > 0)
	        {
	            //for(var i=0;i<ds.Tables[0].Rows.length;i++)
	            for(var i=0;i<ds.Tables[0].Rows.length;i++)
	            {
	                //s[s.length] = "<div class='Artist'>";
	                if(ds.Tables[0].Rows[i].ArtistName.length >= artistnamecharlimit)
	                {
	                    var namessplit = ds.Tables[0].Rows[i].ArtistName.split(" ");
	                    if((namessplit[0].length + namessplit[1].length) <= (artistnamecharlimit-3))
	                    {
	                        name = namessplit[0]+" "+namessplit[1]+" ..";
	                    }
	                    else 
	                    {
	                        name = namessplit[0]+" ..";
	                    }
	                    //name = ds.Tables[0].Rows[i].ArtistName.substr(0,artistnamecharlimit)+"...";	            
	                }
	                else 
	                {
	                    name = ds.Tables[0].Rows[i].ArtistName;
	                }	           
	                if(ds.Tables[0].Rows[i].GalleryID == '')
	                {
	                
	                    //s[s.length] = "<span class='photo_item' style='background-image: url(" + missinggalleryimg + ");background-position:center center;background-attachment: scroll;background-repeat:no-repeat;' ><img  src='images/spacer.gif' width='"+photothumbwidth+"' height='"+photothumbheight+"' alt='' border='0' /></div><div class='ArtistName'><a href='"+artistsdetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"' >"+name+"</a></div>";
	                    
	                    // fix for defect #50:(artist name wrapping) -eda 4.26.7  --> cont'd below
	                    //s[s.length] = "<a href='#' class='photo_item'><img style='background-image:url(" + missinggalleryimg + ");background-position: center center;background-repeat: no-repeat;' src='images/spacer.gif' width='120px' height='90px'/><div style='width:120px;'>"+name+"</div></a>";
	                    s[s.length] = "<a href='#' class='photo_item_modified'><img src='" + missinggalleryimg + "' /><div>"+name+"</div></a>";
    	                
	                }
	                else 
	                {
	                    if(ds.Tables[0].Rows[i].ImageUrl == '')
	                    {
	                       //s[s.length] = "<div class='ArtistThumb' style='background-image: url(" + missinggalleryimg + ");background-position:center center;background-attachment: scroll;background-repeat:no-repeat;' ><a href='"+photodetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"&GalleryID="+ds.Tables[0].Rows[i].GalleryID+"' ><img  src='images/spacer.gif' width='"+photothumbwidth+"' height='"+photothumbheight+"' alt='' border='0' /></a></div><div class='ArtistName'><a href='"+artistsdetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"' >"+name+"</a></div>"; 
	                       // fix for defect #50:(artist name wrapping) -eda 4.26.7  --> cont'd below
	                       s[s.length] = "<a href='"+photodetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"&GalleryID="+ds.Tables[0].Rows[i].GalleryID+"' class='photo_item_modified'><img src='" + missinggalleryimg + "' /><div>"+name+"</div></a>";
	                    }
	                    else 
	                    {
	                       //s[s.length] = "<div class='ArtistThumb' style='background-image: url(" + ds.Tables[0].Rows[i].ImageUrl + ");background-position:center center;background-attachment: scroll;background-repeat:no-repeat;' ><a href='"+photodetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"&GalleryID="+ds.Tables[0].Rows[i].GalleryID+"' ><img  src='images/spacer.gif' width='"+photothumbwidth+"' height='"+photothumbheight+"' alt='' border='0' /></a></div><div class='ArtistName'><a href='"+artistsdetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"' >"+name+"</a></div>";
	                       // fix for defect #50:(artist name wrapping) -eda 4.26.7 
	                       s[s.length] = "<a href='"+photodetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"&GalleryID="+ds.Tables[0].Rows[i].GalleryID+"' class='photo_item_modified'><img src='" + ds.Tables[0].Rows[i].ImageUrl + "' /><div>"+name+"</div></a>";
	                    }
    	                
	                }
	                //s[s.length] = "</div>";
	            }
	        }
	        else 
	        {
	            s[s.length] ="There are no artists here yet.";
	        }
	        //s[s.length] = "</div>";
	        document.getElementById("GalleryList").innerHTML = s.join("");	    
	    }
	}
	catch(ex)
	{
	    document.getElementById("GalleryList").innerHTML = "There was an internal error.";
	}    
}
