var myimages = new Array();
        /*
        function preloadimages() {
            
            for (i = 0; i < preloadimages.arguments.length; i++) {
                myimages[i] = new Image();
                myimages[i].src = preloadimages.arguments[i];
            }
        }
        preloadimages(  "images/home-slider/image1.jpg", "images/home-slider/image2.jpg", "images/home-slider/image3.jpg", "images/home-slider/image5.jpg",
                        "images/home-slider/image6.jpg", "images/home-slider/image7.jpg", "images/home-slider/image8.jpg", "images/home-slider/image9.jpg",
                        "images/home-slider/image10.jpg", "images/home-slider/image11.jpg", "images/home-slider/image12.jpg", "images/home-slider/image13.jpg",
                        "images/home-slider/image14.jpg" );
        */

        var lstImages = [
                            "images/home-slider/image10.jpg", "images/home-slider/image11.jpg", "images/home-slider/image12.jpg", "images/home-slider/image13.jpg",
                            "images/home-slider/image14.jpg", "images/home-slider/image15.jpg", "images/home-slider/image16.jpg", "images/home-slider/image1.jpg", "images/home-slider/image2.jpg", "images/home-slider/image3.jpg",
                            "images/home-slider/image5.jpg", "images/home-slider/image6.jpg", "images/home-slider/image7.jpg", "images/home-slider/image8.jpg",
                            "images/home-slider/image9.jpg"                           
                         ];

    var rand_pix_5_Slides = new Array();

    var rand_pixV2 = rand_pix.slice(0);
   
            var Found = false;
            var MaxValue = 14; //(Example 2 is equal to: 0,1,2)
            var NumUnique = 5;  //The number of unique numbers required
            var Count = 0;
            var isLoadedFirtTime = true;
            var Current = new Array(NumUnique);

            function GetUnique() {
                for (i = 0; Count < NumUnique; Count++) {
                    Found = false;
                    var rndValue = get_random();
                    var j = 0;
                    for (j = 0; j < Current.length; j++) {
                        if (Current[j] == rndValue) {
                            Found = true;
                            break;
                        }
                    }
                    if (Found) {
                        Count--;
                    } else {
                        Current[Count] = rndValue;
                    }
                }
            }
            function get_random() {
                var ranNum = Math.round(Math.random() * MaxValue);
                return ranNum;
            }
            function ClearArrayGetNewUniq() {
                Current = [];
                Current = new Array(NumUnique);
                Count = 0;
                GetUnique();
            }
            function GenerateNewArrayOfSlidesAndPreLoadImages() {
                var i = 0;
                for (i = 0; i < Current.length; i++) {
                    rand_pix_5_Slides.push(rand_pixV2[Current[i]]);
                }
                for (i = 0; i < Current.length; i++) {
                    myimages[i] = new Image();
                    myimages[i].src = lstImages[Current[i]];
                }
            }
            function GetUniqSuggestedValues() {
                var isToContinueForFurtherUniqSearch = true;
                var iFirstPart = 0;
                var iSecondPart = 0;
                var i = 0;
                do {
                    iFirstPart = 0;
                    iSecondPart = 0;
                    ClearArrayGetNewUniq();
                    for (i = 0; i < Current.length; i++) {
                        if (Current[i] < 8) {
                            iFirstPart++;
                        }
                        else if (Current[i] >= 8) {
                            iSecondPart++;
                        }
                    }
                    if (iFirstPart == 3 && iSecondPart == 2) {
                        isToContinueForFurtherUniqSearch = false;
                    }
                } while (isToContinueForFurtherUniqSearch);
            }

            function GetUniqSuggestedValuesVersion3()
            {
                for (i = 0; Count < NumUnique; Count++) {
                    Found = false;
                    var rndValue = get_random();

                    if(Count < 3 && rndValue >= 8)
                    {
                        Count--;
                        continue;
                    }
                    else if(Count >=3 && rndValue <=7)
                    {
                        Count--;
                        continue;
                    }

                    var j = 0;
                    for (j = 0; j < Current.length; j++) {
                        if (Current[j] == rndValue) {
                            Found = true;
                            break;
                        }
                    }
                    if (Found) {
                        Count--;
                    } else {
                        Current[Count] = rndValue;
                    }
                }
            }   
            //GetUnique();
            //GetUniqSuggestedValues();
            GetUniqSuggestedValuesVersion3();
            GenerateNewArrayOfSlidesAndPreLoadImages();
            //RandomSlideV2(0);
        
        $(document).ready(function () {
                var mygallery = new simpleGallery({ wrapperid: "homegallery1",
                    dimensions: [1000, 734],
                    imagearray: rand_pix_5_Slides,
                    autoplay: [true, 8000, 500],
                    persist: false,
                    fadeduration: 2000,
                    oninit: function () { },
                    onslide: function (curslide, i) {
                        /*if (!isLoadedFirtTime) {
                        if (i == 0) {
                        ClearArrayGetNewUniq(); // Get Uniq numbers , on Second round, third round and onwards.
                        }
                        }
                        RandomSlideV2(i + 1);
                        isLoadedFirtTime = false;*/
                    }
                })
        });

        function RandomSlideV2(currentSlide) {
            var MaxSlide = 14;
            if (currentSlide >= MaxSlide) {
                currentSlide = MaxSlide - 1;
                //alert("completed");
            }
            //var rdmNumber = 0;
            //rdmNumber = Math.floor(Math.random() * (MaxSlide));
            //rand_pix[currentSlide] = rand_pixV2[rdmNumber];
            rand_pix[0] = rand_pixV2[Current[0]];
            rand_pix[currentSlide] = rand_pixV2[Current[currentSlide]];
        }
