﻿// JScript File

     var ImageItemCount=0;
     var ImageItemCountMain=0;
     
       $(document).ready(function(){
            LoadImageryTop();
        });
        
    function LoadImageryTop() 
    {
       $.getJSON("/ImageryTopBanner.axd?request=getRandomListAll&nodeId="+pageId,BuildImageryTop)
    }

    function BuildImageryTop(ImagesList) 
    {
        if(ImagesList.length == 0)
        {
            ImageItemView = 0;
         //   LoadImageryTop();
        }
        else
        {
            var div= "";
            var pos=0;
            while(pos<ImagesList.length)
            {
               if(ImagesList[pos] == null || ImagesList[pos].largeImage == null || ImagesList[pos].largeImage == '')
               {
                    pos++;
               }
               if(ImagesList[pos] != null)
               {
                    if(ImagesList.length > 2)
                    {
                        div += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"display:none; width:100%; height:100%;\" ><tr><td class=\"imagery_left_block\"><img src=\"" + ImagesList[pos].largeImage + "\" title=\"" + ImagesList[pos].altText + "\" /></td></tr></table>";
                    }
                    else
                    {
                        div += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:100%; height:100%;\" ><tr><td class=\"imagery_left_block\"><img src=\"" + ImagesList[pos].largeImage + "\" title=\"" + ImagesList[pos].altText + "\" /></td></tr></table>";
                    }
                    pos++;
               }
            }
           $("#banner").append($(div));
           setTimeout("ResizeLogoTop()",300);
           setTimeout("startImageryTop()",1000);
         // startImagery();
         }
   }
    

var CountRepeatTop = 0;

function ResizeLogoTop()
{

    LoadCountImages = 0;
    CountImages = 0;
        $("#banner img").each(function()
       {
        CountImages++;

        originalWidth = this.width;
        originalHeigth = this.height;       
	if(originalWidth > 0 && originalHeigth  > 0)
	{
		// Resample image
		if (originalWidth  > maxWidthTopBanner)
		{
			$(this).attr("height",(originalHeigth  * (maxWidthTopBanner / originalWidth)));
			$(this).attr("width", maxWidthTopBanner);

        		originalWidth = this.width;
        		originalHeigth = this.height;
		}

		if (originalHeigth  > maxHeigthTopBanner)
		{
			$(this).attr("height", maxHeigthTopBanner);
			$(this).attr("width", (originalWidth * (maxHeigthTopBanner / originalHeigth)));
		}
		

		LoadCountImages++;
	}
	
 });
 if(LoadCountImages < CountImages && CountRepeatTop < 2000)
   {  
        setTimeout("ResizeLogoTop()",300);
   }
   CountRepeatTop++;
  
}

function startImageryTop()
{
  var h = maxHeigthTopBanner + 'px';
$('#banner').innerfade({
  speed: 750,
  timeout: 6000,
  containerheight: h })
}
