function getFlashMovieObject(movieName){
    if (window.document[movieName])
    {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1)
    {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}

$().ready(function() {
    if($.browser.msie==false || ($.browser.msie==true && $.browser.version!='7.0')){
        $('#mainContent .filo_left h3:first').css('margin','-10px 0 0');
    }
    /*
     * PodĹ›wietlenie gĂłrnego menu
     */
    if($.browser.msie != true && $.browser.version!='6')
    {
        $('ul.belka li').hover( function(){
	
            bgPos = $(this).SIpos();
            $(this).parent().css({
                'background-repeat':'no-repeat',
                'background-image':'url("/public/img/menurollover.png")',
                'background-position': (bgPos.left+($(this).width()/2)-77)+'px 0px'
            }); 
        }, function(){
            $(this).parent().css('background','none');
        });
    }
    /*
     *Zmiana czcionki
     */
    $('#fonts #small').click(function(){
        font_resize('12');
    });
    $('#fonts #normal').click(function(){
        font_resize('13');
    });
    $('#fonts #big').click(function(){
        font_resize('14');
    });

    $('div.bBoxStart .top').css('zIndex','999991');
    $('div.bBoxStart .main').css('zIndex','999999');
    //$('#eFlasz').css('zIndex','899');
    //$('#mainVideo').css({'z-Index':'899'});

    /*
     *  Sprawdzanie wymiarĂłw okna
     */
    $.clientCoords = function(){
        if(window.innerHeight || window.innerWidth){
            return {
                w:window.innerWidth,
                h:window.innerHeight
            }
        }
        return {
            w:document.documentElement.clientWidth,
            h:document.documentElement.clientHeight
        }
    }
    
    /**
     * wysyłanie zapytania
     */
    $("#telefon_zapytanie").mask("+99 - 999 - 999 - 999");
    $('#form_zapytanie').validate({
        rules: {
            imie_zapytanie:       {
                required: true
            },
            email_zapytanie:      {
                required: true, 
                email:true
            },
            email_zapytanie2:     {
                required: true, 
                email:true, 
                equalTo: '#email_zapytanie'
            },
            telefon_zapytanie:    {
                required: true
            },
            tresc_zapytanie:      {
                required:true
            }
        },
        messages: {
            imie_zapytanie:       {
                required: "Podaj imię i nazwisko"
            },
            email_zapytanie:      {
                required: "Podaj adres e-mail", 
                email:"Podaj poprawny adres e-mail."
            },
            email_zapytanie2:     {
                required: "Podaj adres e-mail", 
                email:"Podaj poprawny adres e-mail.",
                equalTo: "Adresy e-mail muszą być zgodne"
            },
            telefon_zapytanie:    {
                required: "Podaj numer telefonu"
            },
            tresc_zapytanie:      {
                required:" Wpisz treść wiadomości"
            }
        }
    });
    /**
     * wyłączanie wklejania
     */
    $('input[name=email_zapytanie2]').bind('contextmenu', function(e){
        return false;
    });
    $('input[name=email_zapytanie2]').keydown(function(event) {
        if (event.ctrlKey==true && (event.which == '118' || event.which == '86')) {
            return false;
        }
    });
    
    var date = new Date();
    date = date.setTime(date.getTime() + (24 * 60 * 60 * 1));
    jQuery.each($('#form_zapytanie input,#form_zapytanie textarea'), function() {
        if($(this).attr('type')!='submit')
        {
            if($.cookie('form'+$(this).attr('name'))===null) {
                $.cookie('form'+$(this).attr('name'),'', {
                    path: '/',
                    expires: date
                });
                $('[name='+$(this).attr('name')+']').val('');
            }else{
                $('[name='+$(this).attr('name')+']').val($.cookie('form'+$(this).attr('name')));
            }
        }
    });
    
    $('#form_wiadomosc input,#form_wiadomosc textarea,#form_zapytanie input,#form_zapytanie textarea').keyup(function(event) {
        $('[name='+$(this).attr('name')+'][id!='+$(this).attr('id')+']').val($(this).val());
        $.cookie('form'+$(this).attr('name'),$(this).val(), {
            path: '/',
            expires: date
        });
    });
    
    /*
     * Reklama 
     */
    date = new Date();
    date.setTime(date.getTime() + (24 * 60 * 60 * 2)*1000); 
    if( $.cookie('spotR') != 'played' ) {
        $.cookie('spotR','played', {
            path: '/',
            expires: date
        });
        $('#ePageBody').addClass("hideContent");
        $('#spotR').css('zIndex','999991');
        swfobject.embedSWF("/public/player.swf", "spotR", "100%", $.clientCoords().h, "9.0.0", "expressInstall.swf", {}, {}, {});
    //$.cookie('spotR','played');
    }
    //$(document).pngFix();


    if ( current_uri == 'kontakt' && $('#errorWiadomosc').length==1 ){
        $('.bFormularz').css('display','block');
    }
    $('#form_przeslij').validate({
        rules: {
            imie_przeslij: {
                required: true
            },
            email_przeslij:{
                required: true, 
                email:true
            }
        },
        messages: {
            imie_przeslij: {
                required: " %{$_|lang:'_PODAJ'}% %{$_|lang:'_IMIE'}% "
            },
            email_przeslij: {
                required: " %{$_|lang:'_PODAJ_EMAIL'}%", 
                email:"%{$_|lang:'_PODAJ_POPRAWNY_EMAIL'}%"
            }
        }
    });

    var flashvars = {
        datatype: "xml",
        dirurl: "",
        headerText: "APLIKACJE DEDYKOWANE",
        normalText: "Automatyzujemy procesy biznesowe, usĹ‚ugowe i handlowe. Tworzymy serwisy oparte o samoczynnÄ… realizacjÄ™ procesĂłw...",
        iconFile: "/public/img/aplikacje_dedykowane_header.gif",
        addressLink: "/uslugi/aplikacje_dedykowane.html"
    };

    var params = {
        menu: "false",
        wmode: "transparent"
    };
    var attributes = {
        id: "headerVideo",
        name: "headerVideo",
        wmode: "transparent"
    };

    swfobject.embedSWF("/public/swf/header.swf", "flasz", "900", "135", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
    if($('#mainContent.case_studiesZasob_wiedzy').length==1)
    {
        $('#mainContent.case_studiesZasob_wiedzy li').children(':not(strong)').css({
            'display':'none'
        });
        $('#mainContent.case_studiesZasob_wiedzy li strong').css({
            'cursor':'pointer'
        });
        $('#mainContent.case_studiesZasob_wiedzy li strong').click(function(){
            $(this).parent().children(':not(strong)').slideToggle('100', function() {
                });
        });
    }
});
function zwin(){
    if($('#kontaktForm').css('display')=='none'){
        $('#kontaktForm').slideDown('slow');
        $("body").animate({
            scrollTop: 600
        }, "slow");

    }else{
        $('#kontaktForm').slideUp('slow');
        $("body").animate({
            scrollTop: 0
        }, "slow");
    }
}
function loadMaps() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        var MapTypes = map.getMapTypes();
        MapTypes[0].getName= function() {
            return "Mapa";
        }
        MapTypes[1].getName = function() {
            return "Satelitarna";
        }
        MapTypes[2].getName = function() {
            return "Hybrydowa";
        }
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(53.435196, 14.540546), 14);
        var info='';
        var point = new GLatLng(53.435196, 14.540546);
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
            });
        map.addOverlay(marker);
    }
}


