$(document).ready(function(){

	//swfobject.embedSWF("/flash/cuber.swf", "CuberPlace", "980", "400", "9.0.0", "expressInstall.swf", {}, { 'scale':'noscale','menu': 'false', 'wmode': 'transparent' }, { 'align':'top' } );
	swfobject.embedSWF("/flash/slider.swf", "SliderPlace", "960", "350", "9.0.0", "expressInstall.swf", {}, { 'scale':'noscale','menu': 'false', 'wmode': 'transparent' }, { 'align':'top' } );
	
	$('a.Rep,a.RepGB').each(function(){
		var e = $(this).attr("href").replace("/","").split(".html")[0]+"@"+$(this).attr("rel");
		$(this).attr({"href":"mailto:"+e});
		if($(this).attr('class').indexOf('RepGB')==-1) $(this).text(e);
	});
	
	$(".lightbox").fancybox({
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'image'
	});
	
	//$("#Main .Text p:last").css({'padding-bottom':'0px'});
	
	$("#LostPasswordButton").click(function(){
		$.fancybox({
			'autoScale'			: true,
			'content'			: '<div id="LostPassForm"><form action="" method="post"><p>Wpisz swój LOGIN a nowe hasło zostanie wysłane na przypisany adres email.</p><input type="text" name="LostPassLogin" /><button type="submit" name="SendLostPass">Wyślij ></button></form></div>'
		});
		return false;
	});
	
	$("#Information").click(function(){
		$(this).animate({opacity:"hide",height:"hide"},"slow")
	});
	
	$("#Captcha img").click(function(){
		$(this).animate({ opacity: 'hide' }, "fast",null,function(){
			$(this).attr({"src":"/captcha.jpg?sid="+ Math.round(Math.random()*100000) });
			$(this).animate({ opacity: 'show' }, "slow");
		});
	});
	
	$("#Zoomer img").hover(
		function () { $(this).stop().animate({ width:"150px", height:"100px", left:"-15px",top:"-10px" }, "fast", "easeInQuad"); },
		function () { $(this).stop().animate({ width:"120px", height:"80px", left:"0px", top:"0px" }, "fast", "easeInQuad"); }
	);
	
	if($("#MapaKontakt").length) {
		
		CenterX = 52.21877798527562;
		CenterY = 21.151778567932135;
		MarkerX = 52.21824556903837;
		MarkerY = 21.25437494625855;
		
		var myOptions = {
			zoom: 11,
			center: new google.maps.LatLng(CenterX,CenterY),
			mapTypeControl: true,
			mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
			navigationControl: true,
			navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		
		var map = new google.maps.Map(document.getElementById("MapaKontakt"), myOptions);
		var infowindow = new google.maps.InfoWindow({ 
			content: '<div style="width:400px;height:200px;"><img src="/gfx/firma.jpg" alt="Octanorm" /></div>',
			size: new google.maps.Size(420,220)
		});
		var location = new google.maps.LatLng(MarkerX, MarkerY);
		var marker = new google.maps.Marker({
			position: location, 
			title: "Octanorm", 
			map: map
		});
		//52.28715899344191
		//21.28920364306639
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.open(map,marker);
			/* $.fancybox({
				'type'				: 'image',
				'width'				: 750,
				'height'			: 424,
				'href'				: '/gfx/interiordesign.jpg'
			}); */
			
		});

	}
	
	if($("#ListaZdjec").length>0) {
		$("#ListaZdjec img").css({"opacity":".5"});
		$("#SubMenu a").hover(
			function () { $("#pic-"+$(this).attr("id")).stop().fadeTo('fast', 1); }, 
			function () { $("#pic-"+$(this).attr("id")).stop().fadeTo('slow', 0.3); }
		);
		$("#ListaZdjec img").hover(
			function () { $(this).stop().fadeTo('fast', 1); }, 
			function () { $(this).stop().fadeTo('slow', 0.3); }
		);
	}
	
});

function CheckContactForm() {
	
	var text = $("#fText").val();
	var name = $("#fName").val();
	var firm = $("#fFirm").val();
	var street = $("#fStreet").val();
	var codecity = $("#fCodeCity").val();
	
	var answerphone = $("#fAnswerPhone").attr("checked");
	var answeremail = $("#fAnswerEmail").attr("checked");
	
	var phone = $("#fPhone").val();
	var email = $("#fEmail").val();
	var code = $("#fCode").val();
	
	if(text.length==0) return ShowError(AskQuestionErrors[0]);
	if(name.length==0) return ShowError(AskQuestionErrors[1]);
	if(firm.length==0) return ShowError(AskQuestionErrors[2]);
	if(street.length==0) return ShowError(AskQuestionErrors[3]);
	if(codecity.length==0) return ShowError(AskQuestionErrors[4]);
	
	if(!answerphone && !answeremail) return ShowError(AskQuestionErrors[8]);
	if(answerphone && phone.length==0) return ShowError(AskQuestionErrors[5]);
	if(answeremail && email.length==0) return ShowError(AskQuestionErrors[6]);
	if(answeremail && !checkEmail(email)) return ShowError(AskQuestionErrors[7]);
	
	if(code.length!=5) return ShowError(AskQuestionErrors[9]);
	
	return true;
}

function checkEmail(x){return/^[\w\.-]+@([\w-]+\.)*[a-z]{2,4}$/.test(x)}

function ShowError(txt) {
	$.fancybox({
		'autoScale'			: true,
		'content'			: '<div id="Question"><div class="txt">'+txt+'</div></div>'
	});
	return false;
}

