$(document).ready(function(){

	
	// ramka w okól obrazka z podsisem z alta
	$('#content img').each(function() {
	    $(this).wrap('<div class="caption" style="' + $(this).attr('style') + '"></div>').after('<div class="imgcaptiontext">' + $(this).attr('alt') + '</div>');
	   
	});
	
	
	// link na gore strony
	$('a[href=#top]').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	

	

	// madanie id naglowka h4 w content-text
	var index = 1;
	$('#content-text h4').each(function() {
	    $(this).attr("id", index);
	    index++;	   
	});


	$('#content-text .imagetiem a').lightBox();


	jQuery.validator.addMethod("notEqual", function(value, element, param) {
		return this.optional(element) || value != param;
	}, "Please specify a different (non-default) value");

 	
 	
 	$("#contactForm").validate({
   		
   		submitHandler: function(form) {
     
	      	
	      	var dataString = $("form#contactForm").serialize();
			//alert (dataString);return false;
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {
	 		 // search for selectors you want to add hover behavior to
			
			} else {
				
				$(".contaktFormToggle").html("<div id=\"messagesend\"><img src=\"layouts/images/ajax-loader.gif\" alt=\"Postęp\" /><br /><p>Trwa wysyłanie.</p></div>");
			}
					
			$("#messagesend")
				.fadeIn(1500, function() {
					$("#messagesend");
				});
			
			$.ajax({
	      		type: "POST",
	      		url: "_wyslij.php",
	      		data: dataString,
	      		success: function() {
					$(".contaktFormToggle").html("<div id=\"message\"></div>");
					$("#message").html("<h3>Wiadomość została wysłana.</h3>")
					.append("<p>Wkrótce otrzymasz odpowiedz.</p>")
					.hide()
					.fadeIn(1500, function() {
					$("#message");
					});
				}
     		});
      
   			form.submit();
   		},	
   		
   		rules: {
			name: { notEqual: "Nazwa firmy / Imię Nazwisko" },
			email: { notEqual: "E-mail / Telefon" },
			ftext: { notEqual: "Twoja wiadomość" }
		}

   		
   		
	});
 	
 	
 	$(".contaktForm input#fname").focusout(function() {
		if ( $(this).val() == "") { $(this).val('Nazwa firmy / Imię Nazwisko'); $(this).css('color', '#CAD2D4'); }
		
	});
	
	$(".contaktForm input#femail").focusout(function() {
		if ( $(this).val() == "") { $(this).val('E-mail / Telefon'); $(this).css('color', '#CAD2D4'); }
	});

	$(".contaktForm textarea#ftext").focusout(function() {
		if ( $(this).val() == "") { $(this).val('Twoja wiadomość'); $(this).css('color', '#CAD2D4'); }
	});

 	

//	Cufon.replace('#content-text h1,  #content-text h2, #content-text h3, #content-text h4', {
//		textShadow: '#ffffff 1px 1px'
//	});

	
	Cufon.replace('.headerImgIn h1, #content-text h1, #content-text h2, #sitebar h4, #sitebar h5, #footerTwoBars h3', {
		textShadow: '#fff 1px 1px'
	});


	$(".contaktForm input#fname").click(function(){
		if ( $(this).val() == "Nazwa firmy / Imię Nazwisko") { $(this).val(''); }
		$(this).css('color', '#535454');
	});
	
	$(".contaktForm input#femail").click(function(){
		if ( $(this).val() == "E-mail / Telefon") { $(this).val(''); }
		$(this).css('color', '#535454');
	});
	
	$(".contaktForm textarea#ftext").click(function(){
		if ( $(this).val() == "Twoja wiadomość") { $(this).val(''); }
		$(this).css('color', '#535454');
	});
	
	
		
	
	$('#newClientForm').validate({
  	
	});
	
	$('#plik').uploadify({
    'uploader' : '/uploadify/uploadify.swf',
    'script' : '/uploadify/uploadify.php',
    'cancelImg' : '/uploadify/cancel.png',
    'folder' : '/uploads',
	'removeCompleted' : false,
	'multi' : true,
	'auto' : true,
	'buttonText' : 'Dodaj plik/pliki',
	'fileExt' : '*.jpg;*.gif;*.png;*.zip;*.rar;*.7z;*.doc;*.docx;*.jpeg;*.txt;*.pdf',
	'fileDesc' : 'Tylko pliki (.JPG, .JPEG, .GIF, .PNG, .ZIP, .RAR, .7ZIP, .DOC, .DOCX, .TXT, >PDF)',
	'sizeLimit' : 65011712,
    'displayData' : 'speed',
    'onSelect' : function(event, queueID, fileObj){
      		if (fileObj.size > 65011712) {
        		alert('Plik ' + fileObj.name + ' jest za duży (max 55MB).')
        	return false;
      		}
    	},
    'onComplete' : function(event, queueID, fileObj, response, data) { 
			
			// dodanie do tablicy nazwy pliku
			var pliki = $('#plikiLista').val();
			
			if (pliki == "") {
				$('#plikiLista').val(Date.today().toString("yyyy.MM.dd-") + fileObj.name);
			} else {
				$('#plikiLista').val(pliki + '::' + Date.today().toString("yyyy.MM.dd-") + fileObj.name);
			}	
			
			},	
    	
    'onAllComplete' : function(event,data) {
			$('#submit').removeClass('submitOff');	
			$('#submit').removeAttr("disabled");
    	},	
    'onCancel' 	: function(event,ID,fileObj,data) {
			if (data.fileCount < 1) {
			$('#submit').removeClass('submitOff');
			$('#submit').removeAttr("disabled");
			
			// usuniece z tablicy nazwy pliku
			
			}
		},		
    'onOpen'      : function(event,ID,fileObj) {
			$('#submit').attr('disabled', 'disabled');
			$('#submit').addClass("submitOff");
    	},		
	});

	
	/*
	
	$("#newClientForm").validate({
   		
   		submitHandler: function(form) {
     
	      	
	      	var dataString = $("form#newClientForm").serialize();
			//alert (dataString);return false;
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {
	 		 // search for selectors you want to add hover behavior to
			
			} else {
				
				$(".contaktFormToggle").html("<div id=\"messagesend\"><img src=\"layouts/images/ajax-loader.gif\" alt=\"Postęp\" /><br /><p>Trwa wysyłanie.</p></div>");
			}
					
			$("#messagesend")
				.fadeIn(1500, function() {
					$("#messagesend");
				});
			
			$.ajax({
	      		type: "POST",
	      		url: "_new-client.php",
	      		data: dataString,
	      		success: function() {
					$("#bb").html("<div id=\"message\"></div>");
					$("#message").html("<h3>Wiadomość została wysłana.</h3>")
					.append("<p>Wkrótce otrzymasz odpowiedz.</p>")
					.hide()
					.fadeIn(1500, function() {
					$("#message");
					});
				}
     		});
      
   			form.submit();
   		},	
   			
	});
	
	
	*/
	


});


