/*tooltip*/
	this.tip = function(){this.xOffset = 10;this.yOffset = -20;
	$(".tip").unbind().hover(function(e){this.t = this.title;this.title = '';
	this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
	$('body').append( '<p id="tip">' + this.t + '</p>' );
	$('p#tip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");},
	function() {
	this.title = this.t;
	$("p#tip").fadeOut("slow").remove();}
	).mousemove(
	function(e) {
	this.top = (e.pageY + yOffset);this.left = (e.pageX + xOffset);                     
	$("p#tip").css("top", this.top+"px").css("left", this.left+"px");});};
/*form-completer*/
	var selector = [];
	function Selector(id, value){this.id=id;this.value=value;}
/*document-ready*/
$(document).ready(function(){
/*tooltip init*/
	tip();
/*captions*/
	$('.boxgrid.captionfull').hover(function(){
	$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:260});
	}, function() {
	$(".cover", this).stop().animate({top:'260px'},{queue:false,duration:260});
	});
/*completer*/
	var elements = $('.cleared').get();
	for(var i = 0; i < elements.length; i++)
	selector[i] = new Selector($(elements[i]).attr('id'), $(elements[i]).val());
	jQuery.each(selector, function(){var s = this;
	$('#' + s.id).focus(function () {if($(this).val() == s.value)$(this).val('');
	$(this).blur(function(){if($(this).val() == '')$(this).val(s.value);});});});
	Shadowbox.init();
	$('#contactus').click(function(){$('html,body').animate({scrollTop:$("#sendquestion").offset().top},2400);});
	$('#works').click(function(){$('html,body').animate({scrollTop:$("#gallery").offset().top},2400);});
	
	$('#sendquestion').submit(function() {
		var data   = $('form').serialize();
		$.ajax({
    		url: "mail.php?mail",
    		type: "POST",
    		data: data,
    		success: function(result) {
	    		var split = result.split(/\|/);
	    		
	    			for (i=0;i<split.length;i++) {
	    				if (split[i]) {
		    				var cls = '#' + split[i];
		    				if (split[0] == 'ok') {
		    					$('.result').html("Dziękujemy, mail został wysłany!");
		    					$(cls).css("border","1px solid green");
		    				}
		    				else {
   		 						$(cls).css("border","1px solid red");	
   		 					}
   		 				}
	    			}
	    				
    		},
   			error: function(error) { $('.result').html(error); }
		});
	return false;
	});
});
