var DefaultImageShowCount=2;
var ImageBoxWidth=142;
var ImageWidth="100";
var IMAGE_LABLE_LENGTH=36;

var ImageBlockFormat="<div style=\"float:left;width:##BOXWIDTH##px;\">";
    ImageBlockFormat+="<div style=\"cursor: pointer;height:113px;\" class=\"PhotoAlbum\">";
    ImageBlockFormat+="<div style=\"background-image: url(); padding-top: 15px;text-align:center;height:113px;\" class=\"PhotoAlbumCSS_Photo_InnerImage\">";
    ImageBlockFormat+="##THUMB##";
    ImageBlockFormat+="</div>";
    ImageBlockFormat+="</div>";
    ImageBlockFormat+="<div class=\"AlbumsTextHeading\">";
    ImageBlockFormat+="##IMAGETITLE##";
    ImageBlockFormat+="</div>";
    ImageBlockFormat+="</div>";

var MovieBlockFormat="<div style=\"float:left;width:##BOXWIDTH##px;\">";
    MovieBlockFormat+="<div style=\"cursor: pointer;height:113px;\">";
    MovieBlockFormat+="<div style=\"background-image: url(); padding-top: 15px;text-align:center;height:113px;\">";
    MovieBlockFormat+="##THUMB##";
    MovieBlockFormat+="</div>";
    MovieBlockFormat+="</div>";
    MovieBlockFormat+="<div class=\"Text MusicTextColor\" style=\"padding-right:5px;text-align:center;\">";
    MovieBlockFormat+="##IMAGETITLE##";
    MovieBlockFormat+="</div>";
    MovieBlockFormat+="</div>";


var VideoBlockFormat="<div style=\"float:left;width:##BOXWIDTH##px;\">";
    VideoBlockFormat+="<div style=\"cursor: pointer;height:115;width:130\" class=\"\">";
    VideoBlockFormat+="<div style=\"background-image: url(); padding-top: 15px;text-align:center;\" class=\"\">";
    VideoBlockFormat+="##THUMB##";
    VideoBlockFormat+="</div>";
    VideoBlockFormat+="</div>";
    VideoBlockFormat+="<div onclick=\"OpenVideoPage('##Vid##');\" class=\"AlbumsTextHeading\">";
    VideoBlockFormat+="##IMAGETITLE##";
    VideoBlockFormat+="</div>";
    VideoBlockFormat+="</div>";

var AlbumBlockFormat="<div style=\"float:left;width:##BOXWIDTH##px;padding-top:5px;\" >";
    AlbumBlockFormat+="<div class=\"PhotoAlbumCSS_BG_WithoutImage\" style=\"height:105;width:135;\" title=\"{3}\">";
    AlbumBlockFormat+="<div onclick=\"ShowAlbumPhotos('{0}');\" class=\"PhotoAlbumCSS_Photo_AlbumInnerImage_Small\" style=\"background-image:url('{1}');\">";
    AlbumBlockFormat+="</div>";
    AlbumBlockFormat+="</div>";
    AlbumBlockFormat+="<div onclick=\"ShowAlbumPhotos('{0}');\" class=\"AlbumsTextHeading\">";
    AlbumBlockFormat+="{2}";
    AlbumBlockFormat+="</div>";
    AlbumBlockFormat+="</div>";
 

/*var ThumbFormat="<div class=\"MyTownAlbumCSS_Photo_InnerImage\" style=\"background-image:url('{0}');cursor:pointer;padding-top: 15px;\"></div>";*/
var ThumbFormat="<img src=\"##IMAGEPATH##\" border=\"0\" style=\"height:80px;width:100px;\"  />";

var LinkFormat="<a href=\"{1}\" title=\"{2}\" class=\"Link\">{0}</a>";
var ImageLinkFormat="<a href='{1}' rel='lightbox[Photos]' title=\"{2}\">{0}</a>";
var MovieLinkFormat="<a href='{1}' rel='lightbox[Photos]' title=\"{2}\">{0}</a>";
var AlbumLinkFormat="<a href='ShowPhotos.aspx?AId={1}' title=\"{2}\">{0}</a>";

