﻿$(document).ready(function() {

	jQuery.fn.exists = function() { return jQuery(this).length>0; }



	// Focus border remove

			$("a").focus(function() {
				$(this).blur();
			});






	// Menu dropdown

			$(".menu_head").click(function() {
				$(this).next(".menu_body").slideToggle(300).siblings(".menu_body").slideUp("fast");
			});


			$(".hit").next(".menu_body").slideToggle(300).siblings(".menu_body").slideUp("fast");





	// Opacity

			$.fn.opacity = function() {
				$(this).hover(
				  function () {
					$(this).css({ opacity: ".9" });
				  },
				  function () {
					$(this).css({ opacity: "1" });
				  }
				);
			}

			if ($('#gallery').exists()) {
				$('#gallery a').opacity();
			}





	// Change Font Size

			$(".small").click(function(){
				var $cookie_name = "textsize";
				var $cookie_line = "lineheight";
				var $newFontSize = "100%";
				var $newLineHeight = "16px";

				$("#center").css({ fontSize: $newFontSize, lineHeight: $newLineHeight });

				$.cookie($cookie_name, $newFontSize);
				$.cookie($cookie_line, $newLineHeight);

				return false;
			});



			$(".medium").click(function(){
				var $cookie_name = "textsize";
				var $cookie_line = "lineheight";
				var $newFontSize = "120%";
				var $newLineHeight = "16px";

				$("#center").css({ fontSize: $newFontSize, lineHeight: $newLineHeight });

				$.cookie($cookie_name, $newFontSize);
				$.cookie($cookie_line, $newLineHeight);

				return false;
			});

			$(".large").click(function(){
				var $cookie_name = "textsize";
				var $cookie_line = "lineheight";
				var $newFontSize = "140%";
				var $newLineHeight = "18px";

				$("#center").css({ fontSize: $newFontSize, lineHeight: $newLineHeight });

				$.cookie($cookie_name, $newFontSize);
				$.cookie($cookie_line, $newLineHeight);

				return false;
			});


			checkCookies = function() {
				var $cookie_name = "textsize";
				var $cookie_line = "lineheight";
				var $originalFontSize = $("#center").css("font-size");

				if($.cookie($cookie_name)){
					var $getSize = $.cookie($cookie_name);
					var $getLine = $.cookie($cookie_line);
					$("#center").css({ fontSize: $getSize, lineHeight: $getLine });
				}

			}



			checkCookies();






	// Clear input

			clearInput = function (arg) {
				var $nam = $(arg).val();

				$(arg).focus(function() {
					if(	$(this).val() == $nam) {
						$(this).val('');
					}
				})

				$(arg).blur(function() {
					if(	$(this).val() == '') {
						$(this).val($nam);
					}
				});
			}

			clearInput("#search-form #search");



	// Carousel

			$("#carousel ul").carouFredSel({
				auto: false,
				infinite: false,
				items: 3,
				next: {
					button: ".next",
					key: "right"
				},
				prev: {
					button: ".prev",
					key: "left"
				}
			});






	// Fancy
			$("#gallery a, .fancy").fancybox({
				'cyclic'  : true,
				'titlePosition'	: 'over'
			});





	//.photo is empty

		if ($('.photo img').exists()) {
			$('.photo').css('height', '363px');
		}



	// Remove margin in last element

			$("#menu-horiz a:first").css({ borderLeft: "2px solid white" });
			$(".pagination:last").css({ display: "none" });

			if($("#gallery-index").exists()) {
				$("#gallery-index div a:last-child").css({ margin: "0" });
			}


	// Cycle plugin

		$('.slides').cycle({
			next:	'.next',
			prev:	'.previous',
			sync:	1,
			pager:	'.pagination'
		});




	// walidacja formularza

		$('.error').hide();
		$('#formularz form').bind('submit', function(){
			var valid = true;
			$('.required').click(function(){
				$(this).removeClass('error-input');
			});
			$('.required').each(function(){
				if($(this).val()==''){
					$(this).addClass('error-input');
					 valid = false;
				}else{
					$(this).removeClass('error-input');
				}
			});
			if(!valid){
				$('#error').fadeIn();
				return false;
			}
		});



	// path

		$('.doradca #path a:nth-child(2)').attr('href', 'http://www.promag.pl/Doradca,9334.html');

		//if($('.doradca #menu-vertical a:first-child').hasClass("hit") == true){
		//	$('.doradca #middle .odp:first').hide();
		//}

		//if($('.doradca #middle #formularz').length > 0){
		//	$('.doradca #middle .odp:first').hide();
		//	$('.doradca #middle .odp:eq(1)').hide();
		//}

		//if($('.doradca #middle .msg').length > 0){
		//	$('.doradca #middle .odp:first').hide();
		//	$('.doradca #middle .odp:eq(1)').hide();
		//}


});

