// JavaScript Document
$(function(){
	$("a[rel='newtab']").click(function(){
		window.open(this.href);
		return false;
	});
});

function tip(){
	$("#tudta > p").html('<img src="/img/load.gif" alt="Lekérés..." style="margin-top:20px; margin-left:20px;" />');
	$.post('/action/ajax.php',{action:'tip'},function(data){
		$("#tudta > p").html(data);
	});
}

$(document).ready(function(){
	$("#map_canvas").html('<iframe width="260" height="150" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=hu&amp;msa=0&amp;msid=112468309240155462426.00046bed90b34c902f9dc&amp;ll=47.591346,17.094727&amp;spn=0.5557,1.422729&amp;z=8&amp;output=embed"></iframe>');
	
	tip();
	
	$("a[rel='cbox']").colorbox();
	
	$("#status").hide();
	$("#send").click(function(){
		$("#status").html('<img src="/img/form-load.gif" alt="" />');
		$("#ajanlat-form").css('opacity',0.3);
		$("#status").show();
		
		var nev = $("#nev").val();
		var mail = $("#mail").val();
		var cnev = $("#cnev").val();
		var mire = $("#mire").html();
		var tel = $("#tel").val();
		var mennyi = $("#mennyi").html();
		var text = $("textarea").val();
		
		$.post('/action/ajax.php',{action:'contact', nev:nev, mail:mail, cnev:cnev, mire:mire, tel:tel, mennyi:mennyi, text:text},function(data){
			$("#status").html(data);
			if(data=='<b>Köszönjük, hamarosan válaszolunk!</b><br /><br /><p style="text-align:center;"><small>Kattintásra tovább...</small></p>'){
					$("#nev").val('');
					$("#mail").val('');
					$("#cnev").val('');
					$("#mire").html('[kérjük válasszon]');
					$("#tel").val('');
					$("#mennyi").html('[kérjük válasszon]');
					$("textarea").val('');
				}
		});

	});
	$("#status").click(function(){
		$("#status").hide();
		$("#ajanlat-form").css('opacity',1);
	});
	
	$('#menu > a > span').css('visibility','hidden');
	$("#links").hide();
	
	$('#menu > a').mouseover(function(){
		$(this).children().css('visibility','visible');
	})
	
	$('#menu > a').mouseout(function(){
		$(this).children().css('visibility','hidden');
	})
	
	$('#egyeb').click(function(){
		var w = $("#links").width();
		if(w==0){
			$("#egyeb").animate({"width": "+=605px"}, "slow", function(){
				$("#links").animate({"width": "+=600px"}, "slow");
				$("#links > *").show();
				$("#links").css('padding-left','5px');
			});
			$("#left").css('background-image','none');
			$("#left > img").attr('src','/img/right-nyil.png');
		}else{
			$("#links").animate({"width": "-=600px"}, "slow", function(){
				$("#egyeb").animate({"width": "-=605px"}, "slow");
				$("#links > *").hide();
				$("#links").css('padding-left','0px');
				$("#left").css('background-image','url(../img/egyeb-left.png)');
				$("#left > img").attr('src','/img/left-nyil.png');
			});
		}
	})
	
	//domain select
	$("#domains").hide();
	$("#value").click(function(){
		$("#domains").show();
	});
	$("#domains > span").click(function(){
		var val = $(this).html();
		$("#value").html(val);
		$("#domains").hide();
	});

	//form select
	$(".values").hide();
	$(".value").click(function(){
		$(this).next(".values").show();
	});
	$(".values > span").click(function(){
		$(this).parent().prev(".value").html($(this).html());
		$(".values").hide();
	});

	$("#check").click(function(){
		$("#domain > p").html('<img src="/img/load.gif" alt="Ellenőrzés..." style="margin-top:10px; margin-left:20px;" />');
		var domain = $("#domain > input:text").val();
		var veg = $("#value").html();
		$.post('/action/ajax.php',{action:'check',domain:domain,veg:veg},function(data){
			$("#domain > p").html(data);
		});
	});

	$("#new").click(function(){
		tip();
	});

	$("#callback").click(function(){
		if($(this).css('left')=='0px'){
			$(this).animate({left:'215px'},500);
			$("#callbackform").animate({left:'0px'},500);
		}else{
			$(this).animate({left:'0px'},500);
			$("#callbackform").animate({left:'-215px'},500);		
		}
	});
	
	$("#callbackform > img").click(function(){
		var nev = $("#callbackform > input:eq(0)").val();
		var tel = $("#callbackform > input:eq(1)").val();
		
		if(nev!=='' && tel!==''){
		$.post('/action/ajax.php',{action:'callback', nev:nev, tel:tel },function(data){

			$("#callbackform > *").fadeOut('fast',function(){
				$("#callbackform").html('<p>Köszönjük!<br />Hamarosan hívni fogjuk!</p>').delay(1500);
				$("#callbackform").animate({left:'-215px'},500);		
				$("#callback").animate({left:'0px'},500);
			});
			
		});
		}else{
			$("#callbackform").animate({left:'-215px'},500);		
			$("#callback").animate({left:'0px'},500);
		}
	});

	$(".ref-img[title]").tooltip({
		tip:'#tip',
		position:'top center',
		offset:[-80,-130]
	}); 
})

$(function() {
	$("#jcar").jCarouselLite({
		visible: 1,
		auto:3000,
		speed:700
	});
});

/*
function modalbox(){
	function boxclose(){
		$("#modalbox").animate({'height':'0px'},'slow',function(){
			$('#modalwrap').fadeOut(500);
		});
	}
	var height = $(document).height();
	$('<div id="modalwrap"></div>').prependTo("body");
	$('#modalwrap').css({backgroundColor:'#000',width:'100%',height:height,position:'absolute','z-index':100,opacity:0});
	
	$('#modalwrap').click(function(){
		boxclose();
	});

	$('<div id="modalbox"></div>').prependTo("body");
	var width = $(document).width();
	var left = (width/2);
	left = left-(500/2);
	$('#modalbox').css({backgroundColor:'#fff',width:'500px',height:'0px',position:'fixed','z-index':110,top:0,left:left});

	$('#modalwrap').fadeTo(500,0.8,function(){
		$("#modalbox").animate({'height':'300px'},'slow');
	});
}
*/

