jQuery(function($) {
	$('.blink').focus(function() {
        if(this.title==this.value) {
            this.value = '';
        }
    }).blur(function(){
        if(this.value=='') {
            this.value = this.title;
        }
    });
    
    $('#main-slider .slider').jcarousel({
    	scroll : 1,
    	//auto : 5,
    	wrap : 'both'
    });

    $('#footer .nav ul li span:last').remove();

    $('.tabs-container .tabs a').click(function() {
        var cnt = $(this).parents('.tabs-container:eq(0)');
        var idx = cnt.find('.tabs a').index($(this));
        cnt.find('.single-tab').hide();
        cnt.find('.single-tab:eq(' + idx + ')').show();
        cnt.find('.tabs a.active').removeClass('active');
        $(this).addClass('active');
        return false; 
    });

    var interval;

    function video_player_slide() {
        var current = $('#video-player .slide').index($('#video-player .slide:visible'));
        var total = $('#video-player .slide').length;
        if (current == total - 1) {
            current = 0;
        } else {
            current++;
        }
        $('#video-player .thumbs li:eq(' + current + ') a:eq(0)').trigger('click');
    }

    if ($('#video-player').length) {
        interval = setInterval(video_player_slide, 8000);
    }

    var timeout;
    $('#video-player .thumbs a').click(function() {
        if ($('#video-player .big .slide:animated').length) {
            return false;
        }
        var idx = $('#video-player .thumbs a').index($(this));
        var next = $('#video-player .big .slide:eq(' + idx + ')');
        if (next.is(':visible')) {
            return false;
        }

        clearInterval(interval);
        interval = setInterval(video_player_slide, 8000);

        $('#video-player .big .slide:visible').fadeOut();
        next.find('.text').show();
        next.fadeIn();

        clearTimeout(timeout);
        timeout = setTimeout(function() {
            next.find('.text').fadeOut();
        }, 5000);
        return false; 
    });
    
    $('#video-player .thumbs a:eq(0)').trigger('click');

    $('#main-nav > ul').each(function() {
       var items = $(this).children('li');
       var pad = ( $('#main-nav').width() - $(this).width() ) / items.length / 2;
       items.each(function() {
          $(this).find('a:eq(0)').css({
              'padding-left': pad,
              'padding-right': pad
          });
       });
    });

});
