/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

/* timico */

var theHref="";
var cSuccess=false;
function redirectToPath(path) {
  window.location.href=path;
}

function checkDEmail(mail) {
	if (/^(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)$/i.test(mail)) {
		return true;
	} else {
		return false;
	}	
}

function checkDForm (field) {
	var errors=false;
	if (field) {
		if (field.val()=="") { field.parent().next().find(".dhint").show();field.parent().next().find(".dok").hide(); } else { field.parent().next().find(".dhint").hide();field.parent().next().find(".dok").show(); }
		if (field.attr("name")=="email") { if (checkDEmail(field.val())==false) { field.parent().next().find(".dhint").show();field.parent().next().find(".dok").hide(); } else { field.parent().next().find(".dhint").hide();field.parent().next().find(".dok").show(); } }
	} else {
	$("#dcaptureForm input.required").each(function() {
		if ($(this).val()=="") {
			$(this).parent().next().find(".dhint").show();
			$(this).parent().next().find(".dok").hide();
			errors=true;
		}
		if ($(this).attr("name")=="email") {
			if (checkDEmail($(this).val())==false) { $(this).parent().next().find(".dhint").show();$(this).parent().next().find(".dok").hide(); }
		}
	});
	}
	if (errors) { return false; }
	return true;
}

$(document).ready(function() {

	$("#menu ul li").hoverIntent({over:function() {
		$(this).children("ul").css("left","100%").fadeIn();
	},out:function () {
		$(this).children("ul").hide().css("left","-9999px");
	},timeout:300});

	$(".linkButtonBox.fullc").parent().parent().click(function() {
		document.location=$(this).find(".linkButtonBox a").attr("href");
	});
	$(".linkButtonJump2.fullc").parent().click(function() {
		document.location=$(this).find(".linkButtonJump2 a").attr("href");
	});

	$(".linkButtonBox.fullc").parent().parent().css('cursor','pointer');
	$(".linkButtonJump2.fullc").parent().css('cursor','pointer');
	
	$("#dcaptureForm input").keyup(function(e) {
		checkDForm($(this));
	});

  $("#dcaptureForm").submit(function(e) {
    e.preventDefault();
	$(".dhint").hide();
	$(".dok").show();
	if (checkDForm()) {
		$.ajax({
		url:'/controller/dcapture.php',
		type:"POST",
		data:"href="+theHref+"&"+$("#dcaptureForm").serialize(),
		success: function(data) {
		}
		});
		cSuccess=true;
		$.fancybox.close();
	}
  });

  $(".dcapture").bind("contextmenu",function(e){
    return false;
  });

  $(".dcapture").each(function() {
    $(this).attr("ohref",$(this).attr("href"));
	$(this).attr("href","");
  });

  $(".dcapture").click(function(e) {
    theHref=$(this).attr("ohref");
	e.preventDefault();
    $.ajax({
      url:'/controller/dcapture.php', 
      type:"POST",
      data:"c=1&href="+theHref,
	  dataType:"json",
      success: function(data) {
	    if (data.unknown) {
	      $.fancybox({
            'centerOnScroll' : true,
            'padding':0,
	        'overlayColor':'#ffffff',
	        'overlayOpacity':0.5,
	        'showCloseButton':false,
			'scrolling':'no',
            'href':"#dcaptureDiv",
	        'onClosed':function(h) {
			  if (cSuccess) { redirectToPath(theHref); }
	        }
          });
		} else { 
			redirectToPath(theHref);
		}
      },
	  error: function(data) {
	  }
    });
  });
});