/*ImageList: Array of Image Objects {"Title":"ImageName","Path":"IMAGE_PATH","ClickAction":"ActiononImageClick"}
  ApplyLinkToTitle : Weather you want to apply href to Title
  ImageListDiv : UniqueId for div containing all images
  ImageListContainerDiv : UniqueId for main container
  NextLinkDivId : UniqueId for Next Link Button for slideshow navigation
  BackLinkDivId : UniqueId for Previous Link Button for slideshow navigation
  SlideShowFor : "IMAGE","VIDEO"
*/
function InitSlideShow(ImageList,ApplyLinkToTitle,ImageListDiv,ImageListContainerDiv,NextLinkDivId,BackLinkDivId,SlideShowFor,ObjDefaultImageShowCount,ObjImageBoxWidth)
{
	var ImageBlocks="";
	var ImageCount=0;

	try
	{
	    if(ObjDefaultImageShowCount)
	    {
	        DefaultImageShowCount=ObjDefaultImageShowCount;
	    }
	    if(ObjImageBoxWidth)
	    {
	        ImageBoxWidth=ObjImageBoxWidth;
	    }
		if(ImageList)
		{
			ImageCount=ImageList.length;
			$j("#"+ImageListContainerDiv).css("width",(ImageBoxWidth*DefaultImageShowCount)+'px');
			$j("#"+ImageListDiv).css("width",(ImageBoxWidth*ImageCount)+'px');
		}
		if(!ApplyLinkToTitle || typeof(ApplyLinkToTitle)=='undefined')
		{
			ApplyLinkToTitle=false;
		}
		if(ImageList && ImageList.length>0)
		{
			for(var i=0;i<ImageList.length;i++)
			{
				var ImageBlock="";

				var Thumb=ThumbFormat;
				Thumb=Thumb.replace("##IMAGEPATH##",ImageList[i].Path);
				Thumb=Thumb.replace(/##IMAGEWIDTH##/gi,ImageWidth);
				var IMGLable=ImageList[i].Title;
				if(IMGLable.length>IMAGE_LABLE_LENGTH)
				{
					IMGLable=ImageList[i].Title.substring(0,IMAGE_LABLE_LENGTH)+"&nbsp;...";
				}
				if(SlideShowFor=="IMAGE")
				{
					ImageBlock=ImageBlockFormat;
					var _Thumb=Thumb;
					Thumb=MVJS.StringFormat(ImageLinkFormat,[_Thumb,ImageList[i].BigImgPath,ImageList[i].Title,ImageListDiv]);
				}
				else if(SlideShowFor=="MOVIE_ALBUM")
				{
					ImageBlock=MovieBlockFormat;
					var _Thumb=Thumb;
					Thumb=MVJS.StringFormat(MovieLinkFormat,[_Thumb,ImageList[i].ClickAction,ImageList[i].Title,ImageListDiv]);
				}				
				else if(SlideShowFor=="VIDEO")
				{
					ImageBlock=VideoBlockFormat.replace(/##Vid##/gi,ImageList[i].ID);
					var _Thumb=Thumb;					
					Thumb=MVJS.FormatString(LinkFormat,[_Thumb,'javascript:OpenVideoPage(\''+ImageList[i].ID+'\')',ImageList[i].Title]);
				}
				else if(SlideShowFor=="ALBUM")
				{
					ImageBlock=AlbumBlockFormat;
					
					ImageBlock=MVJS.StringFormat(ImageBlock,[ImageList[i].ObjectId,ImageList[i].Path,IMGLable,ImageList[i].Title]);

				}
				ImageBlock=ImageBlock.replace(/##THUMB##/gi,Thumb);
				ImageBlock=ImageBlock.replace(/##BOXWIDTH##/gi,ImageBoxWidth);

				if(ApplyLinkToTitle==true)
				{
					ImageBlock=ImageBlock.replace("##IMAGETITLE##",MVJS.StringFormat(LinkFormat,[ImageList[i].ClickAction,""]));
				}
				else
				{
					
					ImageBlock=ImageBlock.replace("##IMAGETITLE##",IMGLable);
				}
				ImageBlocks+=ImageBlock;

			}
			$j("#"+ImageListDiv).html(ImageBlocks);
		}

		InitList(BackLinkDivId,NextLinkDivId,ImageListContainerDiv);
	}
	catch(e)
	{
		alert(e);
	}
}
function InitList(BackLinkId,NextLinkId,FixedWindowId){

	try
	{
	  $j("#"+NextLinkId).click(function(){
	      $j("#"+FixedWindowId).animate({ scrollLeft: "-="+(ImageBoxWidth*DefaultImageShowCount) }, "fast");
	  });

	  $j("#"+BackLinkId).click(function(){
	    $j("#"+FixedWindowId).animate({ scrollLeft: "+="+(ImageBoxWidth*DefaultImageShowCount) }, "fast");
	  });
	}
	catch(e)
	{
		alert(e);
	}
}
function ShowAlbumPhotos(AlbumId)
{
	try
	{
		var Location="ShowPhotos.aspx?AId="+AlbumId +"";
		/*alert('Feature Comming Soon.');		
		'location.href=Location;*/
		Location =ObjSettings.SiteURL +"/" +Location;
		OpenExternalURL(Location);
	}
	catch(e)
	{
		alert(e);
	}
}
function OpenVideoPage(Id)
{
    try
    {       
        var URL = ObjSettings.SiteURL+'/'+'ViewSingleVideo.aspx?VId='+Id;	
        window.open(URL,'ExternalLink'+(Math.round((Math.random()*9)+1)).toString(),'menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,width=800,height=600,top=100,left=100,centerscreen=yes');
    }
    catch(e)
    {
        alert(e);
    }
}

