var current_slide_pos = 1;
$().ready(function() {
	
	/*Author: Paulo Oreda
	 * This method manage the style of the videos container
	 * on a mouse over the play button of each video.
	 */
	$('.playBtn').mouseover(function(){
		$(this).parent().parent().addClass('mOver');
	}).mouseout(function(){$(this).parent().parent().removeClass('mOver')});
	
		
	$('#video_tabs .tab_container').each(function(){
		$(this)
			.bind('mouseover', function(){$(this).find('.tab_content').slideDown();})
			.bind('mouseleave', function(){$(this).find('.tab_content').slideUp();})
			.bind('click', function(){
				$('#video_tabs').find('.tab_button').removeClass('active');
				$(this).find('.tab_button').addClass('active');
				getPlayer($(this).attr('type'));
			});
	});

	$(".testimonial").each(function(){
		var url = '/testimonial/getvideo/'+$(this).find('.video_url_code').val();
		$(this).find('.video').colorbox({href: url, innerWidth: '657px', innerHeight: '390px',iframe:true});
	});
	
	var scrollable = $('.testimonials .scrollable').scrollable({'circular':true});
	
	var timer = setInterval(function(){
		scrollable.scrollable().next();
	}, 5000);

        var scrollable_top = $("#browsable").scrollable({
            'circular':true,
            'items'   : '.items2',
            onSeek: function() {
                var index = this.getIndex();
                var selector = '#lnk_index_'+index;
                $(selector).removeClass('_inactive_index_slide_'+index).addClass('index_slide_'+index);
                var pos = 0;
                $('div.slider_nav a').each(function(){
                    if (pos!=index) {
                        $(this).removeClass('index_slide_'+pos).addClass('_inactive_index_slide_'+pos);
                    }
                    pos++;
                });
                current_slide_pos++;
            }
        });

	var timer_top = setInterval(function(){
                if (current_slide_pos == 3) {
                    current_slide_pos = 0;
                }
                scrollable_top.scrollable().seekTo(current_slide_pos);
	}, 15000);
                
        $('div.slider_nav a').each(function(){
             $(this).click(function(){
                scrollable_top.scrollable().seekTo($(this).attr('rel'));
                window.clearInterval(timer_top);
             });
        });

        $('.playerContainer').click(function(){
            $('.player > div').show();
        });

});

function getPlayer(path) {
	$.post("/videos/landingVideos", {vidPath: path}, function (data) {
		$('div.player').html('<div id="player_container">' + data + '</div>');
    });
}
