/********************************************************************************************
pop overlay v0.03
********************************************************************************************/
var overlay = $("<div id='overlay'></div>");

$(document).ready(function() {
	clickBoom();
	formHover();

$('#contact_close, #close_it').click(function(){ //click close form
	formClose();
});

document.onkeydown = function(e){ //escape close form
  if (e == null) { // za ie
    keycode = event.keyCode;
  } else { // za ffox
    keycode = e.which;
  }
  if(keycode == 27){
    formClose();
		}
}

  $(".click_submit").click(function(){
  	validate();
	});
});

/********************************************************************************************
show pop
********************************************************************************************/
function clickBoom() {
$(".click_boom").click(function(){
  if (typeof document.body.style.maxHeight === "undefined") { //if IE 6
    $("body","html").css({height: "100%", width: "100%"});
}
			$("body").append(overlay.click(function() { formClose(); }))
    	var offsetx = $("#rules").width() / 2;
			overlay.css("opacity", 0.7);
			overlay.css("z-index", 10);
	    overlay.fadeIn("fast", function(){
		 	$("#rules").css("left", ( $(window).width() / 2 - 25 - offsetx + "px"));
			$("#rules").show();
    });
});

$('#rules').click(function(e) {
		e.stopPropagation();
		});
}
/********************************************************************************************
close pop
********************************************************************************************/
function formClose(){
		$('#msg_success').hide();
		$('#rules').hide();
		$("#form_wrap").show();
		$("#msg").hide();
    $("#contact_form ul li").removeClass("error");
		overlay.fadeOut("fast", function(){
		overlay.remove();
		});

}
/********************************************************************************************
hover Form
********************************************************************************************/
function formHover() {
    $("#contact_form input, #contact_form textarea, #contact_form select").focus(function(){
        $(this).parent("li").addClass("on");
    }).blur(function(){
        $(this).parent("li").removeClass("on");
    });
}
/********************************************************************************************
peglaj visinu
********************************************************************************************/
function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
/********************************************************************************************
scroluj
********************************************************************************************/
jQuery.fn.extend({
  scrollTo : function(speed, easing) {
    return this.each(function() {
      var targetOffset = $(this).offset().top;
      $('html,body').animate({scrollTop: targetOffset}, speed, easing);
    });
  }
});