$(function(){


if ($.fn.flexipage !== undefined) {
    
  var carousel = $('.carousel').flexipage({
    perpage:1,
    carousel: true,
    speed:800,
    animation: "swing",
    pager_selector: '.pager',
    navigation: true
  });
	
	//autoplay
	var t = setInterval("$('.carousel').selectPage('next')", 5000);
	//stop if users click pager
	$('#gallery .pager a').bind('click', function(e){
		clearInterval(t);
	})
	
  };


  // highlights effect for floor planes
  var areas = $('#content ol.areas a');
  areas.live('mouseover', function(e){
    e.preventDefault();
    $('div.zone_'+$(this).attr('rel'), $(this).closest('.floor')).removeClass('accessible')
  })
  areas.live('click', function(e){
    e.preventDefault();
  })
  areas.live('mouseout', function(e){
    e.preventDefault();
    $('div.zone_'+$(this).attr('rel'), $(this).closest('.floor')).addClass('accessible')
  })


  //tabs for floors section

  if ($('#floors') !== undefined) {
    var floors = $('#floors .info');
    var tab_bar = $('#floors .tabs')
    var tabs = $('a', tab_bar);
    //show only first and active first tab
    floors.not(':first').addClass('accessible');
    $(tabs[0]).parent().addClass('active');

    tabs.bind('click', function(e){
      e.preventDefault();
      tabs.parent().removeClass('active');
      $(this).parent().addClass('active');
      //show content
      floors.addClass('accessible');        
      $($(this).attr('href')).removeClass('accessible')
    })

  };


  //modal window for large images of floors
  $('.floor a.enlarge').bind('click', function(e){
    e.preventDefault();
    var src = $(this).attr('href');
    $.modal('<iframe src="' + src + '" height="100%" width="100%" style="border:0">', {
      closeHTML:'<a class="close" href="#">cerrar</a>',
      containerCss:{
        backgroundColor:"#FFF",
        borderColor:"#fff",
        height:500,
        padding:0,
        width:630
      },
      overlayClose:true
    });
  })

})
