
$(document).ready(function() {
    $("a.grouped_elements").fancybox({
      
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	300, 
        'speedOut'		:	200, 
        'overlayShow'	:	true,
        'showCloseButton'	: true,
        'titlePosition'     : 'over',
        'titleFormat'       : function(titleStr, currentArray, currentIndex, currentOpts) {
            var imageSrc = currentArray[currentIndex].href;             
            var splittedImage = imageSrc.split("/");            

            // Internet Explorer alatt az indexOf nem mukodik!
            //var pictureDirIndex = splittedImage.indexOf("pictures"); 
                       
            var pictureDirIndex = -1;
            var searchText = "pictures";
            for (var i=0; i<splittedImage.lenght; i++)                
            {
               if (splittedImage[i] == searchText)                     
               {
                   pictureDirIndex = i;
                   break;
               }
            }
            
            var imageExtensionIndex = splittedImage.length-1;
            var hrefElementsNr = imageExtensionIndex - pictureDirIndex;
            var selectedImage = "";  
            for (i=1; i<=hrefElementsNr; i++)
            {
                selectedImage += "/" + splittedImage[pictureDirIndex + i];
            }

            var pageLocation = document.location.href;
            var splittedPageLocation = pageLocation.split("/");            
            var splitedPageLocationIndex = splittedPageLocation.length - 1;
            var pageId = splittedPageLocation[splitedPageLocationIndex];
           
            pageLocation = document.location.href.split('/');
            pageLocation.pop();
            var host = pageLocation.join('/');

            var pictureUrl = escape(host + '/picture.php?selectedpic=' + selectedImage + '&amp;page=' + pageId);
            return '<span id="fancybox-title-over"> <iframe allowTransparency="true" src="http://www.facebook.com/plugins/like.php?href=' + pictureUrl +
            '&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20"frameborder="0" scrolling="no"style="border:none;overflow:hidden;width:90px;height:20px"></iframe> <span>' + titleStr + '</span></span>';
        }
    }
    );	
});

 (function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/hu_HU/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
