$(document).ready(function(){

    $('.image-rotate-a').cycle({
        fx: 'fade',
        speed: 10000,
        timeout: 5000,
        random: 1
    });
    $('.image-rotate-b').cycle({
        fx: 'fade',
        speed: 10000,
        timeout: 5000,
        delay: 5000,
        random: 1
    });
    
    
    $('.fadeThis').append('<span class="hover"></span>').each(function(){
        var $span = $('> span.hover', this).css('opacity', 0);
        $(this).hover(function(){
            $span.stop().fadeTo(400, 1);
        }, function(){
            $span.stop().fadeTo(400, 0);
        });
    });
    
    $('input.btn-go').click(function(){
        var select_value = $('select.month-value option:selected').val();
        
        if (select_value === '-1') {
            $('div.news-item-a').show();
        }
        else {
            $('div.news-item-a:not(.' + select_value + ')').hide();
            $('div.news-item-a.' + select_value + '').show();
        }
    });
    
    
    var continueAnimation = true;
    
    var animationCounter = 0;
    
    $('.item-revealer .item').each(function(i, n){
    
        $(n).bind('click', {
            element: n
        }, revealer);
        
    });
    
    function revealer(event){
    
        var n = event.data.element;
        
        if ($(n).hasClass('open')) {
        }
        else {
            continueAnimation = false;
            $('.item-revealer .item .body').fadeOut('fast');
            $('.item-revealer .item').animate({
                'width': '84.5px'
            }, 500).removeClass('open');
            $(n).stop().animate({
                'width': '430px'
            }, 500, function(){
                $(n).find('.body').fadeIn('slow');
            }).addClass('open');
        }
        
    }
    
    function revealerAnimation(){
    
        if (continueAnimation === true) {
        
            if (animationCounter < 5) {
            
                $('.item-revealer .item .body').fadeOut('fast');
                $('.item-revealer .item').animate({
                    'width': '84.5px'
                }, 500).removeClass('open');
                $('.item-revealer .item:eq(' + animationCounter + ')').stop().animate({
                    'width': '430px'
                }, 500, function(){
                    $('.item-revealer .item:eq(' + animationCounter + ')').find('.body').fadeIn('slow');
                    animationCounter++;
                    var t = setTimeout(revealerAnimation, 6000);
                }).addClass('open');
                
                
            }
            else {
            
                $('.item-revealer .item .body').fadeOut('fast');
                $('.item-revealer .item').animate({
                    'width': '84.5px'
                }, 500).removeClass('open');
                $('.item-revealer .item:first').stop().animate({
                    'width': '430px'
                }, 500, function(){
                    $('.item-revealer .item:first').find('.body').fadeIn('slow');
                    animationCounter = 1;
                    var t = setTimeout(revealerAnimation, 6000);
                }).addClass('open');
                
            }
            
        }
        
    }
    
    var t = setTimeout(revealerAnimation, 6000);
    
    $('.faq-container ul li').each(function(i, n){
        $(n).find('a').click(function(){
            if ($(n).hasClass('selected')) {
                $('li.selected div').slideUp('fast', function(){
                    $('li.selected div').removeClass('openItem');
                    $('li.selected').removeClass('selected');
                });
            }
            else {
                $('li.selected div').slideUp('fast', function(){
                    $('li.selected div').removeClass('openItem');
                    $('li.selected').removeClass('selected');
                });
                $(n).find('div').slideDown('fast', function(){
                    $(n).find('div').removeClass('hide').addClass('openItem');
                    $(n).addClass('selected');
                });
            }
			return false;
        });
    });
    
});

// FAQ list.

var lastSel = "";
// Number of FAQ questions //
var numFaqs = 25;
// Expands out the selected FAQ item, and hides the others. //
function expand(sel){
    // If the item is clicked on again, clear the selection to hide it. //
    if (sel == lastSel) {
        sel = "";
    }
    // For each id name in the FAQs list... //
    for (var i = 1; i <= numFaqs; i++) {
        var id = i;
        var li = document.getElementById("li" + id);
        var div = document.getElementById("div" + id);
        if (!id) 
            continue;
        // Change the class of the li and div elements to display or hide each: //
        if (id == sel) {
            li.className = "selected";
            div.className = "openItem";
        }
        else {
            li.className = "";
            div.className = "hide";
        }
    }
    // Return false to prevent browser from trying to follow links. //
    lastSel = sel;
    return false;
}

// Fix for Internet Explorer DOM incompatibility: //
if ((!document.getElementById) && (document.all)) {
    document.getElementId = function(id){
        return document.all[id];
    }
}

