$(function() {
	
	var defaultVal;
	
	$(" input[type=submit], .browseList li, #sidebar .usersArea, .fileWrapper").hover(function(){ $(this).addClass("hover"); }, function(){ $(this).removeClass("hover"); });
	$(" input[type=submit], ").focus(function(){
		$(this).addClass("hasFocus");
		defaultVal = $(this).attr("value");
		$(this).attr("value","");
	});
	$("input[type=text]").addClass("text");
	$("input[type=text], input[type=submit]").blur(function(){
		$(this).removeClass("hasFocus");
		if($(this).attr("value") == "") {
			$(this).attr("value",defaultVal);
		}
		defaultVal = undefined;
	});
	
	$("#registerForm #Rabbreviation, #registerForm #Rname").prev("label").css("margin-left","110px");
	
	$("#sidebar li").addClass("clear");
	
	$("#sidebar .news .theNews li:last, #footer ul li:last").css("border","0");
	
	$("fieldset.advSearch").hide();
	$("a.advSearch").click(
		function(){
			$("fieldset.advSearch").slideToggle("fast");
			$(this).toggleClass("active");
			if( $(this).hasClass("active") ) {
				$(this).text("Cautare simpla");
			} else {
				$(this).text("Cautare avansata");
			}
		}
	);
	
	$(".answers li").addClass("clear");
	$(".answers li .percentage").prepend("<div class=\"theBar\"></div>");
	var answrs = $(".answers li").children(".percentage");
	answrs.each( function(i){
		var barwidth = $(this).children("em").text();
		$(this).children(".theBar").css("width", 3 * barwidth + "px");
		$(this).css("background-position",3 * barwidth + "px 0px");
	});
	
	$(".theComment .wrapper .full").hide();
	$(".theComment .wrapper .excerpt a").click(function(){
		$(this).parent(".excerpt").next(".full").show("fast");
		$(this).parent(".excerpt").hide();
	});
	$(".theComment .wrapper .full a").click(function(){
		$(this).parent(".full").prev(".excerpt").show("fast");
		$(this).parent(".full").hide();
	});
	
	$(".browseList .headers .sortAsc, .browseList .headers .sortDesc").append("<em>&nbsp;</em>");
	
	$(".browseList li .yMap").css("visibility","hidden");
	$(".browseList li").hover(
		function(){
			$(this).children(".domain").children("a.yMap").css("visibility","visible");
			$(this).children(".domain").children("a.yMap").click(function(){
				var whichMap = $(this).attr("rel");
				$(this).after("<span class=\"yMap\"><span class=\"background\">&nbsp;</span><span id=\"mapContainer\" class=\"mapContainer\"></span></span>");
				var map = new Map("mapContainer", "YD-PAjpx3E_JXlHf8oW.vEFyQ--", whichMap, 3);
				map.addTool( new PanTool(), true );
			});
		},
		function(){
			$(this).children(".domain").children("a.yMap").css("visibility","hidden");	
			$(this).children(".domain").children("span.yMap").remove();	
		}
	);
	
	var doRateObj;
	$(".rating .doRate a").hover(
		function(){
			doRateObj = $(this).parent(".doRate").prev(".soFar").clone().prependTo(".rating");
			$(this).parent(".doRate").prev(".soFar").hide();
			switch($(this).attr("class")){
				case "one" : $(doRateObj).css("width","12px"); $(doRateObj).show();
				break;
				case "two" : $(doRateObj).css("width","27px"); $(doRateObj).show();
				break;
				case "three" : $(doRateObj).css("width","42px"); $(doRateObj).show();
				break;
				case "four" : $(doRateObj).css("width","57px"); $(doRateObj).show();
				break;
				case "five" : $(doRateObj).css("width","72px"); $(doRateObj).show();
				break;
			}
		},
		function(){
			$(doRateObj).remove();
		}
	);
	
	$(".rating .doRate").mouseleave(function(){
		$(this).prev(".soFar").show();
	});
	
	$("#commentForm").hide();
	
	$("a.comenteaza, .comments .heading a").click(function(){
		$("#commentForm").toggle();
	});
	
	$(".browse h2:first").css("padding-top","0");
	
	$(".browse a.more:first").css("margin-top","5px");
	
});
