$(function(){
    $('.click').mouseup(function(){
        id = $(this)[0].id;
        $.ajax({
              url: getBaseURL()+"getProjekt/"+id,
              dataType: 'json',
              success: function(data) {
                img = data.img;
                text = data.popis;
                nazov = data.nazov;
                pozicia = data.pozicia;
                max = ($("#holder td").length - 1);
                
        $('body').animate({scrollTop: 0},'slow', function(){
           $('#banner_body_flash').fadeOut('slow', function(){
               $('#banner_flash').remove();
               $("#contentBody").animate({'paddingTop' : 131},'slow');
               if(!$('#banner_content').length){
                   leftposition = pozicia*1-1;
                   if(leftposition<0)leftposition=max;
                   rightposition = pozicia*1+1;
                   if(rightposition>max)rightposition=0;
                   
                   $('<div id="banner_content" />').appendTo($('#banner_body_flash'));
                   img = $("<img />",{ src : getBaseURL()+'/images/projekty/'+img, alt : nazov});
                   left = $("<a />",{ 'class' : 'left_arrow', id : leftposition })
                   right = $("<a />",{ 'class' : 'right_arrow', id : rightposition });
                   $("#navi").append(left);
                   $("#navi").append(right);
                   $("#banner_content").append(img);
                   $("#navi").delegate('a','click',function(){
                       getbanner($(this).context.id);
                   });
               }
               else{
                   leftposition = pozicia*1-1;
                   if(leftposition<0)leftposition=max;
                   rightposition = pozicia*1+1;
                   if(rightposition>max)rightposition=0;
                   $("#banner_content img").remove(); 
                   img = $("<img />",{ src : getBaseURL()+'/images/projekty/'+img, alt : nazov});
                   $(".left_arrow").attr('id',leftposition);
                   $(".right_arrow").attr('id',rightposition);
                   $("#banner_content").append(img);
                   $("#navi").delegate('a','click',function(){
                       getbanner($(this).context.id);
                       return false;
                   });
               }
               
                 
                 $('#banner_body_flash').fadeIn(function(){
                      
                      body = "<h1 class='super'>"+nazov+"</h1><p>"+text+"</p>";//<div href='"+getBaseURL()+"references/"+data.id+"' class='fb-like' data-send='false' data-layout='button_count' data-width='450' data-show-faces='false' data-font='tahoma'></div><div id='fb-root'></div>"
                     
                     $(".referencie_uvod").fadeOut(function(){
                       
                            $(".referencie_uvod").fadeOut(function(){
                                   $.getScript(getBaseURL()+'js/like.js',function(){    $('.referencie_uvod').animate({'height' : '60px'}).html(body).fadeIn(); });
                          });
                      });
                  });
           });
        });
               
               
              }
            });
        
    });
    
    /*dalsi klik*/
    function getbanner(id){
        
         $.ajax({
              url: getBaseURL()+"getProjekt/"+id,
              dataType: 'json',
              success: function(data) {
                img = data.img;
                text = data.popis;
                nazov = data.nazov;
                pozicia = data.pozicia;
                max = ($("#holder td").length - 1);
                
                   leftposition = pozicia*1-1;
                   if(leftposition<0)leftposition=max;
                   rightposition = pozicia*1+1;
                   if(rightposition>max)rightposition=0;
                   img = $("<img />",{ src : getBaseURL()+'/images/projekty/'+img, alt : nazov}).css({'display' : 'none'});
                   
                   $(".left_arrow").attr('id',leftposition);
                   $(".right_arrow").attr('id',rightposition);
                   $("#banner_content img").css({'zIndex':'30'}).fadeOut(1000,function(){
                       $(this).remove(); 
                       }); 
                       img.appendTo("#banner_content").fadeIn(1000);
                 
                        body = "<h1 class='super'>"+nazov+"</h1><p>"+text+"</p>";//<div href='"+getBaseURL()+"references/"+data.id+"' class='fb-like' data-send='false' data-layout='button_count' data-width='450' data-show-faces='false' data-font='tahoma'></div><div id='fb-root'></div>";
                          $(".referencie_uvod").animate({'opacity' : 0},function(){
                                   $.getScript(getBaseURL()+'js/like.js',function(){ $('.referencie_uvod').html(body).animate({'opacity' : 1}); });
                         
                   }); 
                  
                
              }
         });
    }
    
    
    /*NEWSLETTER*/
    
    $(window).scroll(function(){
    },function(){
       $("#newsletter").stop().animate({'top': getPageScroll()+250} ,2000,'easeOutCirc')
    });
    $("#newsletter").hover(function(){
       $(this).stop().animate({'left': 0})
    },
    function(){
       $(this).stop().animate({'left': -180},'slow','easeOutBounce')
    });
    
    
    function getPageScroll() {
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}
	return yScroll
}
    
    
    
    
    
    
    
    
    
    
    
    
    function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://http://www.funhousestudio.sk') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

} 
});