function send(){

    $('#wyslij').attr('disabled',true);
    $('#form_wiadomosc').ajaxSubmit(function(s){
        s = s.split('|');
        s = s['1'];
        m = s['0'];
        if(!$('#humanMsg').css('display'))
            humanMsg.setup();
        humanMsg.displayMsg(s+'<a href="javascript:void(null);" id="msg_dalej">powrót</a>');
        $('#msg_dalej').click(humanMsg.removeMsg);
        $('#wyslij').attr('disabled',false);
        if(m=='OK') {
            if( $('#wyslij_zapytanie').length==1 )
            {
                zwin();
            }
            $('#form_wiadomosc').ajaxSuccess(function(s){
                $('#imie').attr('value','');
                $('#email').attr('value','');
                $('#tresc').attr('value','');
                $('#telefon').attr('value','');

            });
        }
    });
    return false;

}


function sendEmail(){

    $('#wyslij_zapytanie').attr('disabled',true);
    $('#form_zapytanie').ajaxSubmit(function(s){
        s = s.split('|');
        s = s['1'];
        m = s['0'];
        if(!$('#humanMsg').css('display'))
            humanMsg.setup();
        humanMsg.displayMsg(s+'<a href="javascript:void(null)" id="msg_dalej">powrót</a>');
        $('#msg_dalej').click(humanMsg.removeMsg);
        $('#wyslij').attr('disabled',false);
    });
    return false;

}


