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(){


	$(".tooltip").each(function(){
		if ($(this).attr('title')!=''){
			$(this).wTooltip({
			style: {
				border: "1px solid #e7e7e7",
				background: "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();

	$('a', $('.nav')).each(function(i,el){				
		if (($(this).attr('href')==location.href)&&(location.href.indexOf('product,index,')==-1)){
			$(this).parent().children('ul').show();			
			$(this).parent().children('a').css('backgroundColor','#83161D');			
			$(this).parent().children('a').css('color','white');			
			$(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 #e3dee2');			
		}, 
		function () { 			
			$(this).css('border','4px solid #dfe1e0');			
		}				 
	); 				
	
	// gorne menu
	$(".topmenu1").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/pl/menu1_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 			
	$(".topmenu2").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/pl/menu2_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 				
	$(".topmenu3").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/pl/menu3_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 			
	$(".topmenu4").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/pl/menu4_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 			

	$(".topmenu5").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/pl/menu5_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 				

	$(".topmenu6").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/pl/menu6_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 			

	// gorne menu EN
	$(".topmenu1_en").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/en/menu1_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 			
	$(".topmenu2_en").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/en/menu2_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 				
	$(".topmenu3_en").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/en/menu3_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 			
	$(".topmenu4_en").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/en/menu4_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 			

	$(".topmenu5_en").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/en/menu5_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 				

	$(".topmenu6_en").hover(		
		function () { 	
			$(this).attr('rel',$(this).attr('src'));
			$(this).attr('src','../views/img/en/menu6_on.jpg');
		}, 
		function () { 			
			$(this).attr('src',$(this).attr('rel'));
		}				 
	); 			







	
	$("#wyslij_zapytanie_img").bind('click',function(e){							
		$("#wyslij_zapytanie").slideToggle("slow");
	});		
	
	
	$(".menu_boczne .menuItem0 > a").hover(		
		function () { 				
			$(this).css('text-decoration','none');			
			$(this).attr('alt',$(this).css('backgroundColor')+'|'+$(this).css('fontWeight'));
			$(this).css('color','#ffffff');			
			$(this).css('backgroundColor','#83161C');				
		}, 
		function () { 			
			$(this).css('text-decoration','none');								
			var zmienna = $(this).attr('alt').split('|');			
			$(this).css('backgroundColor',zmienna[0]);						
			if ((zmienna[0]!='rgb(131,22,28)')&&(zmienna[0]!='rgb(131, 22, 28)'))
				$(this).css('color','#222222');
			else
				;//alert('i tak');
			$(this).css('fontWeight',zmienna[1]);
			
			
			$('a', $('.nav')).each(function(i,el){				
				if (($(this).attr('href')==location.href)&&(location.href.indexOf('product,index,')==-1)){
					$(this).parent().children('ul').show();			
					$(this).parent().children('a').css('backgroundColor','#83161D');			
					$(this).parent().children('a').css('color','white');	
					$(this).parent().children('a').css('fontWeight','bold');										
				}
			});							
			
		}		
		 
	); 		
	
	$(".menu_boczne .menuItem1 > a").hover(		
		function () { 			
			$(this).attr('alt',$(this).css('background'));			
			$(this).attr('rev',$(this).css('fontWeight'));			
			if ($(this).attr('alt')=='')
				$(this).attr('alt',$(this).css('backgroundColor'));			
			$(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 #e3dee2');			
		}, 
		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',WEB_IMG+'pl/button_contact_on.png');
		}, 
		function () { 			
			$(this).attr('src',WEB_IMG+'pl/button_contact.png');
		}		
		 
	); 	
	$("#contact_wyslij_en").hover( 
		function () { 			
			$(this).attr('src',WEB_IMG+'en/button_contact_on.png');
		}, 
		function () { 			
			$(this).attr('src',WEB_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');
});


