﻿// JScript File

     var ImageItemCount=0;
     var ImageItemCountMain=0;
     var nodeId = 1048;
     var length = 2;
     
    var IsEndResizeLogo = false;
    var IsEndResizeLogoMain = false;
    
    var ImagesLoaded = 0;
    var MainImagesLoaded = 0;

       $(document).ready(function(){
            LoadImagery();
        });
        
    function LoadImagery() 
    {
       $.getJSON("/ImageryBigHomePage.axd?request=getRandomListAll&nodeId="+nodeId,BuildImageryBig);
       $.getJSON("/ImagerySmallHomePage.axd?request=getRandomListAll&nodeId="+nodeId,BuildImagerySmall);
       setTimeout("startImagery()",1000);
    }

    function BuildImageryBig(ImagesList) 
    {
        if(ImagesList.length == 0)
        {
            ImageItemView = 0;
            LoadImagery();
        }
        else
        {
            var liMain= "";
            var pos=0;
            while(pos<ImagesList.length)
            {
               if(ImagesList[pos] != null && ImagesList[pos].largeImage != null && ImagesList[pos].largeImage != '')
               {
                    liMain += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:100%; height:100%;\" ><tr><td class=\"imagery_block\"><img style=\"float:none;\" src=\"" + ImagesList[pos].largeImage + "\" title=\"" + ImagesList[pos].altText + "\" onload=\"load_mainimage()\" /></td></tr></table>";
               }
               pos++;
            }
           $("#imageryMain").append($(liMain));
           ImageItemCountMain = ImagesList.length;
           setTimeout("ResizeLogoMain()",300);
         }
   }

    function BuildImagerySmall(ImagesList) 
    {
        if(ImagesList.length == 0)
        {
            ImageItemView = 0;
            LoadImagery();
        }
        else
        {
            var li1= "";
            var li2= "";
            var pos=0;
            var posFirst=-1;
            var posSecond=-1;
            while(pos<ImagesList.length)
            {
               if(ImagesList[pos] != null && ImagesList[pos].largeImage != null && ImagesList[pos].largeImage != '')
               {
                        li1 += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:100%; height:100%;\" ><tr><td class=\"imagery_block\"><img style=\"float:none;\" src=\"" + ImagesList[pos].largeImage + "\" title=\"" + ImagesList[pos].altText + "\" onload=\"load_image()\" /></td></tr><tr><td style=\"height:10px;\"></td></tr></table>";
                        
                        if(posFirst == -1)
                        {
                            posFirst = pos;
                        }
                        else
                        {
                            li2 += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:100%; height:100%;\" ><tr><td class=\"imagery_block\"><img style=\"float:none;\" src=\"" + ImagesList[pos].largeImage + "\" title=\"" + ImagesList[pos].altText + "\" onload=\"load_image()\" /></td></tr><tr><td style=\"height:10px;\"></td></tr></table>";
                        }
                        pos++;
               }
               else
               {
                    pos++;
               }
            }
            if(ImagesList[posFirst].largeImage != null && ImagesList[posFirst].largeImage != '')
            {
                 li2 += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:100%; height:100%;\" ><tr><td class=\"imagery_block\"><img style=\"float:none;\" src=\"" + ImagesList[posFirst].largeImage + "\" title=\"" + ImagesList[posFirst].altText + "\" onload=\"load_image()\" /></td></tr><tr><td style=\"height:10px;\"></td></tr></table>";
            }
           $("#imagery1").append($(li1));
           $("#imagery2").append($(li2));
           ImageItemCount = ImagesList.length * 2;
           setTimeout("ResizeLogo()",300);
         }
   }
    
    function ShowImage1(url, alt)
    {
      // $("#Image1").attr("height","");
      // $("#Image1").attr("width","");
       $("#Image1").attr("src",url);
        $("#Image1").attr("title",alt);

        $("#Image1").load(function(){
            $("#Image1").css("display","block");
        });
   }
    function ShowImage2(url, alt)
    {
     //  $("#Image2").attr("height","");
     //  $("#Image2").attr("width","");
       $("#Image2").attr("src",url);
        $("#Image2").attr("title",alt);

        $("#Image2").load(function(){
            $("#Image2").css("display","block");
        });
   }
       function ShowImageMain(url, alt)
    {
     //  $("#Image1").attr("height","");
     //  $("#Image1").attr("width","");
       $("#ImageMain").attr("src",url);
        $("#ImageMain").attr("title",alt);

        $("#ImageMain").load(function(){
            $("#ImageMain").css("display","block");
        });
   }


var ResizeCount = 0;
var CountRepeat = 0;
var IsStartImagery = false;

function load_image()
{
    ImagesLoaded++
}
function load_mainimage()
{
    MainImagesLoaded++
}
function ResizeLogo()
{

    LoadCountImages = 0;
    CountImages = 0;
        $("#imagery img").each(function()
       {
        CountImages++;
	maxWidth = 260;
	maxHeigth = 170;

        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);
   }
   else
 //  if(LoadCountImages > 4 || LoadCountImages == CountImages)
   {
        IsEndResizeLogo = true;
   }
   CountRepeat++;
  
}
var ResizeCountMain = 0;
var CountRepeatMain = 0;

function ResizeLogoMain()
{

    LoadCountImages = 0;
    CountImages = 0;
        $("#imageryMain img").each(function()
       {
        CountImages++;
	maxWidth = 419;
	maxHeigth = 350;

        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 && CountRepeatMain < 2000)
   {  
        setTimeout("ResizeLogoMain()",300);
   }
   else
 //  if(LoadCountImages > 4 || LoadCountImages == CountImages)
   {
        IsEndResizeLogoMain = true;
   }
  
    
    CountRepeatMain++;
  
}

var CountRepeatStartImagery = 0;
function startImagery()
{
    
   if((MainImagesLoaded == ImageItemCountMain && ImagesLoaded == ImageItemCount)
    || (MainImagesLoaded > 1 && CountRepeatStartImagery > 100)
    || (ImagesLoaded > 2 && CountRepeatStartImagery > 100))
   {
        $('#imageryMain').innerfade({
          speed: 750,
          timeout: 6000,
          containerheight: '350px' })
        $('#imagery1').innerfade({
          speed: 750,
          timeout: 6000,
          containerheight: '170px' })
        $('#imagery2').innerfade({
          speed: 750,
          timeout: 6000,
          containerheight: '170px' })
   }
   else
   {
       setTimeout("startImagery()",1000);
   }
   CountRepeatStartImagery++;
}
