$(document).ready(function(){

	/*
	$.ajax({
                    type: "GET",
                    url: "/index.php?module=js&ajax=1&wyk=1",
                    data: {},
                    success: function(data){
                        //alert("OK");
                    },
                    error: function() {
						   //alert("blad");
                    }
                });
		*/
		
	/*
	$('img.Vote').hover(
		function () {
			var id = this.id.split('_');
			for (var a=1;a<6;a++) {
				if (a<=id[1]) $('img#V_'+a).attr('src','/tpl/images/ico_star_on.gif');
				else $('img#V_'+a).attr('src','/tpl/images/ico_star_off.gif');
			}			
		},function (i) {
		$('img.De_1').attr('src','/tpl/images/ico_star.gif');
		$('img.De_2').attr('src','/tpl/images/ico_star_h.gif');
		$('img.De_3').attr('src','/tpl/images/ico_star_off.gif');			
	});
	
	$('img.Vote').click(function() {
		var id = this.id.split('_');
		$('div#Vote').html('Loading...');
		$.ajax({
            type: "POST",
            url: "/index.php?module=vote&ajax=1",
            data: {href: location.href, vote: id[1]},
            success: function(data){

                $('div#Vote').html(data);
            },
            error: function() {
            	$('div#Vote').html('Error');
            }
        });
	});
	*/
	function ol1(text, title) {
		ol_fgcolor='#ffffff';
		ol_bgcolor='#2E74B8';
		ol_width='100%';
		if (title) { return overlib(text, CELLPAD, 1, 3, BORDER, 2); }
		else { return overlib(text); }
	}
	
	$('.overLib').hover(
			function() {
				temp=$(this).attr("title");
				$(this).attr("title","");
				return ol1(temp,'Tresc:');
			},
			function() {
				$(this).attr("title",temp);
				return nd();
			}
	);
	
	$('ul.jd_menu').jdMenu({activateDelay: 0, showDelay: 0, hideDelay: 10});
	
	$('input#pole').focus(function() { $('input#pole')[0].value = "";	});
	
	$('span#szukaj').click(function() { });	
	
	$('#button_newsletter').click(function(){
		
		$('div#newsletter_komunikat').html("Sprawdzanie poprawności adresu e-mail...")
		
		$.ajax({
                    type: "GET",
                    url: "/index.php?module=newsletter&ajax=1&mail="+$('input#mail')[0].value,
                    data: {},
                    success: function(data){
                        if (data=='ERROR') $('div#newsletter_komunikat').html('Bďż˝ďż˝d');
                        else $('div#newsletter_komunikat').html(data);
                    },
                    error: function() {
                        //$('div#ShowOrder').html('Error');
                    }
                });

		});

	
	/* Pawel */
	var i = 0;
	$('div#jAn div.Item').hide();
	$('div#jAn div.Item:first').show();
	$('div#jAn').everyTime(5000, function(i) {
		showNext(i);
	});
	$('a[name^="Item_"]').click(function() {
		var oBj = $('div#jAn div.Item');
		for (i = 0; i<oBj.length; i++) {
			if (i==this.name.split('_')[1]) $(oBj[i]).fadeIn('slow'); 
			else $(oBj[i]).hide();
			}
		$('div#jAn').stopTime();
		$('div#jAn').everyTime(5000, function(i) {
			showNext(i);
		});
	});
	
	if ($('span#Lang').html()=='pl') {
		$('.GaleriaSpis a.Img').lightBox({lang: 'pl', txtImage: 'Zdjęcie', txtOf: 'z'});
		$('.LB').lightBox({lang: 'pl', txtImage: 'Zdjęcie', txtOf: 'z'});
	}
	if ($('span#Lang').html()=='en') {
		$('.GaleriaSpis a.Img').lightBox({lang: 'en', txtImage: 'Image', txtOf: 'of'});
		$('.LB').lightBox({lang: 'en', txtImage: 'Image', txtOf: 'of'});
	}
	if ($('span#Lang').html()=='fr') {
		$('.GaleriaSpis a.Img').lightBox({lang: 'fr', txtImage: 'Photo', txtOf: 'avec'});
		$('.LB').lightBox({lang: 'fr', txtImage: 'Photo', txtOf: 'avec'});
	}
	/* EO Pawel */
});

function sendPolec(id) {
	$('div#Komunikat').html('Trwa wysy3anie...');
	$.ajax({
        type: "POST",
        url: "/index.php?module=ajaxrequest&ajax=1",
        data: {
			akcja: 'polec',
			href: location.href, 
			id: id,
			osoba: $('form[name="Polec"]')[0].osoba.value,
			email: $('form[name="Polec"]')[0].email.value
			},
        success: function(data){
        	$('div#Komunikat').html(data);
        },
        error: function() {
        	$('div.Gradient p.Comment').html('Error');
        }
    });
	return false;
}

