/**
 * Common script to be executed after any website page is loaded
 */

$(document).ready(function() {
    $('#slideshow-pics').cycle({
        random: 1,
        timeout: 6000
    });

    $('#testimonials-slideshow.dynamic').cycle({
        random: 1,
        timeout:10000
    });
    $('#testimonials-slideshow.static').cycle({
        autostop: true,
        autostopCount: 1,
        random: 1
    });
    
    $('.expandable-title a').click(function(event) {
        event.preventDefault();
        
        $(this).addClass('current');
        
        // Hide all accordions
        $('.expandable-content').each(function () {
            $(this).slideUp();
        });
        $('.expandable-title .arrow').attr('src', $('#arrow-off').attr('src'));
        $('.expandable-title a').each(function() {
            if(!$(this).hasClass('current')) {
                $(this).removeClass('opened');
            }
        });

        // Toggle this accordion
        if($(this).hasClass('opened')) {
            $(this).parent().parent().find('.expandable-content').slideUp();
            $(this).removeClass('opened');
            $(this).find('.arrow').attr('src', $('#arrow-off').attr('src'));
        } else {
            $(this).parent().parent().find('.expandable-content').slideDown();
            $(this).addClass('opened');
            $(this).find('.arrow').attr('src', $('#arrow-on').attr('src'));
        }

        $(this).removeClass('current');
    });

    $('#frmContact').validate({
	    submitHandler: function(form) {
            $(form).ajaxSubmit({
                type:       'POST',
                dataType:   'json',
                success: function(data) {
                    switch (data.status) {
                        case 'success': 
                            $('#message').html('<p style="color:green">Thank you! We will contact you as soon as possible.</p>');
                            $('#frmContact').each (function(){
                                this.reset();
                            });
                            break;
                        default: 
                            $('#message').html('<p style="color:red">Oops! We are sorry but there was a problem while sending your request. Please try again.</p>');
                            break;
                    }
                }
            
            }); 

            return false;
        }
	});

});

