$(document).ready(function(){ 
	
	$('a.tips').cluetip();

	//$('#mspacer').css("height",parseInt($('#attachments').css("height"))-150);

	$(function() {
		$('#hsssearch > a > span').hover(
			function() {
				$(this).addClass("hover");
				$('#searchfield').show();
				$('#sif').focus();
			},
			
			function() {
				//$(this).removeClass("hover");
			}			
			);
	 });
	 
	 $(function() {
		$('#hsshome > a > span').hover(
			function() { hideSearch(); },function() {});
	 });
	 $(function() {
		$('#hsssitemap > a > span').hover(
			function() { hideSearch(); },function() {});
	 });
	 
	 function hideSearch() {
	 	$('#hsssearch > a > span').removeClass("hover");
	 	$('#searchfield').hide();
	 }	 
	 
	 $(function() {
		$('#menu > ul > li').hover(
			function() {
				if (!$(this).hasClass("changelangs")) {
					$(this).addClass("lihover");
				}
				
				// az elozo border-bottomjat irtani kell!
				//alert(this.id);
				if (this.id.substr(6,9) != 1) {
					var sub = '#mitem_' + parseInt(this.id.substr(6,9)-1);
					$(sub).addClass("menu_bottom");
				}
				
			},
			
			function() {
				if ($(this).hasClass("active_menu")) {
					// marad a lihover!
				} else {
					$(this).removeClass("lihover");
					if (this.id.substr(6,9) != 1) {
					var sub = '#mitem_' + parseInt(this.id.substr(6,9)-1);
					$(sub).removeClass("menu_bottom");
				}
				}
			}			
			);
	 });
	 
	 
	 $(function() {
		$('#sidemenu > ul > li').hover(
			function() {
				$(this).addClass("lihvr");
			},
			
			function() {
				$(this).removeClass("lihvr");
			}			
			);
	 });
	 
	 
	 $(function() {
	 	$('#content_more_p > a').click(function() {
		$("#content_more_p").hide();
		//$("#content_more_p").addClass("hidn");
		
		$("#content_more").fadeIn("fast");
		return false;
	 });
	 });
	 
	 
	 $(function() {
	 	$('#feedbacktoggle').click(function() {
	 	$('#feedback > h5').text($('#feedback > h5 > a').html());
		$("#feedback_form").fadeIn("fast");
		return false;
	 });
	 });
	 
	 
	 
	 $(function() {
	 	$('#sidemenu > ul > li > a').click(function() {
		
			// kinyitotta, eloszor mindet becsuk
			$('#sidemenu > ul > li > a').removeClass("ctva");
			$('#sidemenu > ul > li > ul').hide();
			
			if (this.className == 'hasnochild') {
				return true;
			}
		
		var sub = '#' + this.id.substr(1,9);
		$(sub).toggle();
						
		if ($(sub).css('display') == 'block') {
			$(this).addClass("ctva");
		} else {
			$(this).removeClass("ctva");
		}
		
		return false;
	 });
	 });
	 
	 
	 
	 
	 
	 
	 $("form#feedback_form_form").submit(function(){
	 	$.ajax({
       		type: "POST",
       		dataType: "json",
       		url: "/do/feedback",
       		data: $("#feedback_form_form").serialize(),
       		success: function(json) {
       			if (json.response[0].error == "ok") {
       				$("#feedback_error").hide();
       				$("#feedback_form").hide();
       				$("#feedback_sent").show();
       			} else {
       				$("#feedback_error").show();
       			}
       		}
       	});
	 	return false;
	 });
	 
	 
	 $("form#feedback2").submit(function(){
	 
	 	$("#sending").show();
	 	$("#fbsubmit").hide();
	 	$("#fb_error").hide();
	 
	 	$.ajax({
       		type: "POST",
       		dataType: "json",
       		url: "/do/info",
       		data: $("#feedback2").serialize(),
       		success: function(json) {
       			if (json.response[0].error == "ok") {
       				$("#feedback2").hide();       				
       				$("#sending").hide();
       				$("#fbsubmit").hide();
       				$("#fb_error").hide();
       				$("#fb_sent").show();
       				$.scrollTo($("#fb_sent"), 800 );
       			} else {       				
       				/* hibas */
       				$("#sending").hide();
       				$("#fbsubmit").show();
       				$("#fb_error").show();
       				
       			}
       		}
       	});
	 	return false;
	 });
	 
	 
	 /*$("#companies").animate({ 
        width: "10px",
      }, 1500 );*/
	 
	 

	 $(function() {	
	 	var ticker = {
        ul_width: 0,
        init: function() {
            ticker.timer = window.setInterval(ticker.animate,50);
        },
        animate: function() {
            $("#companies").css("left",(parseInt( $("#companies").css("left")) - 2) + "px");
            //console.log( $("#companies").css("width") + '--' + $("#companies").css("left"));
            //console.log(parseInt(($("#companies").css("left")))*-1);
            if (parseInt($("#companies").css("width")+30)<parseInt(($("#companies").css("left")))*-1) {
            	// restart
            	$("#companies").css("left","600px");
            }
        },
        timer: null,
        close: function() {
            /*$("#ticker").slideUp("normal",function() {
                window.clearInterval(ticker.timer);
            });*/
        }
    	};
    	
    	//console.log(parseInt($("#companies").css("width")));
    	if (parseInt($("#companies").css("width"))) {
    	ticker.init();
    	}
    	
     });
     
     
     
     $("form#logolist").submit(function(){
     	$("#logolist_okay").hide();
     	$("#logolist_sortable").val($('#logoFull').sortable('toArray'));
	 	$.ajax({
       		type: "POST",
       		dataType: "json",
       		url: "/do/admin",
       		data: $("#logolist").serialize(),
       		success: function(json) {
       			if (json.response[0].error == "ok") {
       				$("#logolist_okay").show();
       			} else {
       				window.location='/hu/adminisztracio/?action=logos';
       			}
       		}
       	});
	 	return false;
	 });
	 
	 

	 $(function() {
		$('table.modulok > tbody > tr > td').hover(
			function() {
				if (!$(this).hasClass("empty")) {
					$(this).addClass("active");
					var sub = '#text_' + this.id;
					$(sub).show();
				}
			},
			
			function() {
				if (!$(this).hasClass("empty")) {
					$(this).removeClass("active");
					var sub = '#text_' + this.id;
					$(sub).hide();
				}
			}			
			);
			
			
		$('table.modulok > tbody > tr > td').click(function() {
				var $x = $(this);
				window.location = $x.find('div > a').attr("href");
			}			
			);
	 });
	 
	 
	 
	 
	  $("#clientfeedback_submit").click(function(){
     	$("#cfb_error").hide();
     	$("#cfb_sending").show();
	 	$.ajax({
       		type: "POST",
       		dataType: "json",
       		url: "/do/checkclientfeedback",
       		data: $("#clientfeedback").serialize(),
       		success: function(json) {
       			if (json.response[0].error == "") {
       				document.getElementById("clientfeedback").submit();
       			} else {
       				$("#cfb_sending").hide();
       				$("#cfb_error > p").text(json.response[0].error);
       				$("#cfb_error").show();
       			}
       		}
       	});
	 	return false;
	 });
	 

});
