﻿var interval;
$(document).ready(function(){
interval = setTimeout('updateMedia(k,true)', 6000);
$('.media_tab').click(function(){
if (!$(this).find('.media_tab_pusher').is(':visible') && !locked) {
clearTime();
updateMedia(parseInt($('.media_tab').index($(this))),false);
}
});				   
});

function updateMedia(index,auto) {
k = index;
locked = true;
tabs_count = $('.media_tab').length;
if (k > (tabs_count - 1)) k = 0;
if (auto) {
interval = setTimeout('updateMedia(k,true)', 6000);
} else {
interval = setTimeout('updateMedia(k,true)', 14000);	
}

var media_div = $('.media_tab_pusher:visible').parent().parent().parent().parent();
var current_div = $('.media_tab').eq(k);

media_div.find('.media_tab_bottom').css({'backgroundImage' : media_div.find('.media_tab_bottom').css('backgroundImage').replace('active','normal')});
media_div.find('.media_tab_left').css({'backgroundImage' : media_div.find('.media_tab_left').css('backgroundImage').replace('active','normal')});
media_div.find('.media_tab_right').css({'backgroundImage' : media_div.find('.media_tab_right').css('backgroundImage').replace('active','normal')});
media_div.css({'color' : '#bfbfbf'});
current_div.find('.media_tab_bottom').css({'backgroundImage' : current_div.find('.media_tab_bottom').css('backgroundImage').replace('normal','active')});
current_div.find('.media_tab_left').css({'backgroundImage' : current_div.find('.media_tab_left').css('backgroundImage').replace('normal','active')});
current_div.find('.media_tab_right').css({'backgroundImage' : current_div.find('.media_tab_right').css('backgroundImage').replace('normal','active')});
current_div.css({'color' : '#fff'});

$('.media_tab_pusher:visible').slideUp(300);
$('#media_picture_div a:visible').fadeOut(900,function(){locked = false;});
current_div.find('.media_tab_pusher').slideDown(500);
$('#media_picture_div a').eq(k).fadeIn(800);
$('.media_tab').css({'cursor' : 'pointer !important'});
current_div.css({'cursor' : 'default !important'});
k++;
}

function clearTime() {
clearTimeout(interval);	
}
