/******************************************/
/* Autor: Domon                           */
/* Kopiowanie zabronione!                 */
/*----------------------------------------*/
/* Jesli fragment ponizszego skryptu      */
/* znajdzie sie na Twojej stronie,        */
/* zjawie sie w nocy pod Twoim lozkiem.   */
/******************************************/

o = {
  
  init: function(){
    $('#content').css('margin-top','-900px');
    $('#nav-left').circlemenu( 120, 100, 145, 90, -90 );
    this.Href = self.location.href.replace('http://www.domons.net/', '');
    if(this.Href.indexOf('#')!=-1) {
      this.Href = this.Href.substring(this.Href.indexOf('#')+1, self.location.href.length);
    }
    if(this.Href == '') { this.Href = 'index.html'; }
    this.get_page(this.Href);
    $('#left nav ul li a, #nav-right a.mail').click(function () {
      var clas = $(this).attr('class');
      if(clas != 'radius-50 diavlobold active') {
        $('#left nav ul li a').removeClass('active');
        $(this).addClass('active');   
        var href = $(this).attr('href');
        if(href == 'blog/') {
          return true;
        }else{
          o.get_page(href);
          self.location.href = '#'+href;
        }
      }
      return false;
    });	
    
    $('#right nav ul li a.mail').hover(function() {
      $('span', this).css('display', 'block').hide().fadeIn();
    },function() {
      $('span', this).css('display', 'none').show().fadeOut();    
    });
    
    $(document).bind("contextmenu",function(e){
      return false;
    });
  },
  
  get_page: function(e){
    $('#content').animate({'margin-top':'-900px'},700);
    $('#loader').fadeIn();
    setTimeout(function() {
      $.ajax({
        url: 'pages/'+e, type: 'GET', success: function (html){
          $('#content').html(html);   
          $('#content').animate({'margin-top':'0px'},400);
        }, error:function(){
          $('#content').animate({'margin-top':'0px'},400);
          $('#content').html('<div id="error">Wystąpił błąd!</div>');
        }          
      });
      $('#loader').fadeOut();
    },900);
  },
  
  omnie_init: function() {
    $('#left nav ul li a').removeClass('active');    
    $('#left nav ul li a[href="o-mnie.html"]').addClass('active'); 
    $('#omnie #photo').animate({marginLeft:'437px'},1000);
    $('#omnie ul li span#skill1').animate({width:$('#omnie ul li span#skill1').html()},1000);
    $('#omnie ul li span#skill2').animate({width:$('#omnie ul li span#skill2').html()},1000);
    $('#omnie ul li span#skill3').animate({width:$('#omnie ul li span#skill3').html()},1000);
    $('#omnie ul li span#skill4').animate({width:$('#omnie ul li span#skill4').html()},1000);
  },
  
  index_init: function() {
    $('#left nav ul li a').removeClass('active');    
    $('#cindex #slider-info a.index-right, #cindex #slider-info a.index-left').click(function () {
      var works = $('#works-numrows').html();
      var id = $('#cindex #slider-info a').attr('ajaxify');  
      var clas = $(this).attr('class');
      if(clas == 'index-left') {
      var new_id = id --- 1;
      }else if(clas == 'index-right') {
      var new_id = id +++ 1;    
      }
      if(new_id >= 0 && new_id < works+++1) {
        $('#cindex #slider-info a').attr('href', 'index-'+new_id+'.html');
        $('#cindex #slider-info a').attr('ajaxify', new_id);
        o.get_slide(id);
        self.location.href = '#index-'+id+'.html';     
      }
      return false;
    });	
    
    $('#cindex #slider-info a.index-left').hover(function() {
      $('#cindex #slider-info a.index-left span').stop().animate({ opacity:1 },250);
    },function() {
      $('#cindex #slider-info a.index-left span').stop().animate({ opacity:0 },250);
    });
    $('#cindex #slider-info a.index-right').hover(function() {
      $('#cindex #slider-info a.index-right span').stop().animate({ opacity:1 },250);
    },function() {
      $('#cindex #slider-info a.index-right span').stop().animate({ opacity:0 },250);
    });
  },
  
  get_slide: function(e) {
    $('#slider-info-c div, #sld-img').fadeOut(300);
    setTimeout(function() {
      $.ajax({
        url: 'pages/index_info.php?id='+e, type: 'GET', success: function (html){
          $.ajax({
            url: 'pages/index_img.php?id='+e, type: 'GET', success: function (html2){
              $('#slider-info-c div').html(html).fadeIn(300);  
              $('#sld-img').html(html2).fadeIn(300); 
            }, error:function(){
              $('body').html('Wystąpił błąd!');
            }
          });
        }, error:function(){
          $('#content').html('Wystąpił błąd!');
        }
      });
    },200);
  },
  
  index_img: function() {
    $('#slider-nav').circlemenu( 240, 50, 255, 150, 195); 
    $('#slider-nav li a').click(function() {
      $('#slider-nav li a').removeClass('active');
      $(this).addClass('active');
      var id = $(this).attr('rel');
      var slide = id * 511;
      $('#cindex #slide-img').stop().animate({backgroundPosition: '0px -'+slide+'px'},300);
      return false;
    });
  },
  
  oferta_init: function() {
    $('#left nav ul li a').removeClass('active');    
    $('#left nav ul li a[href="oferta.html"]').addClass('active');
    $('#offer-nav').circlemenu(225, 220, 258, 41, -69); 
    $('#offer-nav a').click(function () {
      var a = $(this).attr('ajaxify');  
      var h = $(this).attr('href');  
      $('#offer-nav a').removeClass('active');    
      $(this).addClass('active');
      o.get_offer(a);
      self.location.href = '#'+h;         
      return false;
    });	
  },
  
  get_offer: function(e) {
    $('#oferta .content-text').fadeOut(300);
    setTimeout(function() {
      $.ajax({
        url: 'pages/'+e, type: 'GET', success: function (html){
          $('#oferta .content-text').html(html).fadeIn(300);  
        }, error:function(){
          $('#content').html('Wystąpił błąd!');
        }
      });
    },400);
  },
  
  oferta_txt: function(e) {
    $('#offer-nav a').removeClass('active'); 
    $('#offer-nav a[ajaxify="oferta_txt.php?id='+e+'"]').addClass('active');

    $('#oferta .content-text a').click(function() {
      var h = $(this).attr('href');  
      o.get_page(h);
      self.location.href = '#'+h;         
      return false;
    });
    
  },
  
  realizacje_init: function() {
    $('#left nav ul li a').removeClass('active');    
    $('#left nav ul li a[href="realizacje.html"]').addClass('active');
    $('#works-list').circlemenu(220, 220, 255, 237, -60);
    
    $('#works-pager a#prev').hover(function() {
      $('#works-pager a#prev span').stop().animate({ opacity:1 },250);
    },function() {
      $('#works-pager a#prev span').stop().animate({ opacity:0 },250);
    });
    $('#works-pager a#next').hover(function() {
      $('#works-pager a#next span').stop().animate({ opacity:1 },250);
    },function() {
      $('#works-pager a#next span').stop().animate({ opacity:0 },250);
    });
    
    $('#works-pager a').click(function() {
      var works = $('#works-pages').html();
      var clas = $(this).attr('id');
      var id = $('#works-pager a').attr('ajaxify');  
      if(clas == 'prev') {
      var new_id = id --- 1;
      }else if(clas == 'next') {
      var new_id = id +++ 1;    
      }
      if(new_id >= 0 && new_id < works+++1) {
        $('.content-text').fadeOut(100);
        $('#works-pager a').attr('href', 'realizacje-'+new_id+'.html');
        $('#works-pager a').attr('ajaxify', new_id);
        $('#realizacje #works-pager #noactive-pager').show();
        var promien = 255;
        var back = false;
        var run = true;
        $('#loader').fadeIn();
        
        var info = (new_id*10);
        
        $.ajax({
          url: 'pages/realizacje_circle.php?page='+new_id, type: 'GET', success: function (html){
            $.ajax({
              url: 'pages/realizacje_info.php?id='+info, type: 'GET', success: function (html2){
                setInterval(function() {
                  if(run == true) {
                    if(back == true) {
                      promien = promien +++ 20;
                      if(promien > 245) {
                        run = false;
                      }
                    }else{
                      promien = promien --- 20;
                      if(promien < 70) {
                        back = true;
                        $('#works').html(html);  
                        $('#loader').fadeOut(); 
                        setTimeout(function() {
                          $('.content-text').html(html2).fadeIn(); 
                        },200);
                        $('#realizacje #works-pager #noactive-pager').hide();
                      }
                    }
                    $('#works-list').circlemenu(220, 220, promien, 237, -60);
                  }
                },1);  
              }, error:function(){
                $('.content-text').html('Wystąpił błąd!');
              }          
            });     
          }, error:function(){
            $('#content').html('<div id="error">Wystąpił błąd!</div>');
          }          
        });
        self.location.href = '#realizacje-'+id+'.html';     
      }
      return false;
    });
  },
  
  realizacje_circle: function() {
    $('#works-list a').click(function() {
      var page = $('#works-pager a').attr('ajaxify');  
      var id = $(this).attr('ajaxify');  
      var rel = $(this).attr('rel');  
      $('#works-list a').removeClass('active');
      $(this).addClass('active');
      $('.content-text').fadeOut(200);
      setTimeout(function() {
        $.ajax({
          url: 'pages/realizacje_info.php?id='+id, type: 'GET', success: function (html){
            $('.content-text').html(html).fadeIn(200);  
          }, error:function(){
            $('.content-text').html('Wystąpił błąd!').fadeIn(200);
          }          
        });
      },200);  
      self.location.href = '#podglad-'+page+'-'+id+'-'+rel+'.html';     
      return false;
    });
  },
  
  realizacje_info: function(a) {
    $('#works-list a').removeClass('active');
    $('#works-list a[ajaxify="'+a+'"]').addClass('active');
    $('#realizacje .content-text a').click(function() {
      var e = $(this).attr('href');  
      o.get_page(e);
      self.location.href = '#'+e;     
      return false;
    });
  },
  
  kontakt_init: function() {
  
    $('#left nav ul li a').removeClass('active');    
    $('#left nav ul li a[href="kontakt.html"]').addClass('active');
      
    $('[name="subject"]').focus(function() { if(this.value == 'Temat wiadomości') this.value = ''; });
    $('[name="subject"]').blur(function() { if(this.value == '') this.value = 'Temat wiadomości'; }); 
    
    $('[name="email"]').focus(function() { if(this.value == 'Adres email') this.value = ''; });
    $('[name="email"]').blur(function() { if(this.value == '') this.value = 'Adres email'; }); 
    
    $('[name="name"]').focus(function() { if(this.value == 'Imię i nazwisko') this.value = ''; });
    $('[name="name"]').blur(function() { if(this.value == '') this.value = 'Imię i nazwisko'; }); 
    
    $('[name="message"]').focus(function() { 
      if($(this).val()=='Treść wiadomości'){
        $(this).val('');
      }
    });
    
    $('[name="message"]').blur(function() { 
      if($(this).val()==''){
        $(this).val('Treść wiadomości');
      }
    });    
      
    $('#contact .content-text form').submit(function() {
      $('[name="send"]').prop('disabled', true);
      var action = $(this).attr('action');
      $.post('pages/'+action, {
        imie: $('[name="name"]', this).val(),
        email: $('[name="email"]', this).val(),
        subject: $('[name="subject"]', this).val(),
        message: $('[name="message"]', this).val()
      },function(data){
        $('#contact #contact-info #contact-idiv').fadeOut();
        setTimeout(function() {
          $('#contact #contact-info #contact-idiv').html(data).fadeIn();
        },500);    
        setTimeout(function() {
          $('[name="send"]').prop('disabled', false);
        },5000);
      }); 
      return false;
    });
  }
  
}

$(function(){ 
  o.init(); 
});
