var defaultBG = "null";

$(document).ready(function() {
	$(".fce-content").each(function() {
		if($(this).find(".fce-content-menu-p").length < 1) {
			$(this).hide();
		}
	});
	
	$(".fce-content-menu-inner").each(function() {
		if($(this).children().length < 1) {
			$(this).prev().css("width", "100%");
		}
	});
	
	if($(".fce-banner-wrapper").length > 0) {
		var text = $(".fce-banner-text").html();
		$(".fce-banner-text").html(text+text);
		window.setTimeout("bannerSlider();", 3000);
		//bannerSlider();
	}
});

function toggleContent(id) {
	if(defaultBG == "null" && !$("#background-wrapper").hasClass("bg-4"))
		defaultBG = $("#background-wrapper").attr("class");
	else if(defaultBG == "null")
		defaultBG = "none";
		
	if(!$("#fce-content-"+id).hasClass("active")) {
		$(".cow-link").hide();
		$("#background-wrapper").removeClass(defaultBG);
		$("#background-wrapper").removeClass("bg-4");
		$("#background-wrapper").addClass("none");
		for(var i = 1; i <= 3; i++) {
			if($("#fce-content-"+i).hasClass("active")) {
				$("#fce-content-"+i).animate({
					height: "40px"
					}, 400, function() {
						// Animation complete.
					}
				);
				$("#fce-content-"+i).removeClass("active");
				break;
			}
		}
		var offsetHeight = $("#fce-content-"+id).find(".fce-content-inner-wrapper").attr("offsetHeight") + 50;

		$("#fce-content-"+id).animate({
			height: offsetHeight
			}, 400, function() {
				// Animation complete.
			}
		);
		$("#fce-content-"+id).addClass("active");
	} else {
		$("#fce-content-"+id).animate({
			height: "40px"
			}, 400, function() {
				$(".cow-link").show();
			}
		);
		$("#background-wrapper").removeClass("none");
		$("#background-wrapper").addClass(defaultBG);
		$("#fce-content-"+id).removeClass("active");
	}
}

function toggleContentInner(wrapperId, innerId) {
	// remove active from link
	$("#fce-content-"+wrapperId).find(".fce-content-menu-inner").find("a").removeClass("active");
	// remove active from container
	$("#fce-content-"+wrapperId).find(".fce-content-inner").removeClass("active");
	
	$("#fce-content-inner-"+wrapperId+"-"+innerId).addClass("active");
	$("#fce-content-link-"+wrapperId+"-"+innerId).addClass("active");
	
	if($("#fce-content-inner-"+wrapperId+"-"+innerId).find("#gmap-1").length > 0) {
		createMap("gmap-1");
	}
	if($("#fce-content-inner-"+wrapperId+"-"+innerId).find("#gmap-2").length > 0) {
		createMap("gmap-2");
	}
	if($("#fce-content-inner-"+wrapperId+"-"+innerId).find("#gmap-3").length > 0) {
		createMap("gmap-3");
	}
	if($("#fce-content-inner-"+wrapperId+"-"+innerId).find("#gmap-4").length > 0) {
		createMap("gmap-4");
	}
	if($("#fce-content-inner-"+wrapperId+"-"+innerId).find("#gmap-5").length > 0) {
		createMap("gmap-5");
	}
	if($("#fce-content-inner-"+wrapperId+"-"+innerId).find("#gmap-6").length > 0) {
		createMap("gmap-6");
	}
	
	var offsetHeight = $("#fce-content-"+wrapperId).find(".fce-content-inner-wrapper").attr("offsetHeight") + 50;

	$("#fce-content-"+wrapperId).animate({
		height: offsetHeight
		}, 400, function() {
			// Animation complete.
		}
	);
}

function setBG(classID) {
	if($("#background-wrapper").hasClass(classID))
		$("#background-wrapper").attr("class",defaultBG);
	else
		$("#background-wrapper").attr("class",classID);
}

function setContentHeight(contentID, height) {
	$("#"+contentID).css("height",height);
}

function bannerSlider() {
	var left = parseInt($(".fce-banner-text").children().first().css("marginLeft"));
	$(".fce-banner-text").children().first().css("marginLeft", left-2+"px");
	if(left < -970) {
		$(".fce-banner-text").children().first().remove();
		var text = $(".fce-banner-text").html();
		$(".fce-banner-text").html(text+text);
	}
	window.setTimeout("bannerSlider();", 75);
}
