﻿

<!--
function Rotator(obj) {
    var $Rot = this;
    this.rot = obj;
    this.target = $('.bg-image');
    this.image = $('#BGImageFade');
    this.animationType = 'scroll';    
    this.active = 0;
    this.max = 0;
    this.next = 0;
    this.t = null, // timeout
    this.autoscroll = 10000; // or bool:false to disable
    this.stopanimation = false;
    this.init = function() {                
        this.getList();
        this.setTargetArea();
        $(window).unbind('resize').bind('resize',function() {
            $Rot.setTargetArea();
        })
        this.setImage(0);
        this.appendControls();
    };    
    this.getList = function() {                
        this.max = $(this.rot).find('.rot-list li').length;
        for(i=0;i<this.max;i++) $Rot.rot.find('.bullet-nav').append('<a href="#" rel="'+i+'"><span>['+i+']</span></a>');        
        $Rot.rot.find('.bullet-nav a').bind('click',function() {
            if($Rot.stopanimation || $(this).attr('rel') == $Rot.active) return false;
            $Rot.setImage($(this).attr('rel'),($(this).attr('rel') > $Rot.active) ? 'next' : 'prev');
            return false;
        });
    };
    this.setTargetArea = function() {               
        if($(window).width() > 1010) {
            var locW = $(window).width();               
            $('html').css({'width': locW+'px'});            
            $('html').css({'overflow-x':'hidden'});
        } else {
            var locW = 1010;                                    
            $('html').css({'width':'1010px'});            
            $('html').css({'overflow-x':'auto'});
        }
                
        $(this.target).css({'width':'1385px'});
        if(locW <= 1385) {                        
            var move = ((1385 - locW)/2);                        
            $(this.target).css({'left': '-'+move+'px'});            
        } else {
            $(this.target).css({'left': '0'});
        }
    }
    this.appendImage = function(i,ord) {        
        var locAlt = '';
        if($($Rot.rot).find('.rot-list li').eq(i).find('img').length > 0 && $($Rot.rot).find('.rot-list li').eq(i).find('img').attr('title') != '') {
            locAlt = $($Rot.rot).find('.rot-list li').eq(i).find('img').attr('title');
        }
        if(ord == 'prev') {
            $($Rot.image).prepend($($Rot.rot).find('.rot-list li').eq(i).html());
        } else {
            $($Rot.image).append($($Rot.rot).find('.rot-list li').eq(i).html());
        }                
        if(locAlt != '') {
            $('.click-area').show().find('a').attr('href',locAlt);
            $($Rot.image).find('img').attr('title','');
        } else {
            $('.click-area').hide();
        }
    }    
    this.showImage = function() {        
        // $($Rot.image).animate({opacity: 1},'slow',function() {$Rot.stopanimation = false;});
        $($Rot.image).show();
        $Rot.stopanimation = false;
    }    
    this.setImage = function(i,ord) {        
        this.stopanimation = true;
        this.active = Number(i);                            
        this.next = (this.active + 2 <= this.max) ? this.active + 1 : 0;
        this.prev = (this.active - 1 > -1) ? this.active - 1 : this.max - 1;                            
        if($.trim($(this.image).html()) != '') {
            switch(this.animationType) {
                case 'scroll' :                
                    $(this.image).css({'width':$(this.image).width()*2+'px'}).children().wrap('<div class="kill-me-now" style="float: '+ ((ord == 'prev') ? 'right' : 'left') +';"/>');
                    $Rot.appendImage(i,ord);                                    
                    if(ord == 'prev') {                         
                        $(this.image).css({'margin-left':'-1385px'});                                            
                        $(this.image).animate({'margin-left':0},'slow',function() {                        
                            $('.kill-me-now').remove();
                            $($Rot.image).css({'width':$($Rot.image).width()/2+'px'});
                            $Rot.stopanimation = false;
                        });                             
                    } else {
                        $(this.image).find('.kill-me-now').animate({'margin-left':'-1385px'},'slow',function() {                        
                            $('.kill-me-now').remove();
                            $($Rot.image).css({'width':$($Rot.image).width()/2+'px'});                            
                            $Rot.stopanimation = false;
                        });     
                    }                    
                    break;;
                case 'fade':
                default:
                    $(this.image).animate({opacity: 0},'slow',function() {
                        $(this).html('');
                        $Rot.appendImage(i);                
                        $Rot.showImage();
                    });        
                    break;;
            }                
        } else {
            $Rot.appendImage(i);                
            $Rot.showImage();            
        }
        this.rot.find('.bullet-nav a').removeClass('active').filter('*[rel="'+this.active+'"]').addClass('active');
        console.log('Active: '+this.active,'Max: '+this.max,'Prev: '+this.prev,'Next: '+this.next);                
        if(this.autoscroll !== false) {
            console.log(this.autoscroll);
            if(isNaN(this.autoscroll)) this.autoscroll = 10000;
            clearTimeout(this.t);
            this.t = setTimeout(function() {
                console.log('Timeout triggered after: ',$Rot.autoscroll);
                $Rot.setImage($Rot.next);
            },this.autoscroll);
        }
    }
    this.appendControls = function() {        
        $(this.rot).find('.arrow-left').click(function() {
            if(!$Rot.stopanimation) $Rot.setImage($Rot.prev,'prev');            
        });
        $(this.rot).find('.arrow-right').click(function() {            
            if(!$Rot.stopanimation) $Rot.setImage($Rot.next,'next');                        
        });                
    }
    this.init();
}
$(document).ready(function() {       
    var rotator = ($('#rotator').length > 0) ? new Rotator($('#rotator')) : {};
});
//-->

