﻿function checkemail(str){
	var filter=/^.+@.+\..{2,3}$/
	return (filter.test(str))
}

$().ready(function() {

	$('.img_big a').lightBox();

	$('#menu a').mouseover(function() {
		
		subname = $(this).attr('title');
		
		if(subname)
		{
			$(this).addClass('active2');
			$('.'+subname).show();
		}
		return false;
	});
	
	$('.has_extension').mouseover(function() {

		$('.first_angielski').css('background-position','0px 30px');		

		subname = $(this).attr('title');
		
		if(subname)
		{
			$(this).addClass('active2');
			$('.'+subname).show();
		}
		return false;
	});
	
	$('.extension').mouseover(function() {

		$('.first_angielski').css('background-position','0px 30px');		
		return false;
	});	
	
	$('.has_extension').click(function() {
		$('.has_extension').removeClass('active2');
		return false;
	});

	$('.has_submenu').click(function() {
		$('#menu .btn').removeClass('active2');
		$('.submenu').fadeOut('fast');
		$('.extension').fadeOut('fast');
		return false;
	});

	$('.submenu').mouseover(function() {
		$('.first_angielski').css('background-position','0px 0px');
		$('.extension').fadeOut('fast');
		return false;
	});

	$('body').mouseover(function() {
		$('.first_angielski').css('background-position','0px 0px');	
		$('#menu .btn').removeClass('active2');
		$('.submenu').fadeOut('fast');
		$('.extension').fadeOut('fast');		
		return false;
	});
	
	$('.map').jmap('init', {'mapType':'map','mapCenter':[50.319957,19.207964], 'mapZoom':16});
	$('.map').jmap('AddMarker', {'pointLatLng': [50.319957,19.207964]});


	msgs = new Array();
	msgs['name'] = 'Wpisz imię i nazwisko';
	msgs['email'] = 'Wpisz adres e-mail';
	msgs['phone'] = 'Wpisz numer telefonu';
	msgs['body'] = 'Wpisz wiadomość';
	msgs['country'] = 'Wpisz kraj / miejscowość';
	msgs['date'] = 'Wpisz termin wyjazdu';
	msgs['time'] = 'Wpisz długość pobytu';
	msgs['age'] = 'Wpisz rok urodzenia';
	msgs['language'] = 'Wpisz język';
	msgs['region'] = 'Wpisz miejscowość / region';
	msgs['limit'] = 'Wpisz limit';

	$('textarea, input').focus(function() {
		if($(this).val()==msgs[this.name]) $(this).val('');
	});
	
	$('textarea, input').blur(function() {
		if($(this).val()=='') $(this).val(msgs[this.name]);
	});

	$('.contact_form textarea, .contact_form input').each(function() {
		$(this).val(msgs[this.name]);
	});

	$('.btn_send').click(function() {
		resultList = '';
		error=false;

		$('.contact_form input, .contact_form textarea').each(function() {
		
			
			change_class = 'input';
			if($(this).parent().hasClass('textarea'))
			change_class = 'textarea';

			if(this.value=='' || this.value==msgs[this.name])
			{
				error=true;
				$(this).parent().addClass(change_class+'_r');
			}
			else
			$(this).parent().removeClass(change_class+'_r');

			if(this.name=='email')
			{
				if (!checkemail(this.value))
				{
					$(this).val(msgs[this.name]);
					error=true;
					$(this).parent().addClass(change_class+'_r');
				}
				else
				$(this).parent().removeClass(change_class+'_r');
			}


			resultList += this.name+'='+this.value+'&';

		});


		if(error==false)
		{
			$('.contact_form').hide();
			$('.text2 .loader').fadeIn();

			$.ajax({   
				type: "POST",   
				url: "/extras/contact.php",  
				data: resultList,   
				success: function(html)
				{  
					$('.text2 .loader').fadeOut();
					$('.text2 .loader').after('<div class="result">'+html+'</div>');
				}	 
			});
		}

		return false;
	});

	$('.btn_go').click(function() {
		resultList = '';
		error=false;

		$('.newsletter_form input').each(function() {
		
		 if(this.name=='email')
		 {		
			if (!checkemail(this.value))
			{
				$(this).val(msgs[this.name]);
				error=true;
				$(this).parent().addClass('input_r');
			}
			else
			$(this).parent().removeClass('input_r');
		 }

			resultList += this.name+'='+this.value+'&';

		});

		if(error==false)
		{
			$('.newsletter_hide').hide();
			$('.newsletter .loader').fadeIn();


			$.ajax({   
				type: "POST",   
				url: "/extras/newsletter.php",  
				data: resultList,   
				success: function(html)
				{  
					$('.newsletter .loader').fadeOut();
					$('.newsletter .loader').after('<div class="result_newsletter">'+html+'</div>');
				}	 
			});
		}
		return false;
	});

	$('.btn_del').click(function() {
		resultList = '';
		error=false;

		$('.newsletter_form input').each(function() {
		
		 if(this.name=='email')
		 {		
			if (!checkemail(this.value))
			{
				$(this).val(msgs[this.name]);
				error=true;
				$(this).parent().addClass('input_r');
			}
			else
			$(this).parent().removeClass('input_r');
		 }

			resultList += this.name+'='+this.value+'&';

		});

		if(error==false)
		{
			$('.newsletter_hide').hide();
			$('.newsletter .loader').fadeIn();


			$.ajax({   
				type: "POST",   
				url: "/extras/newsletter.php",  
				data: resultList+'delete=true',   
				success: function(html)
				{  
					$('.newsletter .loader').fadeOut();
					$('.newsletter .loader').after('<div class="result_newsletter">'+html+'</div>');
				}	 
			});
		}
		return false;
	});


	$('#transport').DeseoSelect(178);
	$('#type').DeseoSelect(178);
	$('#cantonment').DeseoSelect(178);
	$('#wyzywienie').DeseoSelect(178);	
	$('#waluta').DeseoSelect(178);
	$('#limit').DeseoSelect(178);		
	$('#jezyk').DeseoSelect(178);	


	$('.wybor img').mouseover(function() {
		$(this).fadeTo('normal', '0.4');
	});

	$('.wybor img').mouseout(function() {
		$(this).fadeTo('normal', '1');
	});

	$('.wybor img').click(function() {
		return false;
	});


	$('.flash_cont').flash(
		{ src: '/media/flash.swf',
		  width: 940,
		  height: 325,
		  wmode: 'transparent'},
		{ version: 8 }
	);

	if(!$('.flash_cont').children('embed').width())
	{
		$('#header').css('background-image', 'url(media/images/header.jpg)');
	}



});
