var rot_foto = 0;
var rot_foto_act = 0;
var rot_foto_len = 0;
var slider_news = 0;
var slider_news_s = 0;
var slider_news_t = "down";
jQuery(document).ready(function(){
	jQuery('#TOP .info a:eq(0)').click(function(){
		this.style.behavior = 'url(#default#homepage)'; 
		this.setHomePage(window.location.href);     	
		return false;
	});
	jQuery('#TOP .info a:eq(2)').click(function(){
		if(window.sidebar){
    	   window.sidebar.addPanel(page_title, page_url, "");
    	   return false;
  		}else if(window.external){
    	   window.external.AddFavorite(page_url, page_title);
    	   return false;
  		}
	});
   jQuery('#TOP .shoutbox input, .panel_vip input, .guestpanel form input').focus(function(){
   	if(jQuery(this).val() == this.defaultValue){
   		jQuery(this).val('');
   	}
   });
   jQuery('#TOP .news .arrow-up').mouseover(function(){
   	clearInterval(slider_news);
   	slider_news = setInterval('slider_scroll("up", false)', 20);
   	slider_news_t = "up";
   });
   jQuery('#TOP .news .arrow-down').mouseover(function(){
   	clearInterval(slider_news);
   	slider_news = setInterval('slider_scroll("down", false)', 20);
   	slider_news_t = "down";
   });
   jQuery('#TOP .news .arrow-up, #TOP .news .arrow-down').mouseout(function(){
   	clearInterval(slider_news);
   	slider_auto();
   });
	active_foto_rotator();
	slider_auto();
	jQuery('.panel_projects .content_tab, .panel_actors .content_tab, .panel_hsm .content_tab').nextAll('.content_tab').css({display: 'none', opacity: 0});
	jQuery('.panel_projects .tabs ul li, .panel_actors .tabs ul li, .panel_hsm .tabs ul li').click(function(){
		var new_eq = jQuery(this).prevAll().length;
		var old_eq = jQuery(this).parent().find('.act').prevAll().length;
		if(new_eq != old_eq){
			var this_el = jQuery(this).parents('.mainpanel-c');
			jQuery(this_el).find('.content_tab').eq(old_eq).animate({opacity: 0}, 500, function(){
				jQuery(this_el).find('.content_tab').css({display: 'none', opacity: 0});
				jQuery(this_el).find('.tabs ul li').removeClass('act');
				jQuery(this_el).find('.tabs ul li').eq(new_eq).addClass('act');
				jQuery(this_el).find('.content_tab').eq(new_eq).css('display', 'block').animate({opacity: 1}, 500);
			});
		}
	});
	if(jQuery.browser.msie && jQuery.browser.version.substr(0,1) < 7){
		jQuery('.mainpanel .mainpanel-t h2').each(function(){
			var old_marg = jQuery(this).css('margin-left').replace('px', '');
			jQuery(this).css('margin-left', (old_marg > 0 ? old_marg / 2 : 0) + 'px');
		});
	}
});

function active_foto_rotator(){
	rot_foto_len = jQuery('#TOP .rotator ul li').size();
	if(rot_foto_len > 1){
		jQuery('#TOP .rotator ul li').css('opacity', 0);
		jQuery('#TOP .rotator ul li:first-child').css({'z-index': 10, 'opacity': 1});
		rot_foto = setInterval("next_foto_rotator()", 5000);
	}
};

function next_foto_rotator(){
	var id = (rot_foto_act < rot_foto_len-1 ? rot_foto_act+1 : 0);
	if(id != rot_foto_act){
		clearInterval(rot_foto);
		jQuery('#TOP .rotator ul li:eq(' + rot_foto_act + ')').css({'z-index': 1}).animate({'opacity': 0}, 300, function(){
			jQuery(this).css('display', 'none');
			jQuery('#TOP .rotator ul li:eq(' + id + ')').css({'display': 'block', 'z-index': 10}).animate({'opacity': 1}, 300);
			rot_foto_act = id;	
			rot_foto = setInterval("next_foto_rotator()", 5000);
		});
	}
};

function slider_auto(){
	if(jQuery('#TOP .news .slide').height() > jQuery('#TOP .news .news-slider').height()){
		clearInterval(slider_news);
		slider_news = setInterval('slider_scroll("' + slider_news_t + '", true)', 100);
	}
};

function slider_scroll(type, auto){
	var news_top = jQuery('#TOP .news .news-slider').scrollTop();
	var slide_here = true;
	if(auto == true){
		if(type == "up" && news_top == 0 && slider_news_s <= 0){
			slider_news_t = "down";
			slider_auto();
			slide_here = false;
			
		}else if(type == "down" && news_top < slider_news_s){
			slider_news_t = "up";
			slider_auto();
			slide_here = false;
		}
	}
	if(slide_here == true){
		jQuery('#TOP .news .news-slider').scrollTop((type == "up" ? news_top-2 : news_top+2)); 
		slider_news_s = (type == "up" ? news_top-2 : news_top+2);
	}
};
