function blurAnchors(){
if(document.getElementsByTagName) {
var a = document.getElementsByTagName("a");
for(var i = 0; i < a.length; i++){
a[i].onfocus = function(){this.blur();};
}
}
}

window.onload = blurAnchors;

$(document).ready(function(){

	//przycisk wyszukiwania
	$('form#searchform a').click(function() { document.getElementById('searchform').submit(); })

	
	$("a.bigmenu").click(function(e) {
		e.preventDefault();
	});	
	
	$("ul.bm").prev('a').click(function(e) {
		e.preventDefault();
	});	
	
	// newsticker
	$('div#newsticker marquee').marquee('pointer').mouseover(function () {
	  $(this).trigger('stop');
	}).mouseout(function () {
	  $(this).trigger('start');
	}).mousemove(function (event) {
	  if ($(this).data('drag') == true) {
	    this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
	  }
	}).mousedown(function (event) {
	  $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
	  $(this).data('drag', false);
	});
	
	$(window).bind('resize', function() {
		$('div#newsticker > div').css('width',$(window).width());
		$('div#newsticker > div > div').css('padding-left',$(window).width());
		$('div#newsticker > div > div').css('padding-right',$(window).width());		
	});
	
	// walidacja formularza notki w blogu	
	var validator = $("#bform").validate({
	rules: {
		'cm-imie'  : "required",
		'cm-email' : { required: true, email: true },
		'cm-comment': "required"
	},
	messages: {
		'cm-imie'  : "Proszę wpisać imię",
		'cm-email'  : "Proszę podać prawidłowy adres e-mail",
		'cm-comment': "Proszę wpisać tre¶ć komentarza"
	},

	errorPlacement: function(error, element) {
		if ( element.is(":radio") )
			error.appendTo( element.parent().next().next() );
		else if ( element.is(":checkbox") )
			error.appendTo ( element.next() );
		else
			error.appendTo( element.parent().next() );
	}
	
	});	
	
	$('#top1').cycle({
		delay: 1000,
		speed: 3000,
		sync: 1
	});
	
	$(function() {
		$('#top2 a, .galler a, a.lightbox').lightBox({
			txtImage: '',
			txtOf: ' / '		
		});
	});
	
	jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback); 
	};	
	
