$(document).ready(function() {


    var cache = new Array();
    var isOpera = window.opera ? true : false;

   
    /*
     * MAIN MENU INITIALIZATON */

    $('#main-menu').pixelMenu({
        moreText: '',
        animationSpeed: 400
    });
    
    /*
     * ROUND CORNERS */
    
    $('.message-box .box-content').corner("bottom round 8px");
    $('.simple-message-box').corner('round 8px');
    $('blockquote').corner('round 8px');
    $('ul.page-navbar li a').corner('round 2px');


    /*
     * WIDGET MENU */

    $('.widget ul.widget-menu li a').hover(
        function() {
            $(this).stop().animate({
                textIndent: '10px'
            })
        },
        function() {
            $(this).stop().animate({
                textIndent: '0px'
            })
        }
        );


    /*
     * FRONTPAGE SLIDER */

    frontpageTransitionSliderInit();
     

    /*
     * TEXT MESSAGE BOX */
    $('.message-box .title a').click(function(e) {
        e.preventDefault();
        $(this).parent().parent().find('.box-content').slideToggle(500);
    });


    /*
     * Search bar initialization
     */

    $('#search').focusin(function() {
        if ( $(this).val() == '' ) {
            $(this).val('');
        }
    });
    $('#search').focusout(function() {
        if ( $(this).val().trim() == '' ) {
            $(this).val('Search Content');
        }
    });

    /*
     * CONTACT FORM */

    $('#send-email-button').click(function(e) {
        e.preventDefault();
        $.post('email.html', {
            name: $('#contact-name').val(),
            email: $('#contact-email').val(),
            subject: $('#contact-subject').val(),
            message: $('#contact-message').val()
        }, function(data) {
            var response = '<div class="alert-box warning-box"><span>'+ data +'</span></div>';
            $('#email-form div.warning-box').remove();
            $('#email-form').prepend(response);
            $('#email-form div.warning-box').hide().fadeIn(500);
        })
        return false;
    });


    function preloadImages() {
        var img;
        var arg = arguments.length;
        for ( i = 0; i < arg ; i++ ) {
            img = document.createElement('img');
            img.src = arguments[i];
            cache.push(img);
        }
    }

});


String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};



/*
 * FRONTPAGE SLIDER */

function frontpageTransitionSliderInit() {

    var DELAY = 30;

    if ( window.SLIDER_TYPE == undefined ) {
        SLIDER_TYPE = 1;
    }

    if ( SLIDER_TYPE === 4 ) {
        DELAY = 80;
    }

    $("#frontpage-slider").transitionSlider({
        slideWidth: 940,
        slideHeight: 350,
        selSlide: 0,
        delay: DELAY,
        animationStyle : SLIDER_TYPE,
        animationSpeed: 500,
        autoScrollTimer: 10,
        pieceV: 1,
        pieceH: 28,
        hasNavBar: true,
        navbarId: 'slider-navbar'
    });

    /*
     * centering the navbar */
    
    var navbarW = $('#slider-navbar').width();
    var slides = $('#slider-navbar li').length;
    var padding = navbarW/2 - (slides * 16)/2;

    $('#slider-navbar').css('paddingLeft', Math.floor(padding));
}

