﻿function swapArtists(name)
{
    document.getElementById("WallpaperList").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;
    default: break;
    }
    Wallpapers.GetArtistDataSet(name,pribrandid,wallpaperimgsize,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='ArtistWrapper'>";
	    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]+" ..";
	                }
    
	            }
	            else 
	            {
	                name = ds.Tables[0].Rows[i].ArtistName;
	            }
	            if(ds.Tables[0].Rows[i].WallpaperURL == '')
	            {
	                //s[s.length] = "<div class='ArtistThumb' 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>";
	                s[s.length] = "<a href='"+photodetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"' class='freestuff_item'><img style='background-image:url(" + missinggalleryimg + ");background-position: center center;background-repeat: no-repeat;' src='images/spacer.gif' width='120' height='90'/>"+name+"</a>";
	            }
	            else 
	            {
	                if(ds.Tables[0].Rows[i].WallpaperURL == '')
	                {
	                   //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+"' ><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>"; 
	                   s[s.length] = "<a href='"+photodetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"' class='freestuff_item'><img style='background-image:url(" + missinggalleryimg + ");background-position: center center;background-repeat: no-repeat;' src='images/spacer.gif' width='120' height='90'/>"+name+"</a>";
	                }
	                else 
	                {
	                   //s[s.length] = "<div class='ArtistThumb' style='background-image: url(" + ds.Tables[0].Rows[i].WallpaperURL + ");background-position:center center;background-attachment: scroll;background-repeat:no-repeat;' ><a href='"+photodetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"' ><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>";
	                   s[s.length] = "<a href='"+photodetailpagename+"ArtistID="+ds.Tables[0].Rows[i].ArtistID+"' class='freestuff_item'><img style='background-image:url(" + ds.Tables[0].Rows[i].WallpaperURL + ");background-position: center center;background-repeat: no-repeat;' src='images/spacer.gif' width='120' height='90'/>"+name+"</a>";
	                }
	                
	            }
	           // s[s.length] = "</div>";
	        }
	    }
	    else 
	    {
	        s[s.length] ="There are no artists here yet.";
	    }
	    //s[s.length] = "</div>";
	    document.getElementById("WallpaperList").innerHTML = s.join("");
	   	    
	}
	
	}
	catch(ex)
	{
	  document.getElementById("WallpaperList").innerHTML = "There was an internal error.";  
	} 
}

