$(document).ready(function(){
	
	
	
	
	$(".img_ctrl_1,.img_ctrl_2,.img_ctrl_3,.img_ctrl_4").hover(function(){
			var classStr = this.className.split("_")[2];
			if($.browser.msie && $.browser.version < 9){
			$("#hover-image-"+classStr).css("display","block");
			} else {
				$("#hover-image-"+classStr).filter(':not(:animated)').fadeIn(300);
				if (classStr == 4) {
					$("#questions").addClass("nobg");
				}
			
			}
		},
		function(){
			var classStr = this.className.split("_")[2];
			if($.browser.msie && $.browser.version < 9){
			$("#hover-image-"+classStr).css("display","none");
			} else {
				$("#hover-image-"+classStr).fadeOut(200);
				if (classStr == 4) {
					$("#questions").removeClass("nobg");
				}
			}
		}
	)
//wall
	if($('body#wall').length > 0){
		var wallHeight = $("#wall-content-wrap").outerHeight(true),
			$mainContent = $("#wall-content-wrap");

		
		$("#wall #content").height($("#wall-content-wrap").outerHeight(true)-180);
		setInterval(function() {
			$("#wall #content").height($("#wall-content-wrap").outerHeight(true)-180);
		}, 500);
		
		
		
		$("#wall-menu a").click(function() {
		    aktlink = $(this).attr("href");
		    //alert(aktlink);
		    
		    
		    
		if($(this).attr('class') != "current") {
		   $mainContent
		       .find("#wall-content")
		       .fadeOut(200, function() {
		           $mainContent.hide().load(aktlink+ "?ajaxContent #wall-content", function() {
		               $mainContent.fadeIn(200, function() {
		                   $("#wall #content").css({"height": ($("#wall-content-wrap").outerHeight(true)-180)+"px"});
		               });
		               $("#wall-menu a").removeClass("current");
		               $("#wall-menu a[href="+aktlink+"]").addClass("current");
		           });
		       });
		}
		    
		    
		    

		    return false;
		});
		
		
		
	}

//media
	if($("#media").length > 0) {
		$('label.overlabel').overLabel('overlabel-apply').css("display","inline");
		
		$("#media-video-slider").easySlider({
				prevId: 		'media-video-slider-prevBtn',
				nextId: 		'media-video-slider-nextBtn',
				continuous: true
		});
		$("#media-billboard-slider").easySlider({
				prevId: 		'media-billboard-slider-prevBtn',
				nextId: 		'media-billboard-slider-nextBtn',
				continuous: true
		});
		$("#media-print-slider").easySlider({
				prevId: 		'media-print-slider-prevBtn',
				nextId: 		'media-print-slider-nextBtn',
				continuous: true
		});
		$("#media-radio-slider").easySlider({
				prevId: 		'media-radio-slider-prevBtn',
				nextId: 		'media-radio-slider-nextBtn',
				continuous: true
		});
		
	};
	
	
	
	
//employers


if($("#employers").length > 0) {
	$(".multi-columns .infobox").hide();
	$(".multi-columns h3").click(function(){
		if (!$(this).hasClass("active")) {
			$(this).addClass("active");
			$(this).next().slideDown();
		} else {
			$(this).removeClass("active");
			$(this).next().slideUp();
		}
	});
};

//show/hide all
$("#employers #showall").click(function(){
	if (!$(this).hasClass("open")) {
		$(this).removeClass("closed");
		$(this).addClass("open");
		$(this).attr('title', 'Rejtsd el mindet!');
		$(this).html("Rejtsd el mindet!");
		$(".multi-columns h3").addClass("active");
		$("#employers .multi-columns .infobox").slideDown();
	} else {
		$(this).removeClass("open");
		$(this).addClass("closed");
		$(this).attr('title', 'Mutasd mindet!');
		$(this).html("Mutasd mindet!");
		$(".multi-columns h3").removeClass("active");
		$("#employers .multi-columns .infobox").slideUp();
	}
});


//offer
$("body#offer .field-checkbox").each(function(){
	var $f = $(this), $fs = $f.find("span:eq(0)"), $fi = $f.find("input:eq(0)");
	if ($fi.attr("checked")) { $fs.html("<b></b>"); }
	$f.find("label").click(function(e){
		$fs.html($fi.attr("checked") ? "" : "<b></b>");
		
		if ($f.find("span.extra").length!=0 && !$fi.attr("checked")) { $f.find("span.extra input").focus(); }
		if ($f.closest("fieldset").hasClass("offer-money-form")) {
			if ($fi.attr("checked")) {
				// ki
				$f.nextAll(".field-select:eq(0)").addClass("field-disabled").find("input, select").attr({ disabled: "disabled" });
				$f.nextAll(".field:eq(0)").addClass("field-disabled").find("input, select").attr({ disabled: "disabled" }); 
			} else {
				// be
				$f.nextAll(".field-select:eq(0)").removeClass("field-disabled").find("input, select").removeAttr("disabled");
				$f.nextAll(".field:eq(0)").removeClass("field-disabled").find("input, select").removeAttr("disabled");
			}
		}
	});
});

$("body#offer .field input[type=text]").each(function(){
	if (!$(this).parent().hasClass("extra")) {
	$(this).width( $(this).parent().width()-$(this).parent().find("label").outerWidth(true) );
	}
});

$("body#offer .field-select select").each(function(){
	var $s = $(this);
	$(this).parent().find("span").text( $s.find("option[value="+$s.val()+"]").text() );
	$(this).change(function(){
		$(this).parent().find("span").text( $s.find("option[value="+$s.val()+"]").text() );
	});
});

$("body#offer form.offer-organization .field-textarea textarea").each(function(){
	var $t = $(this), h = $t.val().length, m = $t.attr("rel");
	if (h>m) { h = '<b>' + h + '</b>'; }
	$t.parent().find("span.counter").html( h + '/' + m );
	$t.bind("keyup click",function(){
		var h = $t.val().length, m = $t.attr("rel");
		if (h>m) { h = '<b>' + h + '</b>'; }
		$t.parent().find("span.counter").html( h + '/' + m );
	});
});

function toten(v) {
	var m = (v%6)*10;
	if (m==0) { m += '0'; }
	return (8+Math.floor(v/6))+':'+ m;
}
	
		$("body#offer form.offer-time div.range").each(function(i){
			
			var r = { min: 0, max: 0, full: $(this).height(), steps: 72, enabled: false, index: i };
			$(this).mousedown(function(e){
				if (!r.enabled) {
					r.min = e.layerY;
					$(this).append('<div class="dummy" style="top: '+r.min+'px;"></div>');
				}
			});
			$(this).mousemove(function(e){
				if (!r.enabled) {
					$(this).find(".dummy").css((e.layerY>=r.min) ? { height: (e.layerY-r.min)+'px' } : { top: e.layerY+'px', height: (r.min-e.layerY)+'px' });
				}
			});
			$(this).mouseup(function(e){
				if (!r.enabled) {
					var $r = $(this);
					r.max = e.layerY;
					if (r.max==r.min) { r.max = r.min + Math.round(12*(r.full/r.steps)); }
					if (r.max<r.min) {
						r.min = parseInt($r.find(".dummy").css("top"));
						r.max = parseInt($r.find(".dummy").height()) + parseInt($(this).find(".dummy").css("top"));
					}
					
					r.enabled = true;
					$r.after('<div class="cancel"><a href="javascript:;">mégse</a></div>').find(".dummy").replaceWith("");
					
					$r.slider({
						orientation: "vertical",
						range: true,
						min: 0,
						max: r.steps,
						values: [r.steps-Math.floor(r.max/(r.full/r.steps)), r.steps-Math.floor(r.min/(r.full/r.steps))],
						slide: function(event, ui) {
							var v = toten($r.slider("option","max") - ui.values[1]) + ' - ' + toten($r.slider("option","max") - ui.values[0])
							$r.find(".amount").text(v);
							$(".dayrange:eq("+r.index+")").val(v);
						}
					}).find(".ui-slider-range").append('<div class="amount">' + toten($(this).slider("option","max") - $r.slider("values",1)) + ' - ' + toten($r.slider("option","max") - $r.slider("values",0)) + '</div><div class="shadow"></div>');
					
					$(".dayrange:eq("+r.index+")").val(toten($(this).slider("option","max") - $r.slider("values",1)) + ' - ' + toten($r.slider("option","max") - $r.slider("values",0)));
					$r.parent().find(".cancel a").click(function(){ $r.slider("destroy").html(""); $(this).parent().replaceWith(""); r.enabled = false; $(".dayrange:eq("+r.index+")").val(""); });
				}
			});
		});

}); //doc. ready end




jQuery.fn.overLabel = function(overClass) {
	return this.each(function(){
		var label = jQuery(this);
		
		var f = label.attr('for');
		if (f) {
			var input = jQuery('#' + f);
			
			this.hide = function() {
				label.css({ textIndent: -10000 })
			}
			
			this.show = function() {
				if (input.val() == '') label.css({ textIndent: 0 })
			}

			input.focus(this.hide);
			input.blur(this.show);
			label.addClass(overClass).click(function(){ input.focus() });
			
			if (input.val() != '') this.hide(); 
		}
	})
}
