$(document).ready(function(){
	
	var s = $("span.email-address");
	s.html(s.html().replace(/ at /g, "@")); 
	
	/*
    $('#top-poster-wrap').cycle({
		fx: 'fade', // fade, scrollUp, shuffle
		timeout: 10000,
		delay: 10000,
		pause: 1,
	    next:   '#top-nav-offer-switch-next', 
	    prev:   '#top-nav-offer-switch-prev'
	});
    */
	$('.ebroszura-link').click(function(){
		MM_openBrWindow('http://www.webcoders.eu/media/site/ebroszura/index.html','', 1000, 700);
	});
    
    /*
	$('#form-login-dialog').dialog({
		autoOpen: false,
		width: 450,
		modal: true,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}
		}
	});
	
	$('#form-contact-dialog').dialog({
		autoOpen: false,
		width: 450,
		modal: true,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}
		}
	});
	
	/* klienci slider 
	$('#customers-logos').infiniteCarousel({
		transitionSpeed : 2000,
		displayTime : 6000,
		displayProgressBar : 0,
		displayThumbnails : 0
	});
	

	
	
	
	if(topnav == 0) {
		switchOffTopNav();
	}
*/
	

	$('#form-login-id, #form-login-password, #form-login-submit').focus(function(){
		$('#form-login-dialog').dialog('open');
		return false;
	});
		
	
	/* top-nav slider */
	$("#top-nav-switch-off").click(function () {
		switchOffTopNav();
	});
	
	$("#top-nav, #top-nav-switch-on").click(function () {
		if($("#top-nav").hasClass("off")) switchOnTopNav();
	});
	
	
	function switchOffTopNav() {
		$("#top-nav").animate({height:"33px"},400);
		$("#top-nav").toggleClass("off");
		$(".top-nav-switch a").toggleClass("active");
	}
	
	function switchOnTopNav() {
		$("#top-nav").animate({height:"133px"},400);
		$("#top-nav").toggleClass("off");
		$(".top-nav-switch a").toggleClass("active");
	}


	
	$("#form-contact-submit-btn").click(function() {

		var name = $("#form-contact-name").val();
		var phone = $("#form-contact-phone").val();
		var text = $("#form-contact-text").val();

		var action = $("#form-contact-action").val();
		var key = $("#form-contact-key").val();



		if (phone == "") {
			//$('#form-contact-dialog').dialog('open');
			$("#form-contact-phone").css('border-color', '#e1361d');
		    $("#form-contact-phone").focus();
			return false;
		} else {
			$("#form-contact-phone").css('border-color', '#393939');
		}

		if (name == "") {
			//$('#form-contact-dialog').dialog('open');
			$("#form-contact-name").css('border-color', '#e1361d');
		    $("#form-contact-name").focus();
			return false;
		} else {
			$("#form-contact-name").css('border-color', '#393939');
		}
		
		if (text == "") {
			//$('#form-contact-dialog').dialog('open');
			$("#form-contact-text").css('border-color', '#e1361d');
		    $("#form-contact-text").focus();
			return false;
		} else {
			$("#form-contact-text").css('border-color', '#393939');
		}
		
		var dataString = 'form-contact[name]='+ name + '&form-contact[phone]=' + phone + '&form-contact[text]=' + text + '&action=' + action + '&key=' + key;

		//alert (dataString);return false;

		$.ajax({
		      type: "POST",
		      url: "ajax.php",
		      data: dataString,
		      success: function() {
	        	$('#form-contact').html('<div id="message"></div>');
		        $('#message').html('<p class="success">Twoja wiadomość została wysłana. Dziękujemy!</p>')
		        .hide()
		        .fadeIn(1500);
		      }
		     });
		    return false;
	});



});

function MM_openBrWindow(theURL,winName,w,h,scrollbars) 
{ 
  LeftPosition=(screen.width)?(screen.width-w)/2:100;
  TopPosition=(screen.height)?(screen.height-h)/2:100;
  
  settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrollbars+',location=no,directories=no,status=0,menubar=no,toolbar=no,resizable=no';
  URL = theURL;
  window.open(URL,winName,settings);
}

