var validMail=/^[a-zA-Z0-9._-]+\@([a-zA-Z0-9_-]+\.){1,}[\w]{1,5}$/;
var validPass=/^[a-zA-Z0-9]+$/;

$(document).ready(function(){


	$(".zwin").mouseover(function(){
		$("div#categories").slideUp('fast',function(){
			$("a#sklep").css('background-position','0 0');
		});
	});

	$("a#sklep").mouseover(function(){
		$("a#sklep").css('background-position','0 -72px');
		$("div#categories").slideDown('fast');
	});

	$("a#sklepl2").click(function(){
		$("a#sklep").css('background-position','0 -72px');
		$("div#categories").slideDown('fast');
	});

	$("div#categories").mouseout(function(){
		// wg pozycji x y mouse
		/*$("div#categories").slideUp('fast',function(){
			$("a#sklep").css('background-position','0 0');
			ws = 0;
		});
		*/
	});

	$("div#categories").mouseover(function(){
		$("a#sklep").css('background-position','0 -72px');
	});


	$("#validemail").click(function(){
		adres = document.getElementById('email').value;
		if(adres.search(validMail) == -1)
		{
			alert("Podaj poprawny adres e-mail");
			return false;
		}
		return true;
	});
	$("#validq").click(function(){
		tmp = document.getElementById('q').value;
		if(!tmp || tmp=="wpisz czego szukasz")
		{
			alert("Wpisz czego szukasz");
			return false;
		}
		return true;
	});



	$("#btn_koszyk").click(function(){
		//$("a#sklep").src('background-position','0 -72px');

		if(document.getElementById('koszyk_content').style.display == 'none')
		{
			document.getElementById('btn_koszyk').src = '/images/basket_up.png';
			$("div#koszyk_content").slideDown('fast');
		}
		else
		{
			document.getElementById('btn_koszyk').src = '/images/basket.png';
			$("div#koszyk_content").slideUp('fast');
		}	
	});

	document.getElementById('koszyk_content').innerHTML = '<img src="/images/ajax-loader.gif" style="vertical-align:middle"> Ładowanie koszyka...';
	$.get("/koszyk.html",function(data){
		document.getElementById('koszyk_content').innerHTML = data;
	});
	$.get("/koszyk.html?action=stan",function(data){
		$("div#stan").fadeOut('fast',function(){
			document.getElementById('stan').innerHTML = data;
			$("div#stan").fadeIn('fast',function(){});
		});
		
	});



	$("#mnu1 img.a").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, "slow");
			$("#mnu1 img.b").stop().animate({"opacity": "1"}, "slow");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "slow");
			$("#mnu1 img.b").stop().animate({"opacity": "0"}, "slow");
	});
	$("#mnu2 img.a").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, "slow");
			$("#mnu2 img.b").stop().animate({"opacity": "1"}, "slow");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "slow");
			$("#mnu2 img.b").stop().animate({"opacity": "0"}, "slow");
	});
	$("#mnu3 img.a").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, "slow");
			$("#mnu3 img.b").stop().animate({"opacity": "1"}, "slow");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "slow");
			$("#mnu3 img.b").stop().animate({"opacity": "0"}, "slow");
	});
	$("#mnu4 img.a").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, "slow");
			$("#mnu4 img.b").stop().animate({"opacity": "1"}, "slow");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "slow");
			$("#mnu4 img.b").stop().animate({"opacity": "0"}, "slow");
	});
	$("#mnu5 img.a").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, "slow");
			$("#mnu5 img.b").stop().animate({"opacity": "1"}, "slow");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "slow");
			$("#mnu5 img.b").stop().animate({"opacity": "0"}, "slow");
	});	
	$("#mnu7 img.a").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, "slow");
			$("#mnu7 img.b").stop().animate({"opacity": "1"}, "slow");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "slow");
			$("#mnu7 img.b").stop().animate({"opacity": "0"}, "slow");
	});		
	$("#mnu8 img.a").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, "slow");
			$("#mnu8 img.b").stop().animate({"opacity": "1"}, "slow");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "slow");
			$("#mnu8 img.b").stop().animate({"opacity": "0"}, "slow");
	});		
	$("#mnu1 img.b").stop().animate({"opacity": "0"}, "fast");
	$("#mnu2 img.b").stop().animate({"opacity": "0"}, "fast");
	$("#mnu3 img.b").stop().animate({"opacity": "0"}, "fast");
	$("#mnu4 img.b").stop().animate({"opacity": "0"}, "fast");
	$("#mnu5 img.b").stop().animate({"opacity": "0"}, "fast");
	$("#mnu7 img.b").stop().animate({"opacity": "0"}, "fast");
	$("#mnu8 img.b").stop().animate({"opacity": "0"}, "fast");	

	if(document.getElementById('mycarousel')!=undefined) 
	{
		$("#mycarousel").jcarousel({
			scroll: 1
		});  
	}
	
	 $('img.image1').data('ad-desc', '');
    $('img.image1').data('ad-title', '');
    $('img.image4').data('ad-desc', '');
    $('img.image5').data('ad-desc', '');
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function() {
        galleries[0].settings.effect = $(this).val();
        return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
       galleries[0].slideshow.toggle();
        return false;
      }
    );
		
		function LightboxDelegate(url,caption) {
    Shadowbox.open({
        language:   "pl",
        player:  	'img',
        content:    url,
        title:      caption,
        handleOversize: "resize",
        viewportPadding : "10"
    });
}   
Shadowbox.init({
    language:   "pl",
    players:    ["swf","img"],
    handleOversize: "resize",
    viewportPadding : "10"
});	

});