function sendComment(id) {
	$.ajax({
        type: "POST",
        url: "/index.php?module=ajaxrequest&ajax=1",
        data: {
			akcja: 'comment',
			href: location.href, 
			id: id,
			imie: $('form[name="Comment"]')[0].imie.value,
			email: $('form[name="Comment"]')[0].email.value,
			strona: $('form[name="Comment"]')[0].strona.value,
			wiadomosc: $('form[name="Comment"]')[0].wiadomosc.value
			},
        success: function(data){
			if (data.indexOf('<!--OK-->') != -1) {
				$('form[name="Comment"]').hide();
			}
        	$('div#Komunikat').html(data);
        },
        error: function() {
        	$('div.Gradient p.Comment').html('Error');
        }
    });
	return false;
}

function polec(id) {
	var Formularz = '<div id="Komunikat"></div><form onsubmit="return sendPolec('+id+')" name="Polec" method="post">';
	Formularz += '<table class="AddComment">';
	Formularz += '<tr><td class="Left">Osoba polecająca*:</td><td><input type="text" name="osoba" class="default" /></td></tr>';
	Formularz += '<tr><td class="Left">E-mail odbiorcy*:</td><td><input type="text" name="email" class="default" /></td></tr>';
	Formularz += '<tr><td colspan="2" class="alRight"><input type="image" src="/tpl/images/bg_wyslij.gif" class="Send" /></td></tr>';
	Formularz += '<tr><td colspan="2" class="alRight">* - Pola wymagane</td></tr>';
	Formularz += '</table>';
	Formularz += '</form>';
	$('div#Polec').html(Formularz);
	$('div.Gradient p.Comment').html('');
}

function addComent(id) {
	var Formularz = '<div id="Komunikat"></div><form onsubmit="return sendComment('+id+')" name="Comment"  method="post">';
	Formularz += '<table class="AddComment">';
	Formularz += '<tr><td class="Left">Imię i nazwisko*:</td><td><input type="text" name="imie" class="default" /></td></tr>';
	Formularz += '<tr><td class="Left">E-mail*:</td><td><input type="text" name="email" class="default" /></td></tr>';
	Formularz += '<tr><td class="Left">Strona WWW:</td><td><input type="text" name="strona" class="default" /></td></tr>';
	Formularz += '<tr><td class="Left">Wiadomość</td><td><textarea name="wiadomosc"></textarea></td></tr>';
	Formularz += '<tr><td colspan="2" class="alRight"><input type="image" src="/tpl/images/bg_wyslij.gif" class="Send" /></td></tr>';
	Formularz += '<tr><td colspan="2" class="alRight">* - Pola wymagane</td></tr>';
	Formularz += '</table>';
	Formularz += '</form>';
	$('div.Gradient p.Comment').html(Formularz);
	$('div#Polec').html('');
	$('div.Comment').hide();
}

function odddaj(oBj) {
	
	var odp = -1;

	for (var a=0; a<oBj.odpowiedz.length;a++) {
		if (oBj.odpowiedz[a].checked) odp = a;
	}
	if (odp!=-1) {
	$('div#Sonda').html('Trwa liczenie głosów..');
	$.ajax({
        type: "POST",
        url: "/index.php?module=sonda&ajax=1",
        data: {sonda: oBj.sonda.value, odpowiedz: odp},
        success: function(data){
        	$('div#Sonda').html(data);
        },
        error: function() {
            //$('div#ShowOrder').html('Error');
        }
    }); }
	return false;
}

function zatrzymaj() {
	$('div#jAn').stopTime();
}
function showNext(a) { 
	var oBj = $('div#jAn div.Item');
	var z = 0;
	for (i = 0; i<oBj.length; i++) {
		if ($(oBj[i]).is(":visible")) z = i;
		$(oBj[i]).hide();
	}
	z++;
	if (z>=oBj.length) z = 0;
	$(oBj[z]).fadeIn();
}