//	$("#contactform div.sfield input").click(function(){
//		$("#contactform div.sfield").next().slideUp();
//		$(this).parent().next().slideFadeToggle("slow");
//	}).parent().next().hide();
	
	// walidacja formularza zapytania	
	var validator1pl = $("#form1pl").validate({
	rules: {
		'imienazwisko'  : "required",
		'email' : { required: true, email: true }
	},
	messages: {
		'imienazwisko'  : "Прошу ввести Ваше имя и фамилию",
		'email'  : "Прошу указать Ваш правильный Е-mail"
	},

	errorPlacement: function(error, element) {
		if ( element.is(":radio") )
			error.appendTo( element.parent().next().next() );
		else if ( element.is(":checkbox") )
			error.appendTo ( element.next() );
		else
			error.appendTo( element.parent() );
	}
	
	});
	

	
	// walidacja formularza poleć znajomemu	
	var validator3 = $("#polecznajomemu").validate({
	rules: {
		'timie'  : "required",
		'temail'  : { required: true, email: true },		
		'zimie'  : "required",		
		'zemail'  : { required: true, email: true }
	},
	messages: {
		'timie'  : "Прошу указать Ваше имя",
		'zimie'  : "Прошу указать имя знакомого",		
		'temail'  : "Прошу указать Ваш E-mail",		
		'zemail'  : "Прошу указать E-mail знакомого"		
	},

	errorPlacement: function(error, element) {
		if ( element.is(":radio") )
			error.appendTo( element.parent().next().next() );
		else if ( element.is(":checkbox") )
			error.appendTo ( element.next() );
		else
			error.appendTo( element.parent() );
	}
	
	});		
	
	// walidacja formularza pro¶by o przesłanie próbki	
	var validator_probka = $("#form2pl").validate({
	rules: {
		'imienazwisko'  : "required",
		'zip'  : "required",		
		'miasto'  : "required",		
		'adres'  : "required",				
		'telefon'  : "required",						
		'email' : { required: true, email: true }
	},
	messages: {
		'imienazwisko'  : "Proszę wpisać imię i nazwisko",
		'zip'  : "Proszę wpisać kod pocztowy",		
		'miasto'  : "Proszę wpisać miasto",		
		'adres'  : "Proszę podać adres",				
		'telefon'  : "Proszę podać numer telefonu",						
		'email'  : "Proszę podać prawidłowy adres e-mail"
	},

	errorPlacement: function(error, element) {
		if ( element.is(":radio") )
			error.appendTo( element.parent().next().next() );
		else if ( element.is(":checkbox") )
			error.appendTo ( element.next() );
		else
			error.appendTo( element.parent() );
	}
	
	});
	
	// obsługa tabeli ZEBRA
	$('table.zebra tr:odd td:first-child').addClass('zebrafirst');
	$('table.zebra tr:even td:first-child').addClass('zebrasecond');	

	$("div#partners a").hover(function() {   
		curr = $(this).find("img").attr("src");   
		overlen = curr.length;   
		over = curr.substr(0, overlen-4);   
		over = over+'h.png';   
		
		$(this).find("img").attr({ src: over});  
	},function() {   
		$(this).find("img").attr({ src: curr});  
	});
	
	$("div#partners a").find("img").each(function(i) {   
		temp = this.src;   
		prelen = temp.length;   
		pre = temp.substr(0, prelen-5);   
		pre = pre+'.png';   
		preload_image_object = new Image();   
		preload_image_object.src = pre;
	});	
	
	$('#sl1').cycle({ 
	    fx:     'fade', 
	    speed:   1500, 
	    timeout: 5000, 
	    pause:   1 
	});	
	
	$('#sl2').cycle({ 
	    fx:     'fade', 
	    speed:   1500, 
	    timeout: 5000, 
	    pause:   1 
	});	
	
	$('#sl3').cycle({ 
	    fx:     'fade', 
	    speed:   1500, 
	    timeout: 7000, 
	    pause:   1 
	});	
	
	$('#sl4').cycle({ 
	    fx:     'fade', 
	    speed:   1500, 
	    timeout: 5000, 
	    pause:   1 
	});		
	
	$("ul.bm").mouseover(function(e) {
		$("div.subcontainer > div").hide();		
		$("div.subcontainer > div.starter").show();	
	});		
	
	$("ul.bm li > ol > li a").mouseover(function(e) {
		e.stopPropagation();
		$("div.subcontainer > div").hide();		
		var targetID = $(this).attr('rel');
		$("#"+targetID).show();
	});
	
	$("div.subcontainer ol").mouseover(function(e) {
		e.stopPropagation();
	});	

	$("div.subcontainer").mouseover(function(e) {
		e.stopPropagation();
	});	
	
	
		launchWindow('#poppek');

	$('.window #close').click(function () {
		$('#mask').fadeOut("fast");
		$('.window').fadeOut("fast");
	});		
	
	$('#mask').click(function () {
		$(this).fadeOut("fast");
		$('.window').fadeOut("fast");
	});	
	
});

// obsługa mapy "gdzie kupić"
function showdatafrommap(id) {
		
	$(document).ready(function(){			
		$("#gdzie-lista").html	('');	  			
      $('#gdzie-lista').addClass('loader');	
		
		$.post("/parser/gdzie-kupic.php", { id: id },
		  function(data){
			 $("#gdzie-lista").hide().html(data).fadeIn("slow");
			 
				$(function() {
					$('#gdzie-lista a.lightbox').lightBox({
						txtImage: '',
						txtOf: ' / '		
					});
				});
		  });		

	});	
	
}	

	function launchWindow(id) {
	
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		$('#mask').css('opacity', 0.2);
		$('#mask').fadeIn("slow");
	
		var winH = $(window).height();
		var winW = $(window).width();
              
    $(id).css("position","absolute");
    $(id).css("top", ( $(window).height() - $(id).height() ) / 2+$(window).scrollTop() + "px");
    $(id).css("left", ( $(window).width() - $(id).width() ) / 2+$(window).scrollLeft() + "px");

		$(id).fadeIn(2000);

}

function addfavorites() {
	title = "MEBLIK.ru";
	url = "http://www.meblik.ru/";

	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) {
		window.external.AddFavorite(url, title);
	}
}