function getMousePos(e) { //you need the 'e', although it does NOT need to be defined
    //NS
    if (document.layers || document.getElementById && !document.all) {
        o = (window.innerWidth - 955) / 2;
        hide_preview(e.pageX - o, e.pageY)
        //document.getElementById("test").innerHTML=(e.pageX-o)+" "+(e.pageY)

    }
    //IE
    else if (document.body && document.all) {
		o = (document.body.clientWidth - 955) / 2;
        hide_preview(window.event.clientX - o, window.event.clientY)
        //document.getElementById("test").innerHTML=(window.event.clientX-o)+" "+(window.event.clientY)
    }

}

if (!window.captureEvents) document.onmousemove = getMousePos
if (window.captureEvents) {
    window.captureEvents(Event.MOUSEMOVE)
    window.onmousemove = getMousePos //e should not be defined
}



function hide_preview(x, y) {
    if ((x < -10 || x > 750) || (y < 50 || y > 390)) {
		$("div#categories").slideUp('fast',function(){
			$("a#sklep").css('background-position','0 0');
		});
    }
}

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");

    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}



function loadNewsComsForm()
{
	$.get("/news-coms-form.html?news_id="+news_id, function(data) {
		document.getElementById('comments_form').innerHTML = data;
		$('textarea#comment').autoResize({
			// On resize:
			/*
			onResize : function() {
				$(this).css({opacity:0.8});
			},
			// After resize:
			animateCallback : function() {
				$(this).css({opacity:1});
			},*/
			// Quite slow animation:
			animateDuration : 300,
			// More extra space:
			extraSpace : 16
		});
	});
}
var news_com_count = 1;
function addNewsCom()
{
	var msg = '';
	if(document.add_com_form.content.value=="") msg += "- Podaj treść komentarza\n";
	if(document.add_com_form.nick.value=="") msg += "- Podaj swój nick\n";

	if(msg)
	{
		alert("Błędne dane:\n"+msg);
		return false;
	}

	$.post("/news-coms-form.html",
		{
			news_id: news_id,
			nick: document.add_com_form.nick.value,
			user_id: document.add_com_form.user_id.value,
			content: document.add_com_form.content.value
		}, function(data) {

		coms_count++;
		document.getElementById('div_coms_count').innerHTML = coms_count;

		document.getElementById('news_com'+news_com_count).style.display = 'none';
		document.getElementById('news_com'+news_com_count).innerHTML = data;
		$('#news_com'+news_com_count).slideDown('slow',function(){});

		document.getElementById('news_com_msg').innerHTML = 'Dodano!';

		news_com_count++;
		if(document.add_com_form.user_id.value==0) document.add_com_form.nick.value = '';
		document.add_com_form.content.value = '';
	});

	return false;
}
function validRegForm()
{
	f = document.forms.myform;
	msg = '';
	if(f.username.value.search(validMail) == -1)
	{
		msg += "- Podaj poprawny login (e-mail)\n";
	}
	if(f.password.value.search(validPass) == -1)
	{
		msg += "- Hasło musi składać sie z liter lub cyfr\n";
	}
	else
	if(f.password.value.length<5 || f.password.value.length>12)
	{
		msg += "- Hasło musi mieć od 5 do 12 znaków\n";
	}
	else
	if(f.password.value != f.password2.value)
	{
		msg += "- Powtórz poprawnie hasło\n";
	}
	if(f.imie.value == "")
	{
		msg += "- Podaj imię\n";
	}
	if(f.nazwisko.value == "")
	{
		msg += "- Podaj nazwisko\n";
	}
	if(f.tel_kom.value == "")
	{
		msg += "- Podaj tel. komórkowy\n";
	}
	if(f.ulica.value == "")
	{
		msg += "- Podaj nazwę ulicy\n";
	}
	if(f.nr_domu.value == "")
	{
		msg += "- Podaj nr domu/lokalu\n";
	}
	if(f.kod_pocz.value == "")
	{
		msg += "- Podaj kod pocztowy\n";
	}
	if(f.poczta.value == "")
	{
		msg += "- Podaj pocztę/miejscowość\n";
	}
	if(f.accept.checked == false)
	{
		msg += "- Prosimy o zgodę na przetwarzanie danych osobowych\n";
	}
	if(f.accept2.checked == false)
	{
		msg += "- Prosimy o zgodę na przetwarzanie danych osobowych w celach marketingowych\n";
	}
	if(f.human.value == "")
	{
		msg += "- Podaj wynik - ANTY-SPAM\n";
	}

	if(msg)
	{
		alert("Popraw dane:\n"+msg);
		return false;
	}
	return true;
}

