$(document).ready(function() {
	
	// init menu size
	var width = 968;
	$("#boxes .wrapper").each(function() {
		var count = $(".box", this).length;
		$(".box", this).width( Math.floor((width-count)/count) );
	});
	// init boxes size
	var count = $("#menu li", this).length;
	$("#menu li", this).width( Math.floor((width-count)/count) );
	
	
	// menu
	var counter = 0;
	$("#menu li").hover(function() {
		if (counter == 0) {
			$(this).addClass("over");
			$(this).effect("bounce", {direction: 'up', distance: '5', times: 4}, 150); 
    }
    counter = 1;
  }, function () {
  	$(this).removeClass("over");
    counter = 0;
  });
  
	// homepage images
	$("#menu-img a").hover(function() {
		$(this).effect("pulsate", {times: 1}, 400);
		$('h1.boxes span.em').text($('span', this).text());
		var c = $(this).attr('class').substring(0, 2);
		$("#menu-img a").removeClass("over");
		$(this).addClass("over");
		$("#boxes .wrapper").each(function() {
			if ($(this).hasClass(c)) {
				$(this).show();
			} else {
				$(this).hide();
			}
		});
  }, function() {
	});
	
	// init boxes' details
	if ($("#boxes.btpl").length > 0) {
		if (window.location.href.indexOf("#") != -1) {
			var bId = window.location.href.substr(window.location.href.indexOf("#")+2);
			if (bId) {
				//$("#mtext.btpl").show();
				$("#bd-"+ bId).show();
			}
		} else {
			$("#mtext.btpl .box-detail").first().show();
		}
	}
	$("#boxes.btpl .box").click(function(ev) {
		ev.preventDefault();
		var bId = $(this).attr("id").substr(2);
		//$("#mtext.btpl").show();
		$("#mtext.btpl .box-detail").hide();
		$("#bd-"+ bId).show();
  });
//   $("#boxes.btpl .box .more-link").click(function(ev) {
//   	ev.preventDefault();
//   });
  
});
