﻿$(function(){
    initiateTopNav();
}); 

// submenu
function showLayer(whichdiv){
    $("#" + whichdiv.id+"Hover").toggle();
}

/*
===========================================
    Functions: Nav/ Sub Nav
===========================================
*/
var timeOutEnter;
var timeOutLeave;
var currentIndex =0;
var timeOut;


function navigationEnter()
{

    var index = $(this).closest("ul").find("li").index($(this).closest("li")) - 1;    
    var length = $(this).closest("ul").find("li").length - 3
    
    if (index == currentIndex)
    {
        clearTimeout(timeOutLeave)
        clearTimeout(timeOutEnter)
    }
    else
    {
        clearTimeout(timeOutEnter)
        timeOutEnter = setTimeout("showTopNavSub(" + index + "," + length +")", 250);
    }
}
//// New top Nav
function showTopMenuSub()
{
    if($(".nTopMenuSub").is(":visible"))
    {
        $(".nTopMenuSub").hide();
        hideTopMenuSub();
        return false;
    }
	$(".nTopMenuSub").show();
}

function hideTopMenuSub()
{
	$('.nTopMenuSub').hide();
    clearTimeout(timeOut);
}

/*
	 Top nav sub (categorieën) handlers
*/
function showTopNavSub(index, length)
{
	if(length == index)
	{
        $(".navSub").stop(true,true)
	                .slideUp('normal');	
	                
	    $(".navSubMeer")  .stop(true,true)
	                        .slideDown('slow');
	}
	else
	{
	    $(".navSub").eq(index)
	                .stop(true,true)
	                .slideDown('slow')
	                .siblings(".navSub, .navSubMeer")
	                .stop(true,true)
	                .slideUp('normal');
    	
	    // als hij niet bestaat
	    if($(".navSub").eq(index).length == 0)
		    $(".navSub, .navSubMeer").stop(true,true)
		                .slideUp('normal')
	}
	currentIndex = index
	$(".navigation ul li a").eq(currentIndex+1).addClass("active")
}

function hideTopNavSubReal()
{
	$('.navSub, .navSubMeer') .stop(true,true)
	                          .slideUp('normal');
	
	if (currentIndex != 0)
	{    
        $(".navigation ul li a").eq(currentIndex+1).removeClass("active")
    }
    
    currentIndex = 0
}
function initiateTopNav()
{
    $(".navigation li a").mouseenter(navigationEnter);
   
   $(".navigation li a").mouseleave(function () {clearTimeout(timeOutEnter); timeOutLeave = setTimeout("hideTopNavSubReal()", 249);});
   
    $(".nTopMenuSub").hide();
    
    $(".nTopMenu").mouseenter(function(){clearTimeout(timeOut);});
    $(".nTopMenu").click(showTopMenuSub);
    $(".nTopMenu").mouseleave(function(){timeOut = setTimeout('hideTopMenuSub()', 1000);});	
 
    $(".nTopMenuSub").mouseleave(function(){timeOut = setTimeout('hideTopMenuSub()', 1000);});	
	$(".nTopMenuSub").mouseenter(function(){clearTimeout(timeOut);});	
	
	$(".headerContact").mouseenter(function(){clearTimeout(timeOut);});
	$(".headerContact").mouseleave(function(){timeOut = setTimeout('hideTopMenuSub()', 1000);});

   $(".navSub").mouseleave(function () {clearTimeout(timeOutEnter);timeOutLeave = setTimeout("hideTopNavSubReal()", 249);});
   
   $('.navSub').mouseenter(function() { clearTimeout(timeOutLeave)});
}
/*
==================================
	Overige functies
==================================
*/
function checkInput(input, was, wordt){
	if(input.value==was){
		input.value=wordt;
	}
}
function NieuwsBriefFromHome() {
   parent.location.href = 'http://www.raamdecoratietotaalmarkt.nl/formulieren.aspx?form=nieuwsbrief&email=' + $("#email").val();
}




/*
==================================
	Correcte functies
==================================
*/

var TopMenuTimer;

$(function(){
   $(".footerMail").val($(".footerMail").attr("data-defaultvalue"));
   
   $(".footerMail").mouseenter(function() {
        clearInputText($(this));
   });
   $(".footerMail").focus(function() {
        clearInputText($(this));
   });
   
   $(".footerMail").mouseleave(function() {
        resetInitialText($(this));
   });
   $(".footerMail").blur(function() {
        resetInitialText($(this));
   });
    
   $(".footerMail").keyup(function (event) {
        if (event.keyCode == 13) {
            TriggerNewsletter();
        }
   });
   
   $(".footerMailButton").click(function () {
        TriggerNewsletter();
   });
});

function clearInputText(object) {
    var curValue = $(object).val();
    if (curValue == $(object).attr("data-defaultvalue")) {
        $(object).val('');
    }
}

function resetInitialText(object) {
    if ($(object).val() == '') {
        $(object).val($(object).attr("data-defaultvalue"));
    }
}

function TriggerNewsletter() {    
    if (($(".footerMail").val() != $(".footerMail").attr("data-defaultvalue")) && ($(".footerMail").val() != '')) {
        parent.location.href = '/F/Nieuwsbrief.aspx?email=' + $(".footerMail").val();
    }
}


