var tab_act = 0;
var tab_max = 0;
var kolor0 = 'transparent';
var kolor1 = '#adfdfd';
var kolor2 = '#DDF5FF';
var zoomer = null;
var zazn = Array();

$(function(){
	/**********************************************************
			Init
	**********************************************************/
	$('.tabbed>.tabs:first').css('margin-left','12px');
	
	$('.tabbed>.tabs').each(function(idx){
		var szerokosc = parseInt($('.napis',this).width());
		/*if(szerokosc < 45){
			$('.napis',this).css('text-align','center');
			if(szerokosc < 29){
				$('.napis',this).css('width', (szerokosc*0.7)+'px');
			}
			szerokosc += 45-szerokosc; 
		}
		else{
			szerokosc += 4;
		}*/
		$('.napis',this).css('width',szerokosc+16);
		$(this).css('width',szerokosc+26);
	});

	tab_act = 1;
	tab_max = Math.floor(parseInt($('#przesuniecie').css('width').replace('px',''))/677);
	$('#tabs_'+tab_act).css('background-color', kolor2);
	$('#tabbed>div[id^=tabs_]').each(function(){
		var szerokosc = parseInt($(this).css('width').replace('px','')) + 10;
		$(this).css('width', szerokosc+'px');
	});
	
	/**********************************************************
			Zakładki
	**********************************************************/
	$('div.tabs').mouseover(function(){ //Po najechaniu myszka
		$(this).css('background-color', kolor2);
	});
	$('div.tabs').mouseout(function(){ //Po wyjechaniu myszki
		var id = parseInt(this.id.split('_')[1]);
		if(tab_act!=id) $(this).css('background-color', 'transparent');
		else 			$(this).css('background-color', kolor2);
	});
	$('div.tabs').click(function(){ //Po kliknieciu
		var id = parseInt(this.id.split('_')[1]);
		$(this).css('background-color', kolor2);
		if(tab_act!=id) $('#tabs_'+tab_act).css('background-color', kolor0);
		tab_act=id;
		$(".przesuniecie").animate({ left: (-677*(tab_act-1))+"px"},500);
	});
	/**********************************************************
			Guziki 'poprzednia zakładka', 'następna zakładka'
	**********************************************************/
	$('div.next').click(function(){
		$('#tabs_'+tab_act).css('background-color', kolor0);
		if(tab_act==tab_max) tab_act = 1;
		else tab_act++;
		$('#tabs_'+tab_act).css('background-color', kolor2);
		$(".przesuniecie").animate({ left: (-677*(tab_act-1))+"px"},500);
	});
	$('div.prew').click(function(){
		$('#tabs_'+tab_act).css('background-color', kolor0);
		if(tab_act==1) tab_act = tab_max;
		else tab_act--;
		$('#tabs_'+tab_act).css('background-color', kolor2);
		$(".przesuniecie").animate({ left: (-677*(tab_act-1))+"px"},500);
	});
	/**********************************************************
			Kliknięcie na emotke (teoretycznie nie nastąpi)
	**********************************************************/
	$('div.przesuniecie > div.tab > div.tab_emots > img').click(function(){
		var word = $(this).attr('alt');
		slango_emot(word);
	});
	/**********************************************************
			Podświetlanie aktualnej emotki na liście
	**********************************************************/
	$('div.przesuniecie > div.tab > div').hover(function() {
		return; //temporary diabled
		var src = $('img',this).attr('src');
		var poz = $(this).offset();
		zazn.nazwa = $('img',this).attr('alt');
		
		if(zazn.disp == 1) {
			$('.emot_selector').remove();
			zazn.disp = 0;
		}
		var nowy = $('<div/>');
		var nowy_img = $('<img/>');
		var nowy_br  = $('<br/>');
		
		zazn.left = (poz.left - 30);
		zazn.top  = (poz.top - 30);
		
		nowy.attr('class','emot_selector');
		nowy.css('left', zazn.left+'px');
		nowy.css('top',  zazn.top+'px');
		nowy_img.attr('class', 'emot_selector_img');
		nowy_img.attr('src', src);
		/*****************************************
				Myszka ucieka z kółka
		*****************************************/
		nowy.mouseleave(function(){
				$('.emot_selector').remove();
				zazn.disp = 0;
		});
		/*****************************************
				Myszka rusza się w kółku
		*****************************************/
		nowy.mousemove(function(e){
			var r = 46;
			var a = (zazn.left+r)-e.pageX;
			var b = (zazn.top+r)-e.pageY;
			var c = a*a+b*b;
			var l = Math.floor(Math.sqrt(c));
			
			if(l>40){
				$('.emot_selector').remove();
				zazn.disp = 0;
			}

		});
		/*****************************************
				Kliknięcie na emotke
		*****************************************/
		nowy.click(function(){
			slango_emot(zazn.nazwa);
		});
		/*****************************************
				Dodanie obiektów
		*****************************************/
		nowy.append(nowy_img);
		nowy.append(nowy_br);
		nowy.append(zazn.nazwa);

		$("#body").append(nowy);
		zazn.disp = 1;
	});
	/**********************************************************
			Koniec
	**********************************************************/
});