jQuery(document).ready(function() {

    var sprawdz = document.getElementById('fileFile');

    if(sprawdz) {

        $('#fileFile').uploadify(
        {
            'uploader' : '/public/scripts/jquery.uploadify/uploadify.swf',
            'script2' : '/ajax/index/upload/',
            'script' : '/public/scripts/jquery.uploadify/uploadify.php',
            'cancelImg' : '/public/scripts/jquery.uploadify/cancel.png',
            'folder' : '/public/admin/cv',
            'auto' : true,
            'multi' : false,
            'removeCompleted' : false,
            'hideButton' : true,
            'width' : 100,
            'height' : 160,
            'wmode' : 'transparent',
            'fileExt' : '*.jpg;*.jpeg',
            'fileDesc' : 'Pliki JPG (.jpg, .jpeg)',
            'onCancel' : function(event, ID, fileObj, data)
            {
                fileCVUsun();
            },
            'onComplete' : function(event, ID, fileObj, response, data)
            {
                //data.speed in kbs, response from php
                $('.file').replaceWith('<div id="file" class="file"><div id="fileInner"><span></span><img id="fileImg" src="/public/admin/cv/_' + response + '" alt="" /></div></div>');
                $('#fileCVName').val(response);
                $('#fileUsun').remove();
                //window.alert(response);
            }
        });

    }

    /***STOPKA***/

    if ($("body").height() > $(window).height()) {
        $('#jQ_foot').css('position', 'static');
    } else{
        $('#jQ_foot').css('position', 'fixed');
        $('#jQ_foot').css('bottom', '0px');
    }

    Cufon.replace(['.fonts'],{hover: true,fontFamily: 'Corbel'});
    Cufon.replace(['.fontsb'],{fontFamily: 'CorbelBold'});

    var ht = jQuery('#jQ_widt').height()+21;
    if(ht > 0)
        jQuery('.page_left').css('height', ht+'px');
    else
        jQuery('.page_left').css('height', '39px');

});

function fileCVUsun() {
    $('#file').replaceWith('<div id="file2" class="file">Dodaj zdjęcie</div>');
    $('#fileCVName').val('');
    $('#fileUsun').remove();
}

/***MAPA GOOGLE***/

function initialize() {
    var latlng = new google.maps.LatLng(50.02638, 21.979716);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("maps"),
            myOptions);

    var contentString =
            '<div><br /><h4>BigCom - agencja interaktywna</h4><br />'+
            'ul. Tadeusza Boya-Żeleńskiego 12,<br />' +
            '35-105 Rzeszów,<br />' +
            'telefon: +48 17 864 22 60 <br />'+
            '</div>';

    var marker = new google.maps.Marker({
      position: latlng
    });


    var infowindow = new google.maps.InfoWindow({
            content: contentString
    });

    marker.setMap(map);
    infowindow.open(map,marker);
}

/*Dodawanie inputow*/

var addElement = function(varod, vardo, varjob){
    var count = document.getElementById('licznik');
    var counter = parseInt(count.value);
    counter += 1;
    count.value = counter;
    var container = document.getElementById('box_inputy');
    var newDiv = document.createElement('div');
    newDiv.setAttribute('id','div'+counter);
    var addDiv;

    newDiv.innerHTML = '<div id="div'+counter+'" class="pole">'+
                           '<div class="napis">&nbsp;</div>'+
                           '<input onclick="maskInput(this);" onblur="if(this.value==\'\') this.value=\''+varod+'\';" onfocus="if(this.value==\''+varod+'\') this.value=\'\';" id="od'+counter+'" type="text" class="input_small" name="dosw[od]['+counter+']" value="'+varod+'" />'+
                           '<input onclick="maskInput(this);" onblur="if(this.value==\'\') this.value=\''+vardo+'\';" onfocus="if(this.value==\''+vardo+'\') this.value=\'\';" id="do2'+counter+'" type="text" class="input_small" name="dosw[do]['+counter+']" value="'+vardo+'" />'+
                           '<input onblur="if(this.value==\'\') this.value=\''+varjob+'\';" onfocus="if(this.value==\''+varjob+'\') this.value=\'\';" id="stanowisko'+counter+'" type="text" name="dosw[stanowisko]['+counter+']" value="'+varjob+'" />'+
                           '<div class="button1">'+
                                '<div class="button1_r">'+
                                    '<a class="usun_przycisk" onclick="removeElement(\'div'+counter+'\')">Usuń</a>'+
                                '</div>'+
                           '</div>'+
                       '</div>';
    container.appendChild(newDiv);
}

/*Usuwanie inputow*/

var removeElement = function(removeId){
    var count = document.getElementById('licznik');
    var counter = parseInt(count.value);
    counter -= 1;
    count.value = counter;
    var container = document.getElementById('box_inputy');
    var toRemove = document.getElementById(removeId);
    container.removeChild(toRemove);
}

var maskInput = function(id){
    $(id).mask("99-99-9999");
}

/**BANERY**/
jQuery(window).load(function() {
    var ban = document.getElementById('jQ_slider');
    if(ban){
        $('#jQ_slider').codaSlider({
           autoSlide: true,
           autoSlideInterval: 6000,
           dynamicArrows: false,
           dynamicTabs: false,
           autoSlideStopWhenClicked: true
       });
    }
});
