$(document).ready(function() {
	anchor.init();
			
	$(".roll1").animate({"bottom": "+=390px"}, "slow");
	$(".roll2").animate({"bottom": "+=400px"}, "slow");
	$(".roll3").animate({"bottom": "+=400px"}, "slow");
	$("#star-3d").animate({"bottom": "-=525px"}, "slow");
	$("#menu").animate({"bottom": "+=320px"}, "slow");
	$("#menu2").animate({"bottom": "+=550px"}, "slow");
	$("#tel").animate({"left": "+=44px"}, "slow");
	$("#mail").animate({"left": "+=44px"}, "slow");
	$("#home").animate({"left": "+=44px"}, "slow");
	//$("#stars").fadeIn("slow");
	//$("body").fadeIn(500);

	
	$("#tel").mouseover(function(){
		$(this).animate({"left": "+=257px"}, "fast");
	});
	$("#tel").mouseout(function(){
		$(this).animate({"left": "-=257px"}, 1000);
	});

	$("#mail").mouseover(function(){
		$(this).animate({"left": "+=277px"}, "fast");
	});
	$("#mail").mouseout(function(){
		$(this).animate({"left": "-=277px"}, 1000);
	});
	
	$("#info").mouseover(function(){
		$(this).animate({"left": "+=50px"}, "fast");
	});
	$("#info").mouseout(function(){
		$(this).animate({"left": "-=50px"}, 500);
	});
	
	$("#services").mouseover(function(){
		$(this).animate({"left": "+=50px"}, "fast");
	});
	$("#services").mouseout(function(){
		$(this).animate({"left": "-=50px"}, 500);
	});	
	
	$("#referencies").mouseover(function(){
		$(this).animate({"left": "+=50px"}, "fast");
	});
	$("#referencies").mouseout(function(){
		$(this).animate({"left": "-=50px"}, 500);
	});	
	
	$("#contact").mouseover(function(){
		$(this).animate({"left": "+=50px"}, "fast");
	});
	$("#contact").mouseout(function(){
		$(this).animate({"left": "-=50px"}, 500);
	});	
	
	$("#career").mouseover(function(){
		$(this).animate({"left": "+=30px"}, "fast");
	});
	$("#career").mouseout(function(){
		$(this).animate({"left": "-=30px"}, 500);
	});
		
	$("#tutorials").mouseover(function(){
		$(this).animate({"left": "+=30px"}, "fast");
	});
	$("#tutorials").mouseout(function(){
		$(this).animate({"left": "-=30px"}, 500);
	});
	
	$(function(){
		$('a.out').click(function(){
			window.open(this.href);
			return false;
		});
	});
});

//görgető
anchor = {
	init : function()  {
		$("a.anchor").click(function () {	
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top-200;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 2000 );
		  	return false;
		})
	}
}

//preview 
this.imagePreview = function(){	
		
	xOffset = -550;
	yOffset = -200;
		
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.getElementsByTagName("input")[0].value +"' alt='Kép betöltése...' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY + yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.css("z-index","100")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY + yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
	
	$("#webmelo").hide();
	$("#adatok").hide();
	$("#quest > p").hide();
	
});

$(function() {
	$(".cont").jCarouselLite({
		btnNext: "#next",
		btnPrev: "#prev",
		visible: 1,
		auto: 10000,
		speed: 1000
	});
});


function ajanlat(id){
	$("#adatok").slideUp('fast');

	var head;
	if(id=='weboldal'){
		head = "weboldal készítés";
		$("#webmelo").slideDown('fast');
	}else{
		$("#webmelo").slideUp('fast');
	}
	if(id=='3D'){
		head = "3D látványterv készítés";
	}
	if(id=='arculat'){
		head = "céges arculat tervezés";
	}
	if(id=='kiadvány'){
		head = "kiadvány készítés";
	}
	
	$("#melo-head").html(head);
	$("#adatok").slideDown('fast');
	$("#melo").val(id);

}

var chars = ' ';

function ltrim(str) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function trim(str) {
	return ltrim(rtrim(str, chars), chars);
}

function ajanlat_ker(){
	var modulok = $("input:checkbox");
	var sum = modulok.length;
	
	var moduls = new Array();
	for(i=0; i<sum; i++){
		if(modulok[i].checked){
		moduls.push(modulok[i].value); }
	}
	
	var text = $("#text").val();
	var nev = $("#nev").val();
	var cegnev = $("#cegnev").val();
	var beosztas = $("#beosztas").val();
	var telefon = $("#telefon").val();
	var mobil = $("#mobil").val();
	var email = $("#email").val();
	var melo = $("#melo").val();
	var captcha = $("#captcha").val();
	var hiba = '';
	
	if(trim(nev)==''){
		hiba += 'Név megadása kötelező!\r\n';
	}
	if(trim(email)==''){
		hiba += 'E-mail megadása kötelező!\r\n';
	}
	if(trim(telefon)==''){
		if(trim(mobil)==''){
			hiba += 'Telefon vagy mobil szám megadása kötelező!\r\n';
		}
	}
	if(trim(captcha)==''){
		hiba += 'Ellenőrző kód szükséges!';
	}
	
	if(hiba!==''){
		alert(hiba);
	}else{
	
		$.post("/functions/ajax.php", { action: 'newcontact', nev:nev, cegnev:cegnev, beosztas:beosztas, text:text, telefon:telefon, mobil:mobil, email:email, melo:melo, 'moduls[]':moduls, captcha:captcha }, function(data){
			if(data=='captcha'){
				alert('Hibás ellenőrző kód!');
			}else{
				if(data=='ok'){
					if(melo=='weboldal'){
						$("#webmelo").slideUp('fast');
					}
					$("#adatok").slideUp('fast');
					$("#quest").slideDown('fast');
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: $('body').offset().top-200}, 2000 );
					$("#quest > p").show();

					$("#text").val('');
					$("#nev").val('');
					$("#cegnev").val('');
					$("#beosztas").val('');
					$("#telefon").val('');
					$("#mobil").val('');
					$("#email").val('');
					$("#melo").val('');
					$("#captcha").val('');
					$("input:checkbox").removeAttr("checked");

				}
			}
		});

	}
}