/* ::: - - - - - Ready Function  - - - - - ::: */
jQuery(document).ready(function(){
  initonJcarousel();
  initonJcarouselBig();
  initHover();
  initDropDown();
  //initCheckBox();
  initMaklerHover();
});


/* ::: - - - - - jcarousel - - - - - ::: */
function initonJcarousel() {
  jQuery('#building-ref-jcarousel').jcarousel({
	wrap: 'circular',
	scroll: 3
  });
}
function initonJcarouselBig() {
  jQuery('#building-big-jcarousel').jcarousel({
	wrap: 'circular',
	scroll: 7
  });
}


/* ::: - - - - - jcarousel Hover - - - - - ::: */
var showLayer=false;
var closeLayerListener;

function closeLayerFunction(){
  if(!showLayer){
	jQuery(".building-ref-layer.active").css({'display':'none'});
	jQuery(".building-ref-layer.active").each(function(i,n) { 
		var id = jQuery(n).attr("id").substring(8,jQuery(n).attr("id").length);
		jQuery("ul#building-ref-jcarousel li").eq(id).append(jQuery(n));
	});
	jQuery(".building-ref-layer.active").removeClass("active");
	window.clearInterval(closeLayerListener);
  }
}
function closeLayerFunctionBig(){
  if(!showLayer){
	jQuery(".building-big-layer.active").css({'display':'none'});
	jQuery(".building-big-layer.active").each(function(i,n) { 
		var id = jQuery(n).attr("id").substring(8,jQuery(n).attr("id").length);
		jQuery("ul#building-big-jcarousel li").eq(id).append(jQuery(n));
	});
	jQuery(".building-big-layer.active").removeClass("active");
	window.clearInterval(closeLayerListener);
  }
}

function initHover(){
  jQuery("ul#building-ref-jcarousel li").hover(function(){
	closeLayerFunction();
	showLayer=true;
	jQuery(this).children(".building-ref-layer").css({'left' : jQuery(this).offset().left - jQuery(this).closest(".building-ref-jcarousel").offset().left, 'top' : jQuery(this).offset().top  - jQuery(this).closest(".building-ref-jcarousel").offset().top, 'display':'block' }).addClass("active").attr({"id":"reflayer"+$("ul#building-ref-jcarousel li").index(this)});
	
	jQuery(this).closest(".building-ref-jcarousel").append(jQuery(this).children(".building-ref-layer"));},
	function(){
	  showLayer=false;
	  window.clearInterval(closeLayerListener);
	  closeLayerListener = window.setInterval("closeLayerFunction()",500);
  });

  jQuery("div.building-ref-layer").hover(function(){
	showLayer=true;},
	function(){
	  showLayer=false;
  });
  
  jQuery("ul#building-big-jcarousel li").hover(function(){
	closeLayerFunctionBig();
	showLayer=true;
	jQuery(this).children(".building-big-layer").css({'left' : jQuery(this).offset().left - jQuery(this).closest(".building-big-jcarousel").offset().left, 'top' : jQuery(this).offset().top  - jQuery(this).closest(".building-big-jcarousel").offset().top, 'display':'block' }).addClass("active").attr({"id":"reflayer"+jQuery("ul#building-big-jcarousel li").index(this)});	
	jQuery(this).closest(".building-big-jcarousel").append(jQuery(this).children(".building-big-layer"));},
	function(){
	  showLayer=false;
	  window.clearInterval(closeLayerListener);
	  closeLayerListener = window.setInterval("closeLayerFunctionBig()",500);
  });

  jQuery("div.building-big-layer").hover(function(){
	showLayer=true;},
	function(){
	  showLayer=false;
  });
}


/* ::: - - - - - dropDown - - - - - ::: */
function initDropDown() {
  jQuery(".building-buy-search-b span").click(function () {
	  if (jQuery(this).parent().hasClass("open")) {
		  jQuery(".building-buy-search-b ul").hide();
		  jQuery(this).parent().removeClass("open");
	  }
	  else {
		  jQuery(".building-buy-search-b ul").show();
		  jQuery(this).parent().addClass("open");
	  }
  });
  jQuery(".building-buy-search-b ul li").click(function () { 
	  jQuery(".building-buy-search-b > span").html(jQuery(this).text());
	  jQuery(".building-buy-search-b ul").hide();
	  jQuery(".building-buy-search-b").removeClass("open");
  });	
}


/* ::: - - - - - checkBox - - - - - ::: */
function initCheckBox() {
  jQuery(".building-buy-check-a a").addClass("selected");
  jQuery(".building-buy-check-a a").click(function () {
	  if (jQuery(this).hasClass("selected")) {
		  jQuery(this).removeClass("selected");
	  }
	  else {
		  jQuery(this).addClass("selected");
	  }
  });
  jQuery(".building-buy-check-b a").click(function () {
	  if (jQuery(this).hasClass("selected")) {
		  jQuery(this).removeClass("selected");
	  }
	  else {
		  jQuery(this).addClass("selected");
	  }
  });
}


/* ::: - - - - - initMaklerHover - - - - - ::: */
function initMaklerHover() {
  jQuery("div.regional-markler-row").hover(function(){
	jQuery(this).find('div.layer').show();},
	function(){
	  jQuery(this).find('div.layer').hide();
  });
  jQuery("div.investment-markler-row").hover(function(){
	jQuery(this).find('div.layer').show();},
	function(){
	  jQuery(this).find('div.layer').hide();
  });
}
