$(document).ready(function() {
	
    $('.point, .pointDesc').css('cursor', 'pointer');
    $('.point, .pointDesc').mouseover( function()
    {
        sId = $(this).attr('rel');
        $('.pointDesc[rel='+sId+']').css('text-decoration', 'underline');
    }).mouseout( function()
    {
        sId = $(this).attr('rel');
        $('.pointDesc[rel='+sId+']').css('text-decoration', 'none');
    }).click( function()
    {
        sId = $(this).attr('rel');
        $('#service').hide();
        $('#service').html( '<p>'+$('p[rel='+sId+']').html()+'</p>' ).fadeIn();
    });
  
    $('.minFoto').each(function() {
        var img = $(this).find('img');
        if(img.height < 83) {
            img.css('margin-top', (parseInt((83 - img.height())/2)+9)+'px');
        }
            
        
    });
    //TopLayer

    if($('#topLayer').hasClass('displayYes')) {
        $('#topLayer').css('top', '50px');
        $('#topLayer').css('left', ($(window).width()/2)-($('#topLayer').width()/2));
        $('#topLayer').draggable({
            handle: '#topLayerHandle'
        });
    }

    $('.techA').mouseover(function(){
      $(this).css('opacity', 0.5);
    }).mouseout(function(){
      $(this).css('opacity', 1);
    });

    $('.buttonO').mouseover(function(){
      $(this).css('opacity', 0.5);
    }).mouseout(function(){
      $(this).css('opacity', 1);
    });

    $('.techAnoImg').mouseover(function(){
      $(this).parent().parent().find('td').find('img').css('opacity', 0.5);
    }).mouseout(function(){
      $(this).parent().parent().find('td').find('img').css('opacity', 1);
    });

    $('#btnHome').mouseover(function(){
      $('.btnHome').css('background-position','bottom left');
    }).mouseout(function(){
      $('.btnHome').css('background-position','top left');
    });
    $('#btnSiteMap').mouseover(function(){
      $('.btnSiteMap').css('background-position','bottom left');
    }).mouseout(function(){
      $('.btnSiteMap').css('background-position','top left');
    });

    $('#btnKontakt').mouseover(function(){
      $('.btnKontakt').css('background-position','bottom left');
    }).mouseout(function(){
      $('.btnKontakt').css('background-position','top left');
    });

});

function switchDisplay(id){
    obj = document.getElementById(id);;
    if (obj.style.display == 'none')
        obj.style.display = 'inline';
    else
        obj.style.display = 'none';
}

function topLayerClose(){
    $('#topLayer').fadeOut();
    if($('#topLayerCheckBox:checked').length > 0)
    {
        document.cookie = 'toplayer=no; path=/';
    }
}


function newsletterSend() {
    $('#newsletterForm').submit();
}

function searchSend() {
    $('#searchForm').submit();
}

  	
function formSend()
{
    $('#formOk').hide();
    $('#formError').hide();
    name = $('input[name=name]').val();
    firma = $('input[name=firma]').val();
    mail = $('input[name=mail]').val();
    phone = $('input[name=phone]').val();
    question = $('textarea[name=question]').val();
  
    mail = validateEmail2(mail);

    if(name && mail && phone && question)
    {
        $('#contactFormSend').ajaxSubmit(function(msg) {

            if(msg.indexOf('true') != -1)
            {
                $('#formOk').show();
                $('input[name=name]').val('');
                $('input[name=mail]').val('');
                $('input[name=phone]').val('');
                $('textarea[name=question]').val('');
                $('input[name=firma]').val('');
                $('input[name=code]').val('');
                var d = new Date();
                $('#captcha').attr('src', 'lib/captcha/img.php?'+d.getTime());
            }
            else if(msg.indexOf('ERROR1') != -1) {
                $('#formError').show();
                var d = new Date();
                $('#captcha').attr('src', 'lib/captcha/img.php?'+d.getTime());
                $('input[name=code]').val('');
            }
        });
    }
    else
    {
        $('#formError').show();
        return false;
    }
}

function validateEmail2(x) {
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(x))
        return true;
    else
    {
        //alert('Wpisz poprawny adres email!');
        return false;
    }
}

// Sprawdzanie ankiet  
function pollVote(id) {  
    var type = '';
    var error = 0;
    if($('#'+id).find('input[type=radio]').length > 0)
    { 
        if($('#'+id).find('input[type=radio]:checked').length == 0)
            error = 1;
    }    
    else if($('#'+id).find('input[type=checkbox]').length > 0) 
    {
        if($('#'+id).find('input[type=checkbox]:checked').length == 0)
            error = 1;
    }
    else if($('#'+id).find('select').length > 0) {
        if($('#'+id).find('select').val() == -1)
            error = 1;
    }
    if(error)
        $('#'+id).find('p.pollError').show();
    else  
        $('#'+id).submit();
    
}


function $i() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}