﻿
    var strImgs = [];
    
    var strCat1Imgs = [];
    var strCat2Imgs = [];
    var strCat3Imgs = [];
    var strCat4Imgs = [];
    var strCat5Imgs = [];
    
    var intCurrentIdx = new Array(0, 0, 0, 0, 0);
                
    function fcnFade(strID, intStartOpacity, intEndOpacity, intFadeTime) 
    { 
        //speed for each frame 
        var intSpeed = Math.round(intFadeTime / 100); 
        var intTimer = 0; 

        //determine the direction for the blending, if start and end are the same nothing happens 
        if(intStartOpacity > intEndOpacity) 
        { 
            for(intI = intStartOpacity; intI >= intEndOpacity; intI--) 
            { 
                setTimeout("fcnChangeOpac(" + intI + ",'" + strID + "')",(intTimer * intSpeed)); 
                intTimer++; 
            } 
        }
        else if(intStartOpacity < intEndOpacity) 
        { 
            for(intI = intStartOpacity; intI <= intEndOpacity; intI++) 
            { 
                setTimeout("fcnChangeOpac(" + intI + ",'" + strID + "')",(intTimer * intSpeed)); 
                intTimer++; 
            } 
        } 
    } 

    //change the opacity for different browsers 
    function fcnChangeOpac(intOpacity, strID) 
    { 
        var objImg = document.getElementById(strID).style; 
        objImg.opacity = (intOpacity / 100); 
        objImg.MozOpacity = (intOpacity / 100); 
        objImg.KhtmlOpacity = (intOpacity / 100); 
        objImg.filter = "alpha(opacity=" + intOpacity + ")"; 
    } 
    
    function fcnRotate(blnIn, strIDToRotate, intImgIdx)
    {                        
        if(blnIn)
        {
            document.getElementById(strIDToRotate).src = strImgs[intImgIdx];
        
            if(intImgIdx+5<(strImgs.length))
                intImgIdx+=5;
            else
                intImgIdx=intImgIdx+5-strImgs.length;
            
            fcnFadeIn(strIDToRotate);
        }
        else
        {
            fcnFadeOut(strIDToRotate);
        }
            
        setTimeout("fcnRotate("+!blnIn+", '"+strIDToRotate+"', "+intImgIdx+")",5000);        
    }
    
    function fcnDividedRotate(blnIn, intCategory, strIDToRotate)
    {
        if(blnIn)
        {            
            var strImg = "";
            
            switch(intCategory)
            {
                case 0:
                {
                    strImg = strCat1Imgs[intCurrentIdx[intCategory]];                        
                    
                    if(strCat1Imgs[intCurrentIdx[intCategory]+1])
                        intCurrentIdx[intCategory]++;
                    else
                        intCurrentIdx[intCategory]=0;
                        
                    break;
                }
                case 1:
                {
                    strImg = strCat2Imgs[intCurrentIdx[intCategory]];       
                    
                    if(strCat2Imgs[intCurrentIdx[intCategory]+1])
                        intCurrentIdx[intCategory]++;
                    else
                        intCurrentIdx[intCategory]=0;
                                         
                    break;
                }
                case 2:
                {
                    strImg = strCat3Imgs[intCurrentIdx[intCategory]];      
                    
                    if(strCat3Imgs[intCurrentIdx[intCategory]+1])
                        intCurrentIdx[intCategory]++;
                    else
                        intCurrentIdx[intCategory]=0;
                                          
                    break;
                }
                case 3:
                {
                    strImg = strCat4Imgs[intCurrentIdx[intCategory]];      
                    
                    if(strCat4Imgs[intCurrentIdx[intCategory]+1])
                        intCurrentIdx[intCategory]++;
                    else
                        intCurrentIdx[intCategory]=0;
                                          
                    break;
                }
                case 4:
                {
                    strImg = strCat5Imgs[intCurrentIdx[intCategory]];     
                    
                    if(strCat5Imgs[intCurrentIdx[intCategory]+1])
                        intCurrentIdx[intCategory]++;
                    else
                        intCurrentIdx[intCategory]=0;
                                           
                    break;
                }
            }
            
            //document.getElementById("txtJSDev").value=strImg;
            
            //strImg = "Imgs/GalleriesImgs/" + strImg;
            
            document.getElementById(strIDToRotate).src = strImg;
            
            fcnFadeIn(strIDToRotate);
        }
        else
        {
            fcnFadeOut(strIDToRotate);
        }
            
        setTimeout("fcnDividedRotate("+!blnIn+", "+intCategory+", '"+strIDToRotate+"')",5000);
    }
    
    function fcnFadeIn(strIDToFadeIn)
    {
        var intI=0;
        
        fcnFade(strIDToFadeIn, 0, 100, 3000);
    }
    
    function fcnFadeOut(strIDToFadeOut)
    {
        fcnFade(strIDToFadeOut, 100, 0, 3000);
    }

    function fcnStartRotate()
    {
        //load array with imgs from xml doc     
        var xmlDoc=null;
    	
    	if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || navigator.userAgent.toLowerCase().indexOf('safari') > -1)
		{
		    var xmlhttp = new window.XMLHttpRequest();
            xmlhttp.open("GET", "IndexSquares.xml", false);
            xmlhttp.send(null);
            var xmlDoc = xmlhttp.responseXML.documentElement;
		}
    	else if (window.ActiveXObject)
    	{// code for IE
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false;
			xmlDoc.load("IndexSquares.xml");
		}
		else if (document.implementation.createDocument)
		{// code for Mozilla, Firefox, Opera, etc.
			xmlDoc=document.implementation.createDocument("","",null);
			xmlDoc.async=false;
			xmlDoc.load("IndexSquares.xml");
		}
		else
		{
			alert('Your browser does not support the image display for this page.');
		}
		
		if (xmlDoc!=null)
		{            
			var xmlImgs=xmlDoc.getElementsByTagName("IndexImg");
			
			var intSort=[];
			
			for (intI = 0; intI < xmlImgs.length; intI++)
            {
                var strFile ="Imgs/IndexImgs/" + xmlImgs[intI].getElementsByTagName("strFileName")[0].childNodes[0].nodeValue;
                var intIndex = xmlImgs[intI].getElementsByTagName("intSortOrder")[0].childNodes[0].nodeValue;
                
                imgPL = new Image();                
                imgPL.src = strFile;
                
                strImgs[intI] = strFile;                
                intSort[intI] = intIndex - 0;
            }
            
            //sort array	
            strImgs = fcnSortArray(strImgs, intSort);		
        }
        
        setTimeout("fcnRotate(true, 'img1', 2)", 3500);
        fcnRotate(true, "img2", 0);
        setTimeout("fcnRotate(true, 'img3', 4)", 7000);
        setTimeout("fcnRotate(true, 'img4', 3)", 5250);
        setTimeout("fcnRotate(true, 'img5', 1)", 1750);
    }
    
    function fcnSortArray(strVals, intSorts)
    {        
		var blnReSort=true;
		
		while(blnReSort)
		{
		    blnReSort=false;
		    
		    for(intI = 0; intI<=intSorts.length; intI++)
		    {
		        if(intSorts[intI] > intSorts[intI+1])
		        {
		            var str1 = strVals[intI];
		            var str2 = strVals[intI+1];
		            
		            var int1 = intSorts[intI];
		            var int2 = intSorts[intI+1];
		            
		            strVals[intI]=str2;
		            strVals[intI+1]=str1;
		            
		            intSorts[intI] = int2;
		            intSorts[intI+1] = int1;
		            
		            blnReSort=true;
		        }
		    }
		}
		
        return strVals;
    }

    function fcnStartDividedRotate()
    {       
        //load array with categories and images from xml file
        var xmlDoc=null;
    	
    	if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || navigator.userAgent.toLowerCase().indexOf('safari') > -1)
		{
		    var xmlhttp = new window.XMLHttpRequest();
            xmlhttp.open("GET", "IndexSquares.xml", false);
            xmlhttp.send(null);
            var xmlDoc = xmlhttp.responseXML.documentElement;
		}
    	else if (window.ActiveXObject)
    	{// code for IE
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false;
			xmlDoc.load("IndexSquares.xml");
		}
		else if (document.implementation.createDocument)
		{// code for Mozilla, Firefox, Opera, etc.
			xmlDoc=document.implementation.createDocument("","",null);
			xmlDoc.async=false;
			xmlDoc.load("IndexSquares.xml");
		}
		else
		{
			alert('Your browser does not support the image display for this page.');
		}
		
		if (xmlDoc!=null)
		{            
			var xmlImgs=xmlDoc.getElementsByTagName("IndexImg");
			
			var intSort1 = [];
			var intSort2 = [];
			var intSort3 = [];
			var intSort4 = [];
			var intSort5 = [];
			
			for (intI = 0; intI < xmlImgs.length; intI++)
            {
                var strCat = xmlImgs[intI].getElementsByTagName("strCategory")[0].childNodes[0].nodeValue;
                var strFile ="Imgs/IndexImgs/" + xmlImgs[intI].getElementsByTagName("strFileName")[0].childNodes[0].nodeValue;
                
                imgPL = new Image();                
                imgPL.src = strFile;
                
                var intIndex = xmlImgs[intI].getElementsByTagName("intSortOrder")[0].childNodes[0].nodeValue;                
                var intCategory = -1;
                
                switch(strCat)
                {
                    case "Wedding":
                        intCategory = 0;
                        strCat1Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort1[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    case "Senior":
                        intCategory = 1;
                        strCat2Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort2[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    case "Family":
                        intCategory = 2;
                        strCat3Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort3[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    case "Headshot":                        
                        intCategory = 3;
                        strCat4Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort4[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    case "Boudoir":
                        intCategory = 4;
                        strCat5Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort5[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    default:
                        alert("Unhandled category: "+strCat+" - "+strFile);
                        break;
                }                
                
                intCurrentIdx[intCategory] = intCurrentIdx[intCategory] + 1;
            }
        }
        
        //sort arrays
        strCat1Imgs=fcnSortArray(strCat1Imgs,intSort1);
        strCat2Imgs=fcnSortArray(strCat2Imgs,intSort2);
        strCat3Imgs=fcnSortArray(strCat3Imgs,intSort3);
        strCat4Imgs=fcnSortArray(strCat4Imgs,intSort4);
        strCat5Imgs=fcnSortArray(strCat5Imgs,intSort5);
        
        intCurrentIdx[0] = 0;
        intCurrentIdx[1] = 0;
        intCurrentIdx[2] = 0;
        intCurrentIdx[3] = 0;
        intCurrentIdx[4] = 0;
     
        //start rotating images    
        setTimeout("fcnDividedRotate(true, 0, 'img1')", 3500);
        fcnDividedRotate(true, 1, "img2");
        setTimeout("fcnDividedRotate(true, 2, 'img3')", 7000);
        setTimeout("fcnDividedRotate(true, 3, 'img4')", 5250);
        setTimeout("fcnDividedRotate(true, 4, 'img5')", 1750);
    }

    function fcnStartDividedRotate4()
    {       
        //load array with categories and images from xml file
        var xmlDoc=null;
    	
    	if (window.ActiveXObject)
    	{// code for IE
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		}
		else if (document.implementation.createDocument)
		{// code for Mozilla, Firefox, Opera, etc.
			xmlDoc=document.implementation.createDocument("","",null);
		}
		else
		{
			alert('Your browser does not support the image display for this page.');
		}
		
		if (xmlDoc!=null)
		{
			xmlDoc.async=false;
			xmlDoc.load("IndexSquares.xml");
            
			var xmlImgs=xmlDoc.getElementsByTagName("IndexImg");
			
			var intSort1 = [];
			var intSort2 = [];
			var intSort3 = [];
			var intSort4 = [];
			
			for (intI = 0; intI < xmlImgs.length; intI++)
            {
                var strCat = xmlImgs[intI].getElementsByTagName("strCategory")[0].childNodes[0].nodeValue;
                //var strFile = xmlImgs[intI].getElementsByTagName("strFileName")[0].childNodes[0].nodeValue;
                var strFile ="Imgs/IndexImgs/" + xmlImgs[intI].getElementsByTagName("strFileName")[0].childNodes[0].nodeValue;
                
                imgPL = new Image();                
                imgPL.src = strFile;
                
                var intIndex = xmlImgs[intI].getElementsByTagName("intSortOrder")[0].childNodes[0].nodeValue;                
                var intCategory = -1;
                
                switch(strCat)
                {
                    case "Wedding":
                        intCategory = 0;
                        strCat1Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort1[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    case "Senior":
                        intCategory = 1;
                        strCat2Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort2[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    case "Family":
                        intCategory = 2;
                        strCat3Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort3[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    case "Headshot":                        
                        intCategory = 3;
                        strCat4Imgs[intCurrentIdx[intCategory]] = strFile;
                        intSort4[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    case "Boudoir":
                        intCategory = 4;
                        strCat5Imgs[intCurrentIdx[intCategory]] = strFile;
                        //intSort5[intCurrentIdx[intCategory]] = intIndex - 0;
                        break;
                        
                    default:
                        alert("Unhandled category: "+strCat+" - "+strFile);
                        break;
                }                
                
                intCurrentIdx[intCategory] = intCurrentIdx[intCategory] + 1;
            }
        }
        
        //sort arrays
        strCat1Imgs=fcnSortArray(strCat1Imgs,intSort1);
        strCat2Imgs=fcnSortArray(strCat2Imgs,intSort2);
        strCat3Imgs=fcnSortArray(strCat3Imgs,intSort3);
        strCat4Imgs=fcnSortArray(strCat4Imgs,intSort4);
        
        intCurrentIdx[0] = 0;
        intCurrentIdx[1] = 0;
        intCurrentIdx[2] = 0;
        intCurrentIdx[3] = 0;
     
        //start rotating images    
        setTimeout("fcnDividedRotate(true, 0, 'img1')", 900);
        fcnDividedRotate(true, 1, "img2");
        setTimeout("fcnDividedRotate(true, 2, 'img3')", 1750);
        setTimeout("fcnDividedRotate(true, 3, 'img4')", 1300);
    }
    
    function fcnResizeMainPane(_intBottomMargin)
    {
        var viewportwidth = fcnGetViewportWidth();
        var viewportheight = fcnGetViewportHeight();

        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

        viewportheight -= (46 + parseInt(_intBottomMargin));

        var objImgMain = document.getElementById('imgMain');
        
        var intImgNewH = 0;
        var intImgNewW = 0;
        var intImgOriginalH = 0;
        var intImgOriginalW = 0;

        var dblRatio=0;

        var imgMain = new Image();

        imgMain.src = objImgMain.src;
        
        intImgOriginalH = imgMain.height;
        intImgOriginalW = imgMain.width;            

        dblRatio = intImgOriginalH / intImgOriginalW;

        intImgNewW = viewportwidth - 280;

        intImgNewH = (intImgNewW * intImgOriginalH) / intImgOriginalW;

        if(intImgNewH > viewportheight)
        {
            intImgNewH = viewportheight;
            intImgNewW = (intImgOriginalW * intImgNewH) / intImgOriginalH;
        }
        
        if(intImgNewH > intImgOriginalH)
        {
            intImgNewH = intImgOriginalH;
            intImgNewW = intImgOriginalW;
        }
        
        objImgMain.height = intImgNewH;
        objImgMain.width = intImgNewW;
        
		if (window.ActiveXObject)
		{//ie        
            objImgMain.style.visibility = "visible";
        }
        else
        {
            objImgMain.style.display = "inline";                
        }
    }
    
    function fcnResizeMainPaneDiv(_intBottomMargin)
    {
        var viewportwidth = fcnGetViewportWidth();
        var viewportheight = fcnGetViewportHeight();

        viewportheight -= (46 + _intBottomMargin);

        var objMain = document.getElementById('divMain');
        var objContent=document.getElementById('divContent');
        
        objMain.style.width=viewportwidth-_intBottomMargin+"px";

        objMain.style.height=viewportheight-_intBottomMargin+"px";       
        
        objContent.style.height=objMain.style.height;
    }
    
    function fcnGetViewportHeight()
    { 
        var viewportheight;

        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

        if (typeof window.innerWidth != 'undefined') { viewportheight = window.innerHeight }

        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

        else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) { viewportheight = document.documentElement.clientHeight }

        // older versions of IE

        else { viewportheight = document.getElementsByTagName('body')[0].clientHeight }
        
        return viewportheight;
    }
    
    function fcnGetViewportWidth()
    {
        var viewportwidth;

        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

        if (typeof window.innerWidth != 'undefined') { viewportwidth = window.innerWidth }

        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

        else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) { viewportwidth = document.documentElement.clientWidth }

        // older versions of IE

        else { viewportwidth = document.getElementsByTagName('body')[0].clientWidth }
        
        return viewportwidth;
    }