<!--

var id = 'search_field';
var text = 'wpisz czego szukasz...';
var id_letters1 = 'litery-normal';
var id_letters2 = 'litery-cyrylica';
var id_searchform = 'searchField'; 
var id_header = 'searchHeader';   

var lang='en';
var rev=0;

var newPage = true;

function addBookmark(title,url) {
	if (window.sidebar) {
  		window.sidebar.addPanel(title, url,"");
 	} else if( document.all ) {
 		window.external.AddFavorite( url, title);
 	} else if( window.opera && window.print ) {
 		return true;
	}
}

function addLetter(letter){
	erase();
  	var textField = document.getElementById(id);
  	var textValue = textField.value;
  	var textLen = textValue.length;
  	//caret position
  	var caretPos = -1;
  	if(document.selection) {
  		//IE suport
  		textField.focus();
		var Sel = document.selection.createRange();
		Sel.moveStart ('character', -textField.value.length);
		caretPos = Sel.text.length;
  	} else if(textField.selectionStart || textField.selectionStart == '0') {
		caretPos = textField.selectionStart;
  	}
  	//new string
  	if(caretPos >= 0) {
  		var textValuePrefix = textValue.substring(0, caretPos);
  		var textValueSufix = textValue.substring(caretPos, textLen);
  		textField.value = textValuePrefix + letter + textValueSufix;
  		//focus position
	  	if (textField.setSelectionRange) {
			textField.focus();
			textField.setSelectionRange((caretPos + 1), (caretPos + 1));
		}
		else if (textField.createTextRange) {
			var range = textField.createTextRange();
			range.collapse(true);
			range.moveEnd('character', (caretPos + 1));
			range.moveStart('character', (caretPos + 1));
			range.select();
		}
  	} else {
  		textField.value = textValue + letter;
  		textField.focus();
  	}
}

function erase(mode) {
	if(mode == 3 && newPage == true && document.getElementById(id).value == text) {
		document.getElementById(id).value = '';
	}
	else if (document.getElementById(id).value == text) {
		document.getElementById(id).value = ''; 
	}
	
	newPage = false;
}

function polskie(lit_name, resize) {
	if($('#litery-pl').css('display') == 'none') {
		$('#'+lit_name).hide();
		$('#litery-pl').show();
		
		if(resize == true) {
			$('#searchHeader').removeClass('ruExt').removeClass('uaExt');
			$('#searchField').removeClass('ruExt').removeClass('uaExt');
		}
	}
	else {
		$('#litery-pl').hide();
		$('#'+lit_name).show();
		
		if(resize == true) {
			$('#searchHeader').addClass('ruExt').addClass('uaExt');
			$('#searchField').addClass('ruExt').addClass('uaExt');
		}
	}
}

function cyrylica(){

    if (document.getElementById(id_letters2).style.display == 'none')
    {
        document.getElementById(id_letters1).style.display = 'none';
        document.getElementById(id_letters2).style.display = 'block';
         document.getElementById(id_searchform).style.marginTop = '3px';
           document.getElementById(id_header).style.marginTop = '15px';            
    } else 
    {
      document.getElementById(id_letters2).style.display = 'none';
        document.getElementById(id_letters1).style.display = 'block';   
        document.getElementById(id_searchform).style.marginTop = '7px';
        document.getElementById(id_header).style.marginTop = '20px';   
    }
}


function getTranslation(word){
            $('#example-hint').html('');  
           // language= 'en'; // jest ustawione globalnie w naglowku strony
           $.get('/slownik.php?ajaxSearch='+word+'&lang='+language, function(data){
               if (data != ''){
                    $('#example-hint').html(data);
                    $('#example-hint').show();  
               }
           });

}

function showHint(text) {
	if(text != '' && text != 'undefined') {
		$('#example-hint').html('Zaproponuj przykład zdania zawierającego "'+text+'".');
		$('#example-hint').show();
	}
}

