
function initBAButton(){
	$("#ba_button img").hide();
	$("#ba_button").css({'cursor' : 'pointer'});
	$("#ba_button").mouseenter(function(){
		$("#ba_button img").fadeIn("slow");
	});
	$("#ba_button").mouseleave(function(){
		$("#ba_button img").fadeOut("slow");
	});
	
	if(!$("#moxiBar").hasClass("docked")) $("#moxiBar").hide();   
	$("#moxiBar").removeClass("hidden");
	
	$("#ba_button").click(function(e){
		$("#moxiBar").slideToggle("slow");   
	});
}



function initClasses(tip){
	_filter(tip,".hideWhileLoading").removeClass("hideWhileLoading");
	_filter(tip,".hide").removeClass("hide").hide();
	//_filter(tip,"a.mb_toggle").each(function(e){ initTitleToggle(this); });
	//_filter(tip,".rgexpands").each(function(e){ initExpandable(this); });
	//_filter(tip,".boxImgBorder").each(function(e){ initBoxImgBorder($(this)); });

}

function initBoxImgBorder(box){
	var h = box.find("div.mc").height();
	//alert(h);
	box.find("div.ml").height(h);
	box.find("div.mr").height(h);
	var w = box.find("div.mc").width();
	//alert(h);
	box.find("div.tc").width(w);
	box.find("div.bc").width(w);
	
}
function initTitleToggle(tgl){
	tgl = $(tgl);
	tgl.unbind();
	tgl.text("+").parents(".moxblok:first").find(".xbukket:first").hide();
	tgl.click(function(e){
		stopDef(e);
		var sign = "+";
		if($(this).text()==sign) sign="-";
		$(this).text(sign).parents(".moxblok:first").find(".xbukket:first").toggle(200);
	});
}

function initExpandable(rg){
	rg = $(rg);
	rg.css({"cursor":"pointer"}).unbind();
	//rg.children(".rok:first").append('<span style="color:#666;font-weight:normal;text-decoration:none;font-size:80%">&raquo; [<a href="#">view details</a>]</span>');
	rg.children(".rok:first").filter(":not(.expandable_inited)").append('<span class="arrows">&nbsp;&raquo; [<a href="#">view details</a>]</span>').addClass('expandable_inited');
	//rg.children(".rok:first").find("div").addClass("arrows");
	//alert(rg.children(".rok:first").html());
	rg.next().hide();
	rg.click(function(e){
		if($(this).next().is(":hidden")){
			$(this).next().slideDown("slow");
		} else {
			$(this).next().slideUp("slow");
		}
		return false;
	});
}

function init(tip,disable){
	if(!tip) tip = $('#app');
	tip= jq(tip);
	//console.dir({tip:tip});
	initClasses(tip);
	
	initControls(tip,disable);
	
	initForms(tip,disable);
	
	initInputTypes(tip,disable);
	
	
	//alert("before xbukkets");
	initXbukkets(tip,disable);
	//alert("after xbukkets");
	initXbloks(tip,disable);
	initRoks(tip,disable);
	//initGallerias(tip,disable);
	//alert("got here");
	initPagination(tip,disable);
	custom_init(tip,disable);
	
	//alert('justloaded='+ justloaded);
	if(justloaded){
		initBAButton();
		justloaded=false;
	}
	
	
	
}

$(document).ready(function() {
	//initCustom();
	init();
});	 
	