function FontSize(size) {
	/*
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      
      p[i].style.fontSize = size+"px"
   }   
	
	var div = document.getElementsByTagName('div');
   for(i=0;i<div.length;i++) {
      if(div[i].style.fontSize) {
         var s = parseInt(div[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      
		div["n"].style.fontSize = "12px"
      div[i].style.fontSize = size+"px"
   }   
   
	var a = document.getElementsByTagName('div');
	   for(i=0;i<a.length;i++) {
	      if(a[i].style.fontSize) {
	         var s = parseInt(a[i].style.fontSize.replace("px",""));
	      } else {
	         var s = 12;
	      }
	      
			a["n"].style.fontSize = "12px"
	      a[i].style.fontSize = size+"px"
	   }   
   */
   
   createCookie('font_size', size, 100);
   //$.cookie('font_size', size, 100, '/', 'trzaskowski.dzek');
   //alert($.cookie('font_size'));
   
	$(".p").css('font-size',size+"px");
	$("p").css('font-size',size+"px");
	$(".p a").css('font-size',size+"px");
	$("p a").css('font-size',size+"px");
	$("ul.lin li a").css('font-size',size+"px");
	$("div.news").css('font-size',size+"px");

	history.go(0);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function printSite(module,akcja,row) {
	var options = "width=800,height=600,scrollbars=yes,resizable=no,menubar=yes";
	var help_url="/index.php?module="+module+"&print=1&akcja="+akcja+"&row="+row;
	var win = open(help_url, "help", options);
	win.moveTo(100,50);
	win.focus();
	}
function mailContact() {
	var daReferrer = document.referrer;
	var email = "contact@rafaltrzaskowski.pl";
	var errorMsg = "here here here is the error error error error";
	var subject = "Info";
	var body_message = "%0D%0D%0D%0DWiadomość ze strony "+daReferrer;

	var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;

	win = window.open(mailto_link,'emailWindow');
	if (win && win.open &&!win.closed) win.close();
	return false;
}
function showDate(time, rodzaj) {
	$('div#Calendar').html('<div class="Load"><img src="/tpl/images/ico_load.gif" alt="ładowanie" /></div>');
	$.ajax({
        type: "POST",
        url: "/index.php?module=ajaxrequest&ajax=1",
        data: {akcja: 'calendar', date: time, rodzaj: rodzaj},
        success: function(info){
        	$('div#Calendar').html(info);
        },
        error: function() {
        	$('div#Calendar').html('Error');
        }
    })
}






/**
 * Walidacja formularzy (bez píŠŠíż´extarea), moÂżna by3o lepiej zrobic bo textarea
 * nie moÂże miec atrybutu alt
 * 
 * @return bool - jezeli wszystko ok to true
 */
function validacja_formy(id) {
	var blad='';
	$('#'+id+' [alt=req_text]').each (function () {
		if ($(this).attr('value')=='') {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});
	$('#'+id+' [alt=req_mail]').each (function () {
		if (!isEmail($(this).attr('value'))) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});

	$('#'+id+' .req_text').each (function () {
		if ($(this).attr('value')=='') {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});
	$('#'+id+' .req_mail').each (function () {
		if (!isEmail($(this).attr('value'))) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});

	
	if (blad != '') {
		alert(blad);
		return false;
	}
	else {
		return true;
	}
}


function isEmail(email) {
	email = email.replace(/[ ]/g, '');
	var regEmail = /^([a-zA-Z0-9._-]{1,})@([a-zA-Z0-9._-]{1,})\.([a-zA-Z]{2,4})$/;
	if (!regEmail.test(email))
		return false;
	else
		return email;
}


function podmiotchange(obj) {
	if (obj.value=='Firma') {
		$('.firm_hid').show();
		$('.firm_hid input').addClass('req_text');
	}
	else {
		$('.firm_hid').hide();
		$('.firm_hid input').removeClass('req_text');
	}
}

function pokaz_UE(idek) {
	$('.unia').hide(500);
	$('#'+idek).show(500);
}








$(document).ready(function() {
	// jQuery Plugin :D
	$.fn.replace = function(o) { return this.after(o).remove(); };
	// koniec pluginu
	
	$('div.marquee').each(function() {
		$(this).replace('<marquee scrollamount="1" scrolldelay="'+$(this).attr('title')+'">'+$(this).html()+'</marquee>')
	});
	

	//$('marquee').marquee();
	 $('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);
		 }
		 });
	 
});



	 // basic version is: $('div.demo marquee').marquee() - but we're doing some sexy extras
	 


function zamien_film(id,id_yt,lang,x,y) {
	if (x==undefined || x==0 || x=='0' || x=='') {
		x=260;
	}
	if (y==undefined || y==0 || y=='0' || y=='') {
		y=200;
	}

	prepare_html='<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/'+id_yt+'&amp;hl=pl&amp;fs=1" width="'+x+'" height="'+y+'">'+
	'<param name="movie" value="http://www.youtube.com/v/'+id_yt+'&amp;hl=pl&amp;fs=1" />'+
	'<param name="wmode" value="transparent" />'+
	'<param name="allowFullScreen" value="true" />'+
	'<param name="allowscriptaccess" value="always" />'+
	'<div>';
	if (lang!='pl') {
		prepare_html=prepare_html+'To view video you need Adobe Flash Player plugin. <a href="http://get.adobe.com/flashplayer/">Click here</a> to download Flash Player.';
	}
	else {
		prepare_html=prepare_html+'Do wyświetlenia filmu potrzebujesz zainstalowanej wtyczki Adobe Flash Player. <a href="http://get.adobe.com/flashplayer/">Kliknij tutaj</a>, aby pobrać Flash Player.';
	}
	prepare_html=prepare_html+'</div></object>';
	$("#"+id).html(prepare_html);
}

