﻿var umenu;
var rot;
var rot_act = 0;
jQuery(document).ready(function(){
	jQuery('.T-menu ul li').mouseover(function(){
		jQuery('.T-menu ul li a').removeClass('mactive');
		jQuery('.T-smenu ul').css('display', 'none');
		jQuery(this).find('a').addClass('mactive');
		jQuery('#T-smenu-l' + (jQuery(this).prevAll().length+1)).css('display', 'block');
	});
	jQuery('.T-menu, .T-smenu').hover(function(){
		clearTimeout(umenu);
	},function(){
		umenu = setTimeout(hide_umenu, 1000);
	});
	active_rotator();
	jQuery('.T-panel1 ul li').click(function(){
		change_rotator(jQuery(this).find('a').attr('title')-1);
	});
	jQuery('.T-panel1-nav a').click(function(){
		var rot_len = jQuery('.T-panel1-img a').size();
		if(jQuery(this).prevAll().length == 0){
			change_rotator((rot_act > 0 ? rot_act-1 : rot_len-1));
		}else{
			next_rotator();
		}	
	});
	start_user_panel();
	jQuery('.T-open-panel').click(function(){
		jQuery('.T-open-panel').animate({opacity: 0}, 100, function(){
			jQuery('.T-panel-usera').slideToggle('normal');      
		});
		jQuery.cookie('user_panel', 'on', {expires: 365});
	});
	jQuery('.T-panel-usera .hide-panel').click(function(){
		jQuery('.T-panel-usera').slideToggle('normal', function(){ 
			jQuery('.T-open-panel').animate({opacity: 1}, 100);
		});
		jQuery.cookie('user_panel', null, {expires: 365});
	});
});

function hide_umenu(){	
	jQuery('.T-menu ul li a').removeClass('mactive');
	jQuery('.T-smenu ul').css('display', 'none');
};

function active_rotator(){
	var rot_len = jQuery('.T-panel1-img a').size();
	var rot_li = "";
	if(rot_len > 1){
		jQuery('.T-panel1-img a').css('opacity', 0);
		jQuery('.T-panel1-img a:first-child').css({'z-index': 10, 'opacity': 1});
		for(var a = 2; a <= rot_len; a++){
			rot_li += "<li><a href='javascript: void(0)' title='" + a + "'>" + a + "</a></li>";
		}
		jQuery('.T-panel1-nav, .T-panel1 ul').css('display', 'block');
		jQuery('.T-panel1 ul').append(rot_li);
		rot = setInterval("next_rotator()", 5000);
	}
};

function change_rotator(id){
	if(id != rot_act){
		clearInterval(rot);
		jQuery('.T-panel1-img a:eq(' + rot_act + ')').animate({opacity: 0}, 300, function(){
			jQuery('.T-panel1 ul li a:eq(' + rot_act + ')').removeClass('act');
			jQuery('.T-panel1 ul li a:eq(' + id + ')').addClass('act');
			jQuery('.T-panel1-img a:eq(' + id + ')').animate({'opacity': 1}, 300);
			rot_act = id;	
			rot = setInterval("next_rotator()", 5000);
		});
	}
};

function next_rotator(){
	var rot_len = jQuery('.T-panel1-img a').size();
	change_rotator((rot_act < rot_len-1 ? rot_act+1 : 0));
};

function start_user_panel(){
	var p_cookie = jQuery.cookie('user_panel');
   if(p_cookie != null){
   	jQuery('.T-open-panel').animate({opacity: 0}, 100, function(){
   		jQuery('.T-panel-usera').slideToggle('normal');
   	});
   }else{
   	return false;
   }
};