/* HomePageSlideShow */
Ts(function ()
{
    var GalleryEffects;
    var effects;
    tsopSlideShow = function (myOptions)
    {
        var methods = {
            GalStartup: function ()
            {
                myOptions.thisPreloader.find("li").each(function (index)
                {
                    ThisSettings.slideArray[index] = Ts(this);
                });
                myOptions.thisSliderBox.html(ThisSettings.slideArray[0].html());
                if(myOptions.galleryControls)
                {
                    methods.GalAddSlideNumbering(ThisSettings.slideArray.length, myOptions.slideNumBoxesPosRight);
                    methods.GalSquareNonClickEvent(0);
                }
                
              
            },
            getEffect: function (slide)
            {
                var thisSlide = slide
                var fx = 'methods.GalleryEffects.effects.';
                switch (myOptions.thisEffect)
                {
                case 'fade':
                    fx = eval(fx + 'fadeEffect(' + slide + ')');
                    break;
                case 'verticalMatrix':
                    fx = eval(fx + 'verticalMatrix(' + slide + ')');
                default:
                    'fade'
                }
            },
            GalleryEffects: {
                effects: {
                    fadeEffect: function (x)
                    {
                        myOptions.thisSliderBox.fadeOut(function ()
                        {
                            myOptions.thisSliderBox.html(ThisSettings.slideArray[x].html());
                        });
                        myOptions.thisSliderBox.fadeIn();
                        methods.GalSquareNonClickEvent(x);
                    },
                    verticalMatrix: function (x)
                    { /* This Effect is Beta */
                        myOptions.thisSliderBox.fadeOut(1500, function ()
                        {
                            myOptions.thisSliderBox.html(ThisSettings.slideArray[x].html())
                        }).fadeIn('fast');;
                        var thisNumofVertMatrixes = 50;
                        var thisHeight = myOptions.thisSliderBox.height();
                        var thisWidth = Math.round(myOptions.thisSliderBox.width() / thisNumofVertMatrixes);
                        var thisBackground = myOptions.thisSliderBox.find('img').attr('src');
                        var thisStyle = "style='position:absolute; top:100px; opacity: 0.4; display:inline-block; z-index:100; height:" + (thisHeight - 10) + "px; width: " + thisWidth + "px; background-image:url(" + thisBackground + ")' background-repeat: no-repeat; float:left;'";
                        for (i = 0, a = 800; i < thisNumofVertMatrixes; i++)
                        {
                            myOptions.thisSliderBox.find('#vS_' + i + '').css(
                            {
                                'left': 0
                            });
                            myOptions.thisSliderBox.prepend("<div id='vS_" + i + "' " + thisStyle + "></div>")
                            myOptions.thisSliderBox.find('#vS_' + i + '').animate(
                            {
                                'left': a / 10
                            }, i * 40);
                            myOptions.thisSliderBox.find('#vS_' + i + '').animate(
                            {
                                'width': thisWidth / i
                            }, i * 40);
                            myOptions.thisSliderBox.find('#vS_' + i + '').css(
                            {
                                'background-position': i * 18
                            });
                            a += thisWidth * 10;
                        
                            myOptions.thisSliderBox.find('#vS_' + i + '').fadeOut(0);
                        }
                    }
                }
            },
            GalCycle: function ()
            {
                var imagesLength = ThisSettings.slideArray.length;
                if (ThisSettings.thisImageNumb < (imagesLength - 1))
                {
                    ThisSettings.thisImageNumb++;
                  
                    methods.getEffect(ThisSettings.thisImageNumb);
                }
                else if (ThisSettings.thisImageNumb == (imagesLength - 1))
                {
                    ThisSettings.thisImageNumb = 0;
                  
                    methods.getEffect(0);
                }
            },
            GalPlayStop: function ()
            {
                if (ThisSettings.galswitch)
                {
                    ThisSettings.thisInt = setInterval(methods.GalCycle, myOptions.thisDelay)
                }
                else
                {
                    ThisSettings.galswitch = false;
                    clearInterval(ThisSettings.thisInt);
                };
            },
            GalNext: function ()
            {
                clearInterval(ThisSettings.thisInt);
                var imagesLength = ThisSettings.slideArray.length;
                if (ThisSettings.thisImageNumb < (imagesLength - 1))
                {
                    ThisSettings.thisImageNumb++;
                 
                    this.getEffect(ThisSettings.thisImageNumb);
                }
                else if (ThisSettings.thisImageNumb == (imagesLength - 1))
                {
                    ThisSettings.thisImageNumb = 0;
                   
                    this.getEffect(0);
                }
            },
            GalPrev: function ()
            {
                clearInterval(ThisSettings.thisInt);
                var imagesLength = ThisSettings.slideArray.length;
                if (ThisSettings.thisImageNumb > 0)
                {
                    ThisSettings.thisImageNumb--;
                   
                    this.getEffect(ThisSettings.thisImageNumb);
                }
                else if (ThisSettings.thisImageNumb == 0)
                {
                    imagesLength = imagesLength - 1;
                    ThisSettings.thisImageNumb = imagesLength;
                  
                    this.getEffect(imagesLength);
                }
            },
            GalPrevClick: Ts('#galLeftArrow').live('click', function ()
            {
                methods.GalPrev();
            }),
            GalNextClick: Ts('#galRightArrow').live('click', function ()
            {
                methods.GalNext();
            }),
            GalClickStop: Ts('#stopButton').live('click', function ()
            {
                ThisSettings.galswitch = false;
                methods.GalPlayStop();
                Ts(this).addClass('slideControlOff');
                Ts('#playButton').removeClass('slideControlOn').addClass('slideControlOff');
                Ts('#stopButton').removeClass('slideControlOff').addClass('slideControlOn');
            }),
            GalClickPlay: Ts('#playButton').live('click', function ()
            {
                if (ThisSettings.galswitch != true)
                {
                    ThisSettings.galswitch = true;
                    methods.GalPlayStop();
                    Ts('#playButton').removeClass('slideControlOff').addClass('slideControlOn');
                    Ts('#stopButton').removeClass('slideControlOn').addClass('slideControlOff');
                }
            }),
            GalAddSlideNumbering: function (numOfImages, boxPosRight)
            {
             
                for (i = 0, a = 1; i < numOfImages; i++, a++)
                {
                    myOptions.thisSliderBox.parent().
                    append('<div id="slideBoxNum_' + i + '" class="nonActiveSlideNum" style="left:' + (boxPosRight + (a * 40)) / 2 + 'px;"></div>');
                }
            },
            GalAppendGalNav: function ()
            {
                myOptions.thisSliderBox.parent().append('<div id="galLeftArrow"></div>').
                append('<div id="galRightArrow"></div>').
                append('<div id="slideShowControls"><div id="stopButton" class="slideControlOff"></div><span>Stop</span><div id="playButton" class="slideControlOn"></div><span>Play</span></div>')
            },
            GalSquareClick: Ts('.nonActiveSlideNum').live('click', function ()
            {
                clearInterval(ThisSettings.thisInt);
                var translatedSlideNum = Ts(this).attr('id').replace(/slideBoxNum_/, '');
                translatedSlideNum = parseInt(translatedSlideNum);
                methods.getEffect(translatedSlideNum);
                if (Ts(this).siblings().find('ActiveSlideNum'))
                {
                    Ts(this).siblings().removeClass('ActiveSlideNum');
                }
                Ts(this).addClass('ActiveSlideNum');
            }),
            GalSquareNonClickEvent: function (o)
            {
                if(myOptions.galleryControls)
                {
                    var thisBox = Ts('#slideBoxNum_' + o + '');
                    if (thisBox.siblings().find('ActiveSlideNum'))
                    {
                        thisBox.siblings().removeClass('ActiveSlideNum');
                    }
                    thisBox.addClass('ActiveSlideNum');
                }
            }
        };
        myOptions = {
            thisSliderBox: myOptions.thisSliderBox,
            thisSpeed: myOptions.thisSpeed,
            thisDelay: myOptions.thisDelay,
            thisPreloader: myOptions.thisPreloader,
            thisEffect: myOptions.thisEffect,
            slideNumBoxesPosRight: myOptions.slideNumBoxesPosRight,
            galleryControls : myOptions.galleryControls
        }
        var ThisSettings = {
            slideArray: new Array(),
            thisImageNumb: 0,
            galswitch: false,
            thisInt: null
        };
        
        if(myOptions.galleryControls == true)
        {
             methods.GalAppendGalNav();
        }
        methods.GalStartup();
        methods.GalPlayStop();
        ThisSettings.galswitch = true;
        methods.GalPlayStop();
    };
    if (document.URL == 'http://www.torisoper.com/' || document.URL=="http://www.torisoper.com" || document.URL=="http://torisoper.com" || document.URL=="http://torisoper.com/")
    {
        tsopSlideShow(
        {
            'thisSliderBox': Ts('#tsopHome ul'),
            'thisSpeed': 300,
            'thisPreloader': Ts('#tsophomePreloader'),
            'thisDelay': 5000,
            'thisEffect': 'fade',
            'galleryControls' : false
        });
    }
});
