// biurodetektywistyczne.pl
// effects.js
// by Jacek Bandura


function hideNotNeeded() {
	var items = ['.wspl_frame', '#eng_form', '#de_form', '#more', ".oferta_div", ".wspl_html", "#captcha_animation"];
	for (var i=0; i<items.length; i++) {
		$(items[i]).hide();
	}
}

function showRecaptcha(element) {
	Recaptcha.create("6Lf_vLsSAAAAACvfIAuDvMMyjaizEWvbLQIrjHBg", element, {
	theme: "clean",
	callback: Recaptcha.focus_response_field});
}


function showDiv(div) {
	var element = $(div);
	$(".oferta_div").css("display", "none");
	element.show("fast");
}

function makeBold(el) {
	var element = $(el);
	if(element.css('font-weight') == 'bold') { 
		element.css("font-weight", "normal"); 
	}
	else { element.css("font-weight", "bold"); }
}

function pokazPodpis(lang) {
	
	var esp = $("#engpod");
	var desp = $("#depod");
	var plsp = $("#plpod");
	
	switch(lang) {
		case "eng":
			plsp.css("display", "none");
			desp.css("display", "none");
			esp.fadeIn(600);
		break;
		case "pl":
			esp.css("display", "none");
			desp.css("display", "none");
			plsp.fadeIn(600);
		break;
		case "de":
			esp.css("display", "none");
			desp.fadeIn(600);
			plsp.css("display", "none");
		break;
	}
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


function ukryjPodpisy() {
	$("#engpod").css("display", "none");
	$("#depod").css("display", "none");
	$("#plpod").css("display", "none");
}

function showForm(lang) {
	switch (lang) {
		
		case "eng":
		$("#pl_form").css("display", "none");
		$("#de_form").css("display", "none");
		$("#eng_form").css("display", "");
		
		$("#disp_eng").css("font-weight", "bold");
		$("#disp_de").css("font-weight", "normal");
		$("#disp_pl").css("font-weight", "normal");
		break;
		
		case "pl" :
		$("#pl_form").css("display", "");
		$("#de_form").css("display", "none");
		$("#eng_form").css("display", "none");
		
		$("#disp_pl").css("font-weight", "bold");
		$("#disp_de").css("font-weight", "normal");
		$("#disp_eng").css("font-weight", "normal");
		break;
		
		case "de" :
		$("#pl_form").css("display", "none");
		$("#de_form").css("display", "");
		$("#eng_form").css("display", "none");
		
		$("#disp_de").css("font-weight", "bold");
		$("#disp_eng").css("font-weight", "normal");
		$("#disp_pl").css("font-weight", "normal");
		break;
		
	}
}

function showWspl(what) {
	$(".wspl_frame").css("right", "4px");
	$(".wspl_frame").slideToggle("slow");
	$(this).toggleClass("active");
	var html = $("#" + what).html();
	$(".wspl_frame").html(html);
}

function showCurNav() {
	var pages = ['index', 'oferta', 'kontakt', 'onas', 'struktura', 'placowki'];
	var i = 0;
	var j = 5;
	for( i = 0; i <= j; i++)
	{
		if(window.location.pathname.indexOf(pages[i]) > 0 )
		{
			$("#nav_" + pages[i]).addClass("current");
		}
	}
}


$(document).ready(function() {
	hideNotNeeded();
	ukryjPodpisy();
	showCurNav();
	if(window.location.pathname.indexOf('kontakt' > 0)) {
		$(window).load(function () {
			showRecaptcha('captcha');					 
		});
	}
	
	//fancybox
	
/*	$("a#inline").fancybox({
		'hideOnContentClick': true,
		'overlayOpacity': 0.5
	});
	
	$("a#inline2").fancybox({
		'hideOnContentClick': true,
		'overlayOpacity': 0.5
	});
	$("a#inline3").fancybox({
		'hideOnContentClick': true,
		'overlayOpacity': 0.5,
	});*/
	
	if(!window.location.pathname.indexOf('admin' > 0)) {
		$("a.inline").fancybox({
			'autoDimensions': false,
			'width' : 400,
			'height': 200
		});
	}
	
	
	
	// pasek wspolpraca hover
	$("a#wspl_psld, a#wspl_iaati, a#wspl_ispa").hover(function() { $(this).toggleClass("active") });
	
	//oferta linki
	
	$(".ofertalinki .child li").hover(function() {
		$(this).toggleClass("active");
	});
	$(".ofertalinki .child li").click(function() {
		$(this).toggleClass("active");
		$(this).siblings("li").removeClass("active");
	});
	
	$("#div_main").css("display", "block");

	$("#disp_pl").css("font-weight", "bold");
	$("#logo").fadeIn(2000);
	$('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});	
	$(".more").click(function() {
		$('#more').css("display", "");
		$('#def').css("display", "none");
	});
	$(".less").click(function() {
		$('#more').css("display", "none");
		$('#def').css("display", "");
	});
	
	$("#kontakt").submit( function(event) {
		$(this).validate({
				rules: {
				  name: { 
					  required: true
				  },    // simple rule, converted to {required: true}
				  user_mail: {             // compound rule
					  required: true,
					  email: true
				  },
				  tel: {
					required: true,
					number: true
				  },
				  content: {
					required: true
				  }
				},
				messages: {
				  content: Lang.required,
				  name: Lang.required,
				  user_mail: { 
				  	required: Lang.required,
					email: Lang.user_mail
				  },
				  tel: { 
				  	required: Lang.required,
					number: Lang.tel 
				  }
				}
		});						   
		if($("#captcha_animation").hasClass("hidden")) {	
			$("#captcha_animation").show('slow');
			$("#captcha_animation").removeClass("hidden");
			return false;
		}
		else {
			if($(this).valid()) {
				return true;	
			}
			else {
				return false;
			}
		}
		
	});
	
	$("#pl").hover(function() { pokazPodpis("pl") }, function() { ukryjPodpisy() });
	$("#de").hover(function() { pokazPodpis("de") }, function() { ukryjPodpisy() });
	$("#eng").hover(function() { pokazPodpis("eng") }, function() { ukryjPodpisy() });
	
	$("#disp_pl").click(function() { showForm("pl") });
	$("#disp_de").click(function() { showForm("de") });
	$("#disp_eng").click(function() { showForm("eng") });
	
	
});
