var _config = {
	controller: 'index',
	action: 'index'
}

var _user = {
	bIsLogged: false
}

//
// Tłumaczenia
//
var _translations = new Array();

_translations['pl'] = new Array();
_translations['en'] = new Array();

_translations['pl']['polec_znajomemu'] = 'Poleć znajomemu';
_translations['pl']['prosze_czekac'] = 'Proszę czekać...';
_translations['pl']['twoj_adres'] = 'twój adres';
_translations['pl']['wpisz_szukana'] = 'wpisz szukaną frazę';
_translations['pl']['wyslano_zamknij'] = 'Dziękujemy za przesłanie wiadomości. Kliknij X, aby zamknąć.'

_translations['en']['polec_znajomemu'] = 'Recommend site to friend';
_translations['en']['prosze_czekac'] = 'Please wait...';
_translations['en']['twoj_adres'] = 'your e-mail';
_translations['en']['wpisz_szukana'] = 'enter search term';
_translations['en']['wyslano_zamknij'] = 'Thank you for recommending our site. Click X to close this window.';

//
// Główny skrypt
//
$(document).ready(function(){

	$(".main_kursy_content").css("min-height",$("#main_aktualnosci_content").height()-72);

	// zoomer do logotypow w stopce
	$('ul.thumb li').Zoomer({speedView:200,speedRemove:400,altAnim:false,speedTitle:400,debug:false});
	
	$(".tooltip").each(function(){
		if ($(this).attr('title')!=''){
			$(this).wTooltip({
			style: {
				border: "1px solid #e7e7e7",
				background: "#88B2DE",
				color: "white",
				maxWidth: "500px"
			}
			})
		}						
	});

	$('.nav>li>ul').hide();
	
	var element_aktywny = $('a.active', $('.nav') );
	
	element_aktywny.show();
	element_aktywny.parent().show();
	element_aktywny.parent().parent().show();
	element_aktywny.parent().parent().parent().show();

	
	// aktywne menu - zaznaczenie
	$('a', $('.nav')).each(function(i,el){				
		if ($(this).attr('href')==location.href){
			$(this).parent().children('ul').show();			
			//$(this).parent().children('a').css('backgroundColor','#83161D');			
			//$(this).parent().children('a').css('color','blue');			
			$(this).parent().children('a').css('fontWeight','bold');													
		}
				
	});	

	$('a', $('.nav')).each(function(i,el){				
		if ($(this).attr('href')==location.href){
			$(this).parent().children('ul').show();
									
			$(this).parent().show();
			$(this).parent().parent().show();
		}
				
	});		
	

	$("#rzetelna_firma").hover(		
		function () { 	
			$(this).css('border','4px solid #dfe1e0');			
		}, 
		function () { 			
			$(this).css('border','4px solid #EFF1F0');			
		}				 
	); 				
		







	
	$("#wyslij_zapytanie_img").bind('click',function(e){							
		$("#wyslij_zapytanie").slideToggle("slow");
	});		
	
	// najezdzanie na glowne menu
	$(".menu_boczne .menuItem0 > a").hover(		
		function () { 			
			$(this).css('text-decoration','none');			
			//$(this).attr('alt',$(this).css('backgroundColor'));
			//$(this).css('color','blue');			
			$(this).css('fontWeight','bold');
			//$(this).css('backgroundColor','#83161C');				
		}, 
		function () { 			
			var klasa = $(this).attr('className');			
			$(this).css('text-decoration','none');					
			$(this).css('color','#ddffff');			
			if (klasa.indexOf('active')==-1)
				$(this).css('fontWeight','normal');
			//$(this).css('backgroundColor',$(this).attr('alt'));
		}		
		 
	); 		
	
	$(".menu_boczne .menuItem1 > a").hover(		
		function () { 			
			//$(this).attr('alt',$(this).css('background'));			
			$(this).attr('rev',$(this).css('fontWeight'));			
			//$(this).css('background','url(views/img/right_arrow_gray.gif) no-repeat scroll 0 55% #FFFFFF');				
			$(this).css('textDecoration','none');
			$(this).css('fontWeight','bold');
		}, 
		function () { 						
			//$(this).css('background',$(this).attr('alt'));			
			$(this).css('fontWeight','normal');			
			if ($(this).attr('className')=='active'){
				$(this).css('fontWeight','bold');			
			}	
			$(this).css('textDecoration','none');
			//$(this).css('fontWeight','normal');
		}		
		 
	); 		
		
	if (lewe_blad==1)
		$("#wyslij_zapytanie").slideToggle("slow");

	$("#left_imie").bind('keyup',function(e){							
		$.cookie("left_imie", $(this).attr('value'));							
	});		

	$("#left_email").bind('keyup',function(e){							
		$.cookie("left_email", $(this).attr('value'));				
	});			

	$("#left_tresc").bind('keyup',function(e){							
		$.cookie("left_tresc", $(this).attr('value'));				
	});				


	if (lewe_wyslano==1){			
		$.cookie("left_imie", null);				
		$.cookie("left_email", null);				
		$.cookie("left_tresc", null);				
		alert("Zapytanie zostało wysłane");	
		lewe_wyslano = 0;
	}

	if ($.cookie("left_imie")!=null)
		$("#left_imie").attr('value',$.cookie("left_imie"));
	if ($.cookie("left_email")!=null)		
		$("#left_email").attr('value',$.cookie("left_email"));
	if ($.cookie("left_tresc")!=null)	
		$("#left_tresc").attr('value',$.cookie("left_tresc"));	

	$(".middle").hover( 
		function () { 			
			$(this).css('border','5px solid #88B2DE');			
		}, 
		function () { 			
			$(this).css('border','5px solid #FFFFFF');
		}		
		 
	); 	
	
	$(".previous").hover( 
		function () { 			
			$(this).css('text-decoration','underline');						
		}, 
		function () { 			
			$(this).css('text-decoration','none');
		}		
		 
	); 	

	
	$("#contact_wyslij_pl").hover( 
		function () { 			
			$(this).attr('src','http://www.psikurs.pl/views/img/pl/button_contact_on.png');
		}, 
		function () { 			
			$(this).attr('src','http://www.psikurs.pl/views/img/pl/button_contact.png');
		}		
		 
	); 	
	$("#contact_wyslij_en").hover( 
		function () { 			
			$(this).attr('src','http://www.psikurs.pl/views/img/en/button_contact_on.png');
		}, 
		function () { 			
			$(this).attr('src','http://www.psikurs.pl/views/img/en/button_contact.png');
		}		
		 
	); 		

	$(".box_salonu").hover( 
		function () { 			
			$(this).css('background','#ffffff');
		}, 
		function () { 			
			$(this).css('background','none');
		}		
		 
	); 	
	$('.box_salonu').bind('click',function(e){			
		$(this).children(".wewnatrz").children(".link").click();
	});							
/*	
	$('.naglowek').each(function(i,el){
		var randID = 'rand'+Math.floor(Math.random()*1000);
		var tmp = document.createElement("span");		
		$(el).wrap(tmp);
		$(el).attr('id',randID);
		
		var tekst = el.innerHTML.replace('&nbsp;',' ');
		
		swfobject.embedSWF(
			'/views/flash/textbox.swf?tekst='+tekst.toUpperCase(), 
			randID, 
			"690px", 
			"40px", 
			"9.0.0", 
			"",
				{ },
				{ swliveconnect: true, wmode: "transparent", scale: "noScale", menu: "false", align: "left", salign: "TL" },
				{ id: randID, name: randID }
		);

		
	});		
	
	$('.naglowek2').each(function(i,el){
		var randID = 'rand'+Math.floor(Math.random()*1000);
		var tmp = document.createElement("span");		
		$(el).wrap(tmp);
		$(el).attr('id',randID);
		
		var tekst = el.innerHTML.replace('&nbsp;',' ');
		
		swfobject.embedSWF(
			'/views/flash/textbox.swf?tekst='+tekst.toUpperCase(), 
			randID, 
			"300px", 
			"30px", 
			"9.0.0", 
			"",
				{ },
				{ swliveconnect: true, wmode: "transparent", scale: "noScale", menu: "false", align: "left", salign: "TL" },
				{ id: randID, name: randID }
		);

		
	});	
	
*/

	$(".box_salonu").hover( 
		function () { 			
			$(this).css('background','#ffffff');
		}, 
		function () { 			
			$(this).css('background','none');
		}		
		 
	); 	
	
/*	
	$('.naglowek').each(function(i,el){
		var randID = 'rand'+Math.floor(Math.random()*1000);
		var tmp = document.createElement("span");		
		$(el).wrap(tmp);
		$(el).attr('id',randID);
		
		var tekst = el.innerHTML.replace('&nbsp;',' ');
		
		swfobject.embedSWF(
			'/views/flash/textbox.swf?tekst='+tekst.toUpperCase(), 
			randID, 
			"690px", 
			"40px", 
			"9.0.0", 
			"",
				{ },
				{ swliveconnect: true, wmode: "transparent", scale: "noScale", menu: "false", align: "left", salign: "TL" },
				{ id: randID, name: randID }
		);

		
	});		
*/	
	// Strona główna, top
	// flashvars, params, attributes
	swfobject.embedSWF(
		'views/flash/baner.swf', 'top_srodek',
		'430', '170', '9.0.0', '', { sciezka: 'Awards.php' }, { }, { 'wmode': 'transparent' }
	);

	swfobject.embedSWF(
		'views/flash/salony.swf', 'salony',
		'435', '375', '9.0.0', '', {}, { }, { 'wmode': 'transparent' }
	);	
	
	swfobject.embedSWF(
		'views/flash/animacja.swf', 'main_flash_podmianka',
		'940', '486', '9.0.0', '', { 'wmode': 'transparent'}, {'wmode': 'transparent' }, { 'wmode': 'transparent' } 
	);
	
	
	
	$.datepicker.setDefaults({
		firstDay: '1',
		dateFormat: 'yy-mm-dd',
		changeYear: true,
		dayNames: ['Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'],
		dayNamesMin: ['Nd', 'Pn', 'Wt', 'Śr', 'Cz', 'Pt', 'So'],
		monthNames: ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień']
	});

	// Menu główne, klasy pomocnicze dla CSS
	$('.menu_boczne .active').parents('li').children('a').not('.active').addClass('expanded');
	$('.menu_boczne .active').parents('li').next('.menuItem0').addClass('after-active');

	// IE hack
	$('.menuItem0_first > a').addClass('menuItem0_a_first');

	// Poleć znajomemu
	$('#recommendDialog').dialog({
		bgiframe: true,
		width: 600,
		modal: true,
		autoOpen: false,
		resizable: false,
        title: _translations[_config.lang]['polec_znajomemu']
	});

	$('#recommendButton').click(function(){
		$('#recommendDialog').dialog('open');
		$('.ui-widget-overlay').css('width', '100%');

		return false;
	});

	$('#recommendDialog .btnSend').click(function(){
		$('#recommendDialog .messageList').show();
		$('#recommendDialog .ok').text(_translations[_config.lang]['prosze_czekac']).show();

		var dane = {
			imie_nazwisko: $('#recommendDialog input[name="imie_nazwisko"]').val(),
			email_nadawcy: $('#recommendDialog input[name="email_nadawcy"]').val(),
			email_odbiorcy: $('#recommendDialog input[name="email_odbiorcy"]').val(),
			tresc: $('#recommendDialog textarea').val()
		};

		$('#recommendDialog .messageList .messageError').hide();
		$('#recommendDialog input, #recommendDialog textarea').css({'border': '1px solid #ccc'});

		$.post("recommend,index.html", dane, function(data) {
			if(!data.ok) {
				$('#recommendDialog .messageList').show();
				$('#recommendDialog .ok').hide();

				for(x in data.bledy) {
					$('#recommendDialog input[name="' + x + '"]').css({'border': '1px solid #fb4d4e'});
					$('#recommendDialog textarea[name="' + x + '"]').css({'border': '1px solid #fb4d4e'});
					$('#recommendDialog .' + x).text(data.bledy[x]).show();
				}
			} else {
				$('#recommendDialog .messageList').show();
				$('#recommendDialog .ok').text(_translations[_config.lang]['wyslano_zamknij']).show();
			}
		}, 'json');

		return false;
	});

	// IE hover hack.
	$('.newsDetails img').mouseenter(function(){
		$(this).addClass('on');
	}).mouseleave(function(){
		$(this).removeClass('on');
	});

	$('.search input[name="keywords"]').focus(function(){
		$(this).val('');
	}).blur(function(){
		if ($(this).val() == '')
			$(this).val(_translations[_config.lang]['wpisz_szukana']);
	}).val(_translations[_config.lang]['wpisz_szukana']);

	//
	// Logotypy w stopce
	//
	$('#spolki .carousel').jCarouselLite({
		auto: 3000,
		speed: 1000,
		visible: 7
	});

	//
	// Zewnętrzne linki
	//
	$('a[rel~="external"]').attr('target', '_blank');

	//
	// Newsletter
	//
	$('.newsletter input[name="email"]').focus(function(){
		$(this).val('');
	}).blur(function(){
		if ($(this).val() == '')
			$(this).val(_translations[_config.lang]['twoj_adres']);
	}).val(_translations[_config.lang]['twoj_adres']);

	$('#messageDialog').dialog({
		bgiframe: true,
		width: 400,
		modal: true,
		autoOpen: false,
		resizable: false,
        title: 'MORP'
	});

	$('.newsletter #signin, .newsletter #signout').click(function(){
		$('#messageDialog').dialog('open').find('.status').html('Proszę czekać...');
		$('#messageDialog .btnClose').hide();

		$.post('newsletter,' + $(this).attr('id') + '.html', { email: $('.newsletter input[name="email"]').val() }, function(response){
			$('#messageDialog .status').html(response);
			$('#messageDialog .btnClose').show();
		});

		return false;
	});

	$('#messageDialog .btnClose').click(function(){
		$('#messageDialog').dialog('close');

		return false;
	});

	//
	// LI float hack :]
	//
	//$('.fck ul li').prepend($('<img src="views/img/arrow.gif" alt="" />'));

	//
	// Hack na tło w tabelach FCK
	//
	$.each($('.fck td'), function(){
		var value = $(this).attr('bgcolor');

		if (value)
			$(this).css('background-color', value);
	});

	$.each($('.fck img'), function(){
		var value = $(this).attr('align');

		if (value)
			$('.fck img').css('text-align', 'left');
	});

	$.each($('.fck td'), function(){
		var value = $(this).attr('valign');

		if (value)
			$(this).css('vertical-align', value);
	});

	$.each($('.fck table'), function(){
		var value = $(this).attr('cellpadding');

		if (value)
			$(this).css('border-spacing', value + 'px');
	});
	
	
	$('#.oneBaner').css('width','312px');
	
	
	$('#.oneBaner').css('width','312px');
});