function baloon(elem, text) {
	    $(elem).mouseover(function(e){
			to = setTimeout('showBaloon(\''+text+'\')', 100); 
			$('#example-hint').css('left',e.pageX+'px');
			$('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
		}).mousemove(function(e){
			$('#example-hint').css('left',e.pageX+'px');
			$('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
		}).mouseout(function(e) {
			$('#example-hint').hide();
			clearTimeout(to);
		});
}

function showBaloon(text) {
	if(text != '' && text != 'undefined') {
		$('#example-hint').html(text);
		$('#example-hint').show();
	}
}

function showExplainBaloon(text) {
	if(text != '' && text != 'undefined') {
		$('#explain-hint').html(text);
		$('#explain-hint').show();
	}
}

function translateExamples(){
    //translate = $.get('slownik.php?ajaxSearch='+word+'&lang='+language);
   /* $('.example').each(function (i){
       words = $(this).html().split(" ");
       ret = '';
       for (i=0; i<words.length;i++){
          ret = ret + '<a href="javascript:void(0)">'+words[i]+'</a> ';
       }
       $(this).html(ret);
    });*/
    var to1;
	var to2;
	var to3;
	
    $('.example > a').not('.addExTrans').hover(function(){
       to1 = setTimeout('getTranslation(\''+escape($(this).html())+'\')',200); 
    }, function (){
       $('#example-hint').hide();
       clearTimeout(to1);
    });
}

function setSize(s) {
	// jQuery
	
	// zmiana rozmiaru czcionki
	$('#word2, #static').css('font-size', s+'px').css('line-height', Math.round(Number(s)*1.27)+'px');
	
	
	$('#size11').removeClass('selected');
	$('#size13').removeClass('selected');
	$('#size15').removeClass('selected');
	
	$('#size'+s).addClass('selected');
	
	// zapisanie ajaxem czcionki w sesji
	$.get('/saveSize.php', { size: s });
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function openVideoNauka( urlParameters ) {
    window.open('http://videonauka.pl/'+urlParameters, '_blank');
}

// jQuery main code
$(document).ready(function(){

    // for /videonauka advertisment page
    $('#videonauka-logo').click( function() { openVideoNauka(''); } ); 
    $('#videonauka-movie-chooser').click( function() { openVideoNauka(''); } );
    $('#videonauka-card-notes').click( function() { openVideoNauka(''); } );
    $('#videonauka-kompletne-kursy').click( function() { openVideoNauka(''); } );
    $('#videonauka-webpages').click( function() { openVideoNauka(''); } );
    $('#videonauka-100-movies').click( function() { openVideoNauka(''); } );
    $('#videonauka-gwarancja-zdanej-matury').click( function() { openVideoNauka('regulamin.html#punkt8'); } );
    
	// wykrywanie rozdzielczosci
	createCookie('testCookie','on',1);
	if(readCookie('testCookie') == 'on') {
		eraseCookie('testCookie');
		if(!issetRes) location.replace((screen.width >= 1280)?'/slownik.php?session=powieksz&auto=1':'/slownik.php?session=pomniejsz&auto=1'); 
	}

	// ustaw czcionke
	if(fontsize != 11) setSize(fontsize);
	
	// reklama
	/*$('#form').submit(function() {
		if($('#search_field').val() == text) {
			window.open('http://www.nauka.pl/link.php?d=6488bc2c6afee3b11bd9c77dba168208');
			return false;
		}
	});*/
	
	// ustaw focus na wyszukiwarke
	$('#'+id).focus();
	
	// faq - klikanie w pytania
	$('dl#faq > dt').click(function(){
		var opis = $(this).next('dd');
		
		if($(opis).css('display') == 'none')
			$(opis).show();
		else
			$(opis).hide();
	
	});
	
    translateExamples();
	
	$('#show_author').click(function(){
		if($(this).attr('checked') == true)
			$('#show_author_name').show();
		else
			$('#show_author_name').hide();
	});
	
    $('.addExTrans').mouseover(function(e){
		to2 = setTimeout('showHintTrans(\''+$(this).attr('alt')+'\')', 100); 
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
    }).mousemove(function(e){
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
	}).mouseout(function(e) {
       $('#example-hint').hide();
       clearTimeout(to2);
	});
	
    $('.example > span.addExample > a').hover(function(){
       to2 = setTimeout('showHint(\''+$(this).attr('alt')+'\')', 100); 
    }, function (){
       $('#example-hint').hide();
       clearTimeout(to2);
    });
	
    $('#addWord, .addWord').mouseover(function(e){
	to2 = setTimeout('showHintWord(\''+$(this).attr('alt')+'\')', 100); 
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
    }).mousemove(function(e){
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
	}).mouseout(function(e) {
       $('#example-hint').hide();
       clearTimeout(to2);
	});
    
    $('.example a').not('.addExTrans').not('.addWord').mouseover(function(e){
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
    }).mousemove(function(e){
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
	});
	
	$('div#list ul a').mouseover(function(e) {
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
	   to3 = setTimeout('showBaloon(\''+$(this).attr('alt')+'\')',50); 
	}).mousemove(function(e){
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
	}).mouseout(function(e) {
       $('#example-hint').hide();
       clearTimeout(to3);
	});
	
	$('div.slowo > h2').mouseover(function(e) {
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
	   to3 = setTimeout('showBaloon(\''+$(this).attr('alt')+'\')',50); 
	}).mousemove(function(e){
       $('#example-hint').css('left',e.pageX+'px');
       $('#example-hint').css('top',(e.pageY-$('#example-hint').height()-15)+'px');
	}).mouseout(function(e) {
       $('#example-hint').hide();
       clearTimeout(to3);
	});
	
	$('.objasnienie').mouseover(function(e) {
       $('#explain-hint').css('left',(e.pageX+10)+'px');
       $('#explain-hint').css('top',(e.pageY-$('#explain-hint').height()+60)+'px');
	   to3 = setTimeout('showExplainBaloon(\''+$(this).attr('alt')+'\')',50); 
	}).mousemove(function(e){
       $('#explain-hint').css('left',(e.pageX+10)+'px');
       $('#explain-hint').css('top',(e.pageY-$('#explain-hint').height()+60)+'px');
	}).mouseout(function(e) {
       $('#explain-hint').hide();
       clearTimeout(to3);
	});
	
	
	
	// dymki
	baloon($('#questSyn'), 'Synonim to wyraz lub określenie równoważne znaczeniowo innemu, lub na tyle zbliżone, że można nim czasami zastąpić to drugie.');
	
	baloon($('#questAnt'), 'Antonim - oznacza przeciwieństwo, odwrotność innego terminu, natomiast antonimy to terminy przeciwstawne.');
	
	baloon($('#tools_edit'), 'Dodaj nowe znaczenia, przykłady i tłumaczenia hasła, które aktualnie przeglądasz. Rozwijaj MEGAsłownik razem z nami!');
	baloon($('#tools_print'), 'Drukuj zawartość lewej strony');
	
	baloon($('#tools_examples'), 'Klikając tutaj znajdziesz przykłady zdań zawierających słowo, które właśnie przeglądasz. Przykłady pochodzą ze znanych zagranicznych serwisów internetowych. Funkcja ta jest jeszcze w fazie testowej.');
	
	baloon($('#tools_powrot'), 'Powrót do strony z przeglądanym hasłem');
	baloon($('#tools_dodaj_nowe'), 'Możesz dodać zupełnie nowe hasło do MEGAsłownika jeżeli znasz słowa, których tu brakuje. Dodawane hasła są moderowane przez naszych specjalistów');
	baloon($('#tools_lista_brakujacych'), 'Możesz obejrzeć listę haseł poszukiwanych przez użytkowników, których nie ma w bazie MEGAsłownika. Brakujące hasła możesz uzupełnić');
	baloon($('#new_word_link'), 'Możesz dodać zupełnie nowe hasło do MEGAsłownika jeżeli znasz słowa, których tu brakuje. Dodawane hasła są moderowane przez naszych specjalistów');
	
	//if(zakladka != false)
	//	activateBillboard();
	//else if(zakladka_double != false)
	//	activateDoubleBillboard();
	
	
	
	//testy slowek
	$('a.podpowiedz').click(function(){
		var id= $(this).attr('id').substring(5);
		$('#tip_'+id).slideToggle(500);
	});
	
	$('a.tip').click(function(){
		var id= $(this).parent().attr('id').substring(4);
		$('#answer_'+id).val($(this).attr('title'));
	});
	
	$('#checkAll').click( function() {
		if($('#checkAll').is(':checked')) {
			$('.checkComment').attr('checked', true);
		} else {
			$('.checkComment').attr('checked', false);
		}
	});
	
	$(".select_js").change(function() {
		
		switch ($(this).val()) {
			case 'polsko_angielski':
				lang='en';
				rev=0;
				$('#testContent').fadeIn("slow");
				$('#advertisement').fadeOut("slow");
			break;
			
			case 'angielsko_polski':
				lang='en';
				rev=1;
				$('#testContent').fadeIn("slow");
				$('#advertisement').fadeOut("slow");
			break;
			
			case 'polsko_niemiecki':
				lang='de';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'niemiecko_polski':
				lang='de';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_rosyjski':
				lang='ru';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'rosyjsko_polski':
				lang='ru';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_francuski':
				lang='fr';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'francusko_polski':
				lang='fr';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_hiszpanski':
				lang='es';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'hiszpansko_polski':
				lang='se';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_wloski':
				lang='it';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'wlosko_polski':
				lang='it';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_szwedzki':
				lang='se';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'szwedzko_polski':
				lang='se';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_norweski':
				lang='no';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'norwesko_polski':
				lang='no';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_dunski':
				lang='dk';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'dunsko_polski':
				lang='dk';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_chorwacki':
				lang='hr';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'chorwacko_polski':
				lang='hr';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'polsko_ukrainski':
				lang='ua';
				rev=0;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			case 'ukrainsko_polski':
				lang='ua';
				rev=1;
				$('#testContent').fadeOut("slow");
				$('#advertisement').fadeIn("slow");
			break;
			
			default :
				lang='en';
				rev=0;
				$('#testContent').fadeIn("slow");
				$('#advertisement').fadeOut("slow");
			break;
		}
	});
	
	$('a.tip_link').click( function(){
		var id= $(this).attr('id').substring(1);
		
		 $.ajax({
		   type: "GET",
		   url: "/randomWord.php",
		   data: "lang="+lang+"&rev="+rev,
		   success: function(msg){
		    $('#tip'+id).val(msg);
		   }
		 });

		return false;
	});
	
	$('div.link a').click( function(){
		setWordValue(this);
		return false;
	});
	
	$('div.del a').click( function(){
		deleteUserWord(this);
		return false;
	});
	
	
	$('#language_new').change( function(){
		var lang= $(this).val();
		
		$.ajax({
		   type: "GET",
		   url: "/getUserStorage.php",
		   data: "lang="+lang,
		   success: function(msg){
		   	$('.suggestion_content').html(msg);
		   }
		 });
		
	});
	
	$('input#accept').click( function(){
		$('#act').val('accept');		
	});
	
	$('input#delete').click( function(){
		$('#act').val('delete');
	});
	
	
});

var zakladka = true;
var zakladka_double = true;

function activateBillboard() {
	$('#billboard-top').show();
	
	if(openBook) {
		$('#searchform').css('background-image', 'url(/images/bg-search-billboard.gif)').css('padding-top', '64px').css('margin-top', '5px');
	}
	else {
		$('#searchform').css('background-image', 'url(/images/bg-search-billboard-small.gif)').css('padding-top', '61px');
		$('.dodatkowe-litery').css('padding-right', '10px');
	}
	
	$('#mainbody').css('margin-top', '0');
}

function activateDoubleBillboard() {
	$('#doublebillboard-top').show();
	
	if(openBook) {
		$('#searchform').css('background-image', 'url(/images/bg-search-doublebillboard.gif)').css('padding-top', '119px').css('margin-top', '5px');
	}
	else {
		$('#searchform').css('background-image', 'url(/images/bg-search-doublebillboard-small.gif)').css('padding-top', '116px');
	}
	
	$('#mainbody').css('margin-top', '5px');
}

function setCookie(NameOfCookie, value, expiresec)
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiresec * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + "; path=/ " + ((expiresec == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) {
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) { 
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return null;
}

function delCookie (NameOfCookie)
{
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" + "; path=/ ; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function switchViewWordsList(idToHide, idToShow, nameOfCookie, setCook, speed) {
	$('#' + idToHide).hide(0);
	$('#' + idToShow).slideDown(speed);
	if(setCook > 0) {
		setCookie(nameOfCookie, 'megaslownik', 900);
	} else {
		delCookie(nameOfCookie);
	}		
}


var c=0;
var m=0;
var t;
function timedCount() {
	var txt='';
	if(m<10){
		txt=txt+'0'+m;
	} else {
		txt=txt+m;
	}
	txt=txt+':';
	
	if(c<10){
		txt=txt+'0'+c;
	} else {
		txt=txt+c;
	}
	
	$('#stoper').html(txt);
	$('#time').val(60*m+c);
	c++;
	if(c==60) {
		m++;
		c=0;
	}
	t=setTimeout("timedCount()",1000);
}


function addToStorage(lang, word, container_id) {
	$.ajax({
		   type: "GET",
		   url: "/saveUserStorage.php",
		   data: "lang="+lang+"&word="+word,
		   success: function(msg){
		   		$('#img_'+container_id).attr({src: "/images/storage_after_save.gif"});
				alert("Słówko zostało dodane do Twojej przechowalni.\nBędziesz mógł je wykorzystać do tworzenia własnych testów w słówkoTEŚCIE.");
		   }
		 });
}

function deleteUserWord(handler) {
	var id= $(handler).attr('title');
			
		$.ajax({
		   type: "GET",
		   url: "/deleteUserWord.php",
		   data: "unique="+id,
		   success: function(msg){
		    $('.suggest_'+id).fadeOut();
		   }
		 });
}

function setWordValue(handler) {
	var id= $(handler).parents('div:eq(3)').attr('id').substring(2);
	$('#word_'+id).val($(handler).attr('title'));
	
	var divId= $(handler).attr('id');
	$('.suggest_'+divId).fadeOut();
}



//-->