function sendEmailWiadomosc(){

    $('#wyslij_zapytanie').attr('disabled',true);
    $('#form_wiadomosc').ajaxSubmit(function(s){
        if(!$('#humanMsg').css('display'))
            humanMsg.setup();
        humanMsg.displayMsg(s+'<a href="javascript:void(null)" id="msg_dalej">powrót</a>');
        $('#msg_dalej').click(humanMsg.removeMsg);
        $('#wyslij').attr('disabled',false);
    });

    $('#form_wiadomosc').ajaxSuccess(function(s){
        $('#imie').attr('value','');
        $('#email').attr('value','');
        $('#tresc').attr('value','');
        $('#telefon').attr('value','');


    });
    return false;

}


function rozwinzapytanie(){

    if($('#wyslij_zapytanie').css('display') == 'none'){

        if($('#wyslij_strone').css('display') != 'none')
        {
            $('#wyslij_strone').slideUp(500);
        }

        $('#wyslij_zapytanie').slideDown(500);
        $('#eContent').animate({
            backgroundPosition:'50% 100px'
        },250, function() {
            $('#eContent').animate({
                backgroundPosition:'50% 200px'
            }, 250)
        });

    }else{
        $('#wyslij_zapytanie').slideUp(500);
        $('#eContent').animate({
            backgroundPosition:'50% 100px'
        },250, function() {
            $('#eContent').animate({
                backgroundPosition:'50% 0px'
            }, 250)
        });
    }
}

function rozwinprzeslanie(){

    if($('#wyslij_strone').css('display') == 'none')
    {
        if($('#wyslij_zapytanie').css('display') != 'none')
        {
            $('#wyslij_zapytanie').slideUp(500);
        }

        $('#wyslij_strone').slideDown(500);
        $('#eContent').animate({
            backgroundPosition:'50% 100px'
        },250, function() {
            $('#eContent').animate({
                backgroundPosition:'50% 200px'
            }, 250)
        });

    }
    else
    {
        $('#wyslij_strone').slideUp(500);
        $('#eContent').animate({
            backgroundPosition:'50% 100px'
        },250, function() {
            $('#eContent').animate({
                backgroundPosition:'50% 0px'
            }, 250)
        });
    }

}

function check(name,name_2){

    var copy = $('#'+name).val();

    if(!copy){
        $('#'+name_2).css('background-position','0px -14px');
        $('#'+name).val("1");
    }else{
        $('#'+name_2).css('background-position','0px 0px');
        $('#'+name).val("");
    }
}

function loadAnchor(element)
{
    $('.left_menu .page a').removeAttr('class');
    $("#"+element+"").attr('class','active');


}


function load(element,adres,el_doc){

    $.ajax({
        method: 'get',
        url: adres,
        success: function(s) {
            $(el_doc).html(s);
            $('.left_menu .page a').removeAttr('class');
            $("#"+element+"").attr('class','active');
        }

    });
    return false;
}

function sendPage(){

    $('#wyslij_strone').attr('disabled',true);

    $('#form_przeslij').ajaxSubmit(function(s){
        s = s.split('|');
        s = s['1'];
        m = s['0'];
        if(!$('#humanMsg').css('display'))
            humanMsg.setup();
        humanMsg.displayMsg(s+'<a href="javascript:void(null)" id="msg_dalej">powrót</a>');

        $('#msg_dalej').click(humanMsg.removeMsg);
        $('#wyslij').attr('disabled',false);
    });

    $('#form_przeslij').ajaxSuccess(function(s){
        $('#imie_przeslij').attr('value','');
        $('#email_przeslij').attr('value','');
        $('#tresc_przeslij').attr('value','');
    });

    return false;

}
/* powiekszanie */
function font_resize(size){
    if(size){
        $('div.content_center .submenu li').css('font-size',''+size+'px');
        $('#mainContent').css('font-size',''+size+'px');
    }
    return false;
}

function printFromAS(content) {
    console.log("Content from FlashMovie: " + content);
}

function closeVideoAd () {
    $('#ePageBody').removeClass("hideContent");
    $('#spotR').slideUp(1500, function () {
        $('#spotR').remove();
    /*
        if($('#mainVideo').length=='1')
        {
            var flashMovie=getFlashMovieObject("mainVideo");
            flashMovie.startFP(1);
            
        }
        */
    });
//getFlashMovieObject("mainVideo").stopFP(1);
    
}

function spotR() {
    
}

