$(document).ready(function(){

	$('.totop').click(function () {
		scroll(0,0);
		return false;
	});

	$('input:text, input:password, textarea').focus(function () {
		if ($(this).val()==$(this).attr('sval')) $(this).val('');
		$(this).removeClass('invalid');
		$(this).addClass('active');
		$(this).parents('p').find('.err').removeClass('err');
		$(this).parents('p').find('.msg').remove();
	});
	$('input:text, input:password, textarea').blur(function () {
		if ($(this).val()=='') $(this).val($(this).attr('sval'));
		$(this).removeClass('active');
	});

	$('.sidebar_navigation li').not('.sidebar_navigation li.sidebar_navigation_current_parent, .sidebar_navigation li.sidebar_navigation_current_default').hoverIntent(hoverIn,hoverOut,{sensitivity: 1,timeout: 100});
	
	try {
		if ($('#slideshow .slide').size() > 1) {
			$('#slideshow .slideshow').after('<a href="" id="slideshow_prev"></a><a href="" id="slideshow_next"></a>').cycle({ 
				fx:     'fade', 
				speed:  800, 
				timeout: 5000, 
				prev:  '#slideshow_prev',
				next:  '#slideshow_next',
				cleartypeNoBg: true
			});
		}
		$('#slideshow .slideshow').mouseover(function () { $(this).cycle('pause'); });
		$('#slideshow .slideshow').mouseout(function () { $(this).cycle('resume'); });
	} catch(err) {}
	
	try {
		if ($('#portfolio .slide').size() > 1) {
			$('#portfolio .portfolio').after('<a href="" id="portfolio_prev"></a><a href="" id="portfolio_next"></a>').cycle({ 
				fx:     'fade', 
				speed:  800, 
				timeout: 0, 
				prev:  '#portfolio_prev',
				next:  '#portfolio_next',
				pager: '#portfolio_navigation',
				pagerAnchorBuilder: function(idx, slide) {
					return $('#portfolio_navigation a:eq('+idx+')'); 
				},
				cleartypeNoBg: true
			});
		}
		$('#portfolio .portfolio').mouseover(function () { $(this).cycle('pause'); });
		$('#portfolio .portfolio').mouseout(function () { $(this).cycle('resume'); });
	} catch(err) {}
	
	if ( $.browser.opera ) {
		$('.sidebar_navigation ul li').hover().css('cursor', 'pointer');
	}
	if ( $.browser.msie ) {
		var i;
		for (i in document.images) {
			if (document.images[i].src) {
				var imgSrc = document.images[i].src;
				if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
					document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
				}
			}
		}
	} 	
	if ( /chrome/.test( navigator.userAgent.toLowerCase() ) ) {
	} 	
	if ( /safari/.test( navigator.userAgent.toLowerCase() ) ) {
	} 	
	
	$('.fancybox').fancybox({
		'scrolling': 'no', 
		'titleShow': false, 
		'overlayOpacity':'.6',
		'overlayColor':'#000'
	});

	$('form').each( function(){
		$(this).append(
			$('<input/>').attr({
				'name': '_jsval',
				'type': 'hidden'
			}).val( '1' )
		);
	});
	$("#contactform").validate({
		rules: {
			tresc_zapytania: {
				required: true,
				notEqual: "Treść zapytania...",
				minlength: 6
			},
			tresc_wiadomosci: {
				required: true,
				notEqual: "Treść wiadomości...",
				minlength: 6
			},
			osoba_kontaktowa: {
				required: true,
				notEqual: "Osoba kontaktowa",
				minlength: 2
			},
			telefon: {
				required: true,
				notEqual: "Telefon kontaktowy",
				minlength: 6
			}
		},
		messages: {
			tresc_zapytania: {
				required: "Wiadomość powinna mieć przynajmniej 6 znaków",
				minlength: "Wiadomość powinna mieć przynajmniej 6 znaków"
			},
			tresc_wiadomosci: {
				required: "Wiadomość powinna mieć przynajmniej 6 znaków",
				minlength: "Wiadomość powinna mieć przynajmniej 6 znaków"
			},
			osoba_kontaktowa: {
				required: "Nazwa powinna mieć przynajmniej 2 znaki",
				minlength: "Nazwa powinna mieć przynajmniej 2 znaki"
			},
			telefon: {
				required: "Numer telefonu powinien mieć przynajmniej 6 znaków",
				minlength: "Numer telefonu powinien mieć przynajmniej 6 znaków"
			}
		}
	});
});

function hoverIn(){ $(this).children('ul').animate({height: 'toggle'}, 400);}
function hoverOut(){ $(this).children('ul').animate({height: 'toggle'}, 400);}

$.validator.addMethod("notEqual", function(value, element, param) {
  return this.optional(element) || value != param;
}, "Proszę podać wartość inną niż domyślna");

$.validator.addMethod("equal", function(value, element, param) {
  return this.optional(element) || value == param;
}, "Niepoprawna wartość");

