﻿// JScript File

     var ImageItemCount=0;
     var ImageItemCountMain=0;
     var nodeId = 1048;
     var length = 2;
     
       $(document).ready(function(){
            LoadImageryLeft();
        });
        
    function LoadImageryLeft() 
    {
       $.getJSON("/ImageryLeft.axd?request=getRandomListAll&nodeId="+pageId,BuildImageryLeft)
    }

    function BuildImageryLeft(ImagesList) 
    {
        if(ImagesList.length == 0)
        {
            ImageItemView = 0;
          //  LoadImagery();
        }
        else
        {
            var div= "";
            var pos=0;
            while(pos<ImagesList.length)
            {
               if(ImagesList.length > 2)
                    div += "<div style=\"display:none;\">";
               else
                    div += "<div>";
                    
               if(ImagesList[pos] != null && ImagesList[pos].largeImage != null && ImagesList[pos].largeImage != '')
               {
                   div += "<div class=\"image\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:100%; \" >";
                   div += "<tr><td class=\"imagery_left_block\"><img src=\"" + ImagesList[pos].largeImage + "\" title=\"" + ImagesList[pos].altText + "\" /></td></tr>";
                   div += "<tr><td align=\"center\" valign=\"middle\"></td></tr>";
                   div += "</table></div>";
                   pos++;
               }
               else
               {
                    pos++;
               }
               if(ImagesList[pos] != null && ImagesList[pos].largeImage != null && ImagesList[pos].largeImage != '')
               {
                    div += "<div class=\"image\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:100%; \" >";
                    div += "<tr><td class=\"imagery_left_block\"><img src=\"" + ImagesList[pos].largeImage + "\" title=\"" + ImagesList[pos].altText + "\" /></td></tr>";
                    div += "<tr><td align=\"center\" valign=\"middle\"></td></tr>";
                    div += "</table></div>";
                    pos++;
               }
               else
               {
                    pos++;
               }
               div += "</div>";
            }
           $(".sidebar").append($(div));
           ImageItemCount = ImagesList.length * 2;
           setTimeout("ResizeLogo()",300);
           setTimeout("startImagery()",1000);
         // startImagery();
         }
   }
    

var ResizeCount = 0;
var CountRepeat = 0;

function ResizeLogo()
{

    LoadCountImages = 0;
    CountImages = 0;
        $(".sidebar img").each(function()
       {
        CountImages++;
	maxWidth = 333;
	maxHeigth = 500;

        originalWidth = this.width;
        originalHeigth = this.height;       
	if(originalWidth > 0 && originalHeigth  > 0)
	{
		// Resample image
		if (originalWidth  > maxWidth)
		{
			$(this).attr("height",(originalHeigth  * (maxWidth / originalWidth)));
			$(this).attr("width", maxWidth);

        		originalWidth = this.width;
        		originalHeigth = this.height;
		}

		if (originalHeigth  > maxHeigth)
		{
			$(this).attr("height", maxHeigth);
			$(this).attr("width", (originalWidth * (maxHeigth / originalHeigth)));
		}
		

		LoadCountImages++;
	}
	
 });
 if(LoadCountImages < CountImages && CountRepeat < 2000)
   {  
        setTimeout("ResizeLogo()",300);
   }
   CountRepeat++;
  
}

function startImagery()
{
$('.sidebar').innerfade({
  speed: 750,
  timeout: 6000,
  containerheight: '800px' })
}
