var curTab = 1;

$(document).ready(function(){
  $('div#double-posts').hide();
  $('div#double-posts').fadeIn('slow');
  $('.pagebar a#but'+curTab).addClass('selected');
});


function showTab(id) 
{
  curTab = id;
  $('div#double-posts').fadeOut('normal', function() {
    $('div#double-posts').load('/static/view/page/'+id, {'isAjax': 'true'}, function(){
      $('div#double-posts').fadeIn('normal');
      $('.pagebar a.navlink').removeClass('selected');
      $('.pagebar a#but'+curTab).addClass('selected');
    });
  });
}

function nextTab()
{
  if (++curTab>5) curTab = 1;
  showTab(curTab);
}

function prevTab()
{
  if (--curTab<1) curTab = 5;
  showTab(curTab);
}

function portLoadPhoto(img, desc) {
  $('#portDesc').html('');
  $('img#portPic').fadeOut('fast', function() {
    $('img#portPic').attr('src', img);
    $('img#portPic').load(function() {
      $('#portDesc').html(desc);
      $('img#portPic').fadeIn('fast');
    });
  });
}

/*var data = [
            { image: "http://ile-defrance.local/port/port0/pic1.jpg",class: 'active' },
            { image: "http://ile-defrance.local/port/port0/pic2.jpg",class: 'active' },
            { image: "http://ile-defrance.local/port/port0/pic3.jpg",class: 'active' },
            { image: "http://ile-defrance.local/port/port0/pic4.jpg",class: 'active' },
            { image: "http://ile-defrance.local/port/port0/pic5.jpg",class: 'active' },
        ];
var data_7 = [{image: '/port/port0/pic5.jpg',class: 'active'}];*/
$(function(){
	//jQuery.noConflict();
	Galleria.loadTheme('/js/themes/classic/galleria.classic.js');
	$(".i-img_group img").each(function(){
		//$(this).hide();
	});
	
	
	$(".i-img_group img").click(function(){
		$('#galleria').show();

		var data = new Array();
		var self = this;
		if($(this).attr("class") == "inner") {
			var con_class = $(this).parent().parent().parent().parent().attr("class");
		} else {
			var con_class = $(this).parent().parent().attr("class");
		}
		var str = new String($(self).attr("src"));
		
		var newString = new String(str.replace("&height=85", ""));
		//console.log(newString);
		var str = newString.replace("&height=200", "");
		//console.log(str);
		data.push({image:str, class: 'active'});
		//alert(str);
		
		$("." + con_class + "_source span").each(function(){
			if($(this).text() != str) {
				data.push({image:$(this).text(), class: 'active'});
			}
		});
		
		var position = $(this).position();
		//console.log(($(window).height()));
		$('#galleria').css("top", ($(window).height()/2)-($('#galleria').height()/2)).css("left", ($(document).width()/2)-($('#galleria').width()/2));
		
		var a = $('#galleria').galleria({
			debug: true, // debug is now on
			width: $('#galleria').width(),
			height: $('#galleria').height(),
		    //https://github.com/aino/galleria/blob/master/docs/options/data_config.rst
		    //https://github.com/aino/galleria/blob/master/docs/options/data_source.rst Р�СЃС‚РѕС‡РЅРёРє РґР°РЅРЅС‹С… РґР»СЏ РіР°Р»Р»РµСЂРµРё
		    data_source: data
		});
		var close = $("<div>", {
	        className: "i-galleria_close",
	        click: function() {
				$('#galleria').hide();
			}
	    });
		$('#galleria').prepend(close);
		$('#galleria').mouseover(function(){

		});
		//console.log(a);
		$.scrollTo('#galleria');
	});
});
