
$(document).ready( function(){
    $("a.gallery").fancybox({
                'titlePosition'    : 'over'
            });

$(function() {
        $("#sort").sortable({
            update : function(event,ui){
               
                $.post('http://rewest-service.pl/admin/sortsites',{"order":$(this).sortable('toArray')});
            },
            'axis' : 'x'
        });
        $("#sort").disableSelection();
    });       
    var promo = new ImageFlow();
    promo.init({
        ImageFlowID: 'promoGallery',
        reflections: false,
        opacity: true,
        reflectionP: 0.4,
        slider: true,
        slideshowAutoplay: true,
        slideshow:true,
        aspectRatio: 3.0,
        buttons: true,
        imageFocusM: 1.0,
        opacityArray: [10,5,0.8,0],
        animationSpeed:40,
        circular: true,
        slideshowSpeed:4000
    });
    $('#dialog').dialog({ autoOpen: false,modal: true,buttons: {
                        'Zamknij': function() {
                            $(this).dialog('close');
                        }
                    },width:400
    });
    if($('#dialog').html()) {
        $('#dialog').dialog('open');
    }
    $("#addproductForm").dialog({
            autoOpen: false,
            height: 440,
            width: 680,
            modal: true
    });
    $("#delconfirm").dialog({
            autoOpen: false,
            height: 140,
            width: 350,
            modal: true
    });
    $('#addproduct').button().click(function() {
                $('#addproductForm').dialog('open');
    });
    $('.buttonS').button();
    $('#delbutton').click(function(){
            $('#delconfirm').dialog('open');
    });
    $('#delcancel').click(function(){
            $('#delconfirm').dialog('close');
    });
    
    $("#addphoto").dialog({
            autoOpen: false,
            height: 180,
            width: 400,
            modal: true
    });
    $('#addphotobutton').button().click(function() {
                $('#addphoto').dialog('open');
    });
    $("#active").button();
    //$("#active").button();
    $("[type|=checkbox]").button();
    $("#long").wysiwyg();
    

});

function sendForm(button) {  
  var form = $('#'+button).parents($("form"));
  var url = form.attr("action");
  var data = form.serialize();
  $.post(url,data, function(data) {
      if(data=="") {
        data="Zapytanie zostało wysłane, Dziękujemy."
        $(".contactForm dl").before("<div class='formHide'><div>"+data+"<a id='sendNext'>Kliknij tutaj aby wysłać następne zapytanie</a></div></div>");
        $(".contactForm dd").children().attr("disabled","disabled");
            $('#sendNext').click(function() {
                $('.formHide').remove();
                $(".contactForm dd").children().removeAttr("disabled");
                $('#message').val("");
            });
      } else {
        $('#dialog').html(data);
        $('#dialog').dialog('open');
      }
  });
}

Cufon.replace("h1",{
    textShadow: '1px 1px rgba(0, 0, 0, 0.6)'
});
Cufon.replace("h2");

