// JavaScript Document

var topSubTimer1;
var topSubTimer2;
var topSubTimer5;

var pageRating = 0;

/* tooltip */

$(document).ready(function(){
	 simple_tooltip("a.pointer","tooltip");
	 simple_tooltip(".shopList a","tooltip");
});

function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);

		if($(this).attr("title") != ""){ // checks if there is a title

		$(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
		}).mouseout(function(){
				my_tooltip.fadeOut(400);
		});

		}
	});
}

//Make the anchors in the inlinehtml controls green
$(document).ready(function() {
    $(".htmlDiv a").each(function() {
        $(this).addClass('greenNotBold');
    });
    $(".blockDescription a").each(function() {
        $(this).addClass('greenNotBold');
    });
    $("#divDescription a").each(function() {
        $(this).addClass('greenNotBold');
    });
    $("#divHtmlData a").each(function() {
        $(this).addClass('greenNotBold');
    });
});

$(document).ready(function() {
    $('#print').click(function() { printIt('leftColumn') });
    $('.emailLink').click(function() { showPopup() });
    $('#closePopup').click(function() { hidePopup() });
    //menuPosition();
    if (browserType() == 'MSIE' && IEvesion() != 8)
        $('div.topMenu li.home a').hover(
				function() {
				    $(this).find('img').css("top", -38);
				},
				function() {
				    $(this).find('img').css("top", 0);
				}
			);
    $('div.topMenu > ul > li').hover(
		function() {
		    if (!$(this).hasClass('home')) {
		        $(this).addClass('Hover').find('a:first').addClass('Hover');
		    }
		    $(this).find('ul:first').stop(true, true);
		    $(this).find('ul:first').slideDown(200);
		},
		function() {
		    $(this).find('ul:first').slideUp(100);
		    $(this).removeClass('Hover').find('a:first').removeClass('Hover');
		    Cufon.refresh();
		}
	);

    $("#lockDiv").height($(document).height()).hide();

    $("#emailArticleFormHolder td.l img, #emailArticleFormHolder td.r img").height($("#emailArticleFormHolder td.content").height() + 2);
    //$("#emailArticleFormHolder td.r img").height($("#emailArticleFormHolder td.content").height() + 2);

    $("#emailArticleFormHolder td.content div.pageHolder div.holder").html($("#leftColumn").html());
    $("#emailArticleFormHolder td.content div.pageHolder div.lockAll").height($("#leftColumn").height());
    if (!$.browser.msie) {
        $("#emailArticleFormHolder").fadeTo(0, 0);
        $("#emailArticleThanxHolder").fadeTo(0, 0);
    }
    $("#emailArticleFormHolder").hide();
    $("#emailArticleThanxHolder").hide();


    prepareCommentsFunctionality();
    addCommentFunctionality();

    $('div.leftColumn div.block').append('<div class="Clear"><!--  --></div>');
});

/*
$(window).resize(function(){
$("div.flashHolder").width($(window).width());
});
*/

$.fn.delay = function(time, callback) {
    jQuery.fx.step.delay = function() { };
    return this.animate({ delay: 1 }, time, callback);
}

function openSubMenu(objID) {
    $("#parent" + objID).css("background-position", "0px -38px");
    $("#sub" + objID).slideDown(200);
}

function closeSubMenu(objID) {
    if (!$("#parent" + objID).hasClass("selected")) $("#parent" + objID).css("background-position", "0px 0px");
    $("#sub" + objID).slideUp(100);
}

function openTab(tabLink, tabID) {
    $("div.tabsTitlesHolder > a").removeClass();
    tabLink.className = "selected";
    $("div.newsContent > div.news").hide();
    $("#tabContent" + tabID).show();
}

function checkInput(action, inputID, defaultText) {
    switch (action) {
        case "focus":
            if ($("#emailListOrder input")[0] == $("#" + inputID)[0]) $("#emailListOrder input").removeClass("notValid");
            if ($("#" + inputID).val() == defaultText) {
                $("#" + inputID).attr("value", "");
            }
            break;
        case "unfocus":
            if ($("#" + inputID).val() == "") {
                $("#" + inputID).attr("value", defaultText);
            }
            break;
    }
}

function openCommentForm(linkObj, scrollObj) {
    if ($("#" + linkObj).text() == "comment toevoegen [+]") {
        $("#" + linkObj).html("comment toevoegen [&ndash;]");
        if (scrollObj != null) {
            $.scrollTo($("#" + scrollObj), { duration: 500 });
        }
    } else {
        $("#" + linkObj).html("comment toevoegen [+]");
    }
    $("#addCommentHolder").slideToggle(300);
}

function rateThis(starID) {
    for (var i = 0; i < 5; i++) {
        if (i < starID) {
            $("#star" + i).removeClass().addClass("raitingStar");
        } else {
            $("#star" + i).removeClass().addClass("raitingStarNull");
        }
    }
}

function resetRate() {
    for (var i = 0; i < 5; i++) {
        if (i < pageRating) {
            $("#star" + i).removeClass().addClass("raitingStar");
        } else {
            $("#star" + i).removeClass().addClass("raitingStarNull");
        }
    }
}

function setupRating(starID) {
    pageRating = starID;
}

function quizSubmit() {
    if ($("input[name$='poll']:checked").length != 0) {
        $("div.quizHolder").hide();
        $("div.quizResults").show();
    }
}

var printwindow;

function printIt(contentId) {
    if (typeof (isfront) == "undefined" || isfront == null) isfront = false;
    contentTag = document.getElementById(contentId);
    printwindow = window.open("", null, "height=480,width=660,status=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,left=" + (screen.availWidth - 640) / 2 + ",top=" + (screen.availHeight - 480) / 2);
    printwindow.document.write('<html>');
    printwindow.document.write('<head>');
    printwindow.document.write('<title>');
    printwindow.document.write(printTitle);
    printwindow.document.write('</title>');
    printwindow.document.write(cssLinks);
    printwindow.document.write('</head>');
    printwindow.document.write('<body onLoad="window.opener.printMove();">');
    printwindow.document.write('<div id="printDiv" style="width:640px; margin:10px;">');
    printwindow.document.write('</div>');
    printwindow.document.write('</body>');
    printwindow.document.write('</html>');
    printwindow.document.close();
    return true;
}

function printMove() {
    printwindow.document.getElementById('printDiv').innerHTML = contentTag.innerHTML;
    printwindow.focus();
    printwindow.print();
}

function browserType() {
    var agent = navigator.userAgent;
    var browser;
    if (agent.lastIndexOf('MSIE') != -1) browser = 'MSIE';
    else if (agent.lastIndexOf('Firefox') != -1) browser = 'Firefox';
    else if (agent.lastIndexOf('Safari') != -1) browser = 'Safari';
    else if (agent.lastIndexOf('Opera') != -1) browser = 'Opera';
    else browser = 'Unknown';

    return browser;
}

function IEvesion() {
    var agent = navigator.userAgent;
    var version;
    if (agent.lastIndexOf('MSIE') != -1) {
        if (agent.lastIndexOf('MSIE 8.0') != -1) version = 8;
        if (agent.lastIndexOf('MSIE 7.0') != -1) version = 7;
        if (agent.lastIndexOf('MSIE 6.0') != -1) version = 6;
        if (agent.lastIndexOf('MSIE 5.5') != -1) version = 55;
        if (agent.lastIndexOf('MSIE 5.0') != -1) version = 5;
    }
    return version;
}

function menuPosition() {
    if (browserType() == 'MSIE' && IEvesion() != 8)
        $('a.topMenu .over').css('top', '-18px');
}

function showPopup() {
    $('#coverDiv').css('display', 'block');
    $('#popupEmail').css('display', 'block');

    var h = $('.copyrightDiv').attr('offsetTop') + $('.copyrightDiv').attr('offsetHeight');
    var w = $('body').attr('scrollWidth');

    $('#coverDiv').css('height', h + 'px');
    $('#coverDiv').css('width', w + 'px');


    $('#popupEmail').css('left', (w - $('#popupEmail').width()) / 2 + 'px');
    $('#popupEmail .popupContent_inner').html($('.leftColumn > div').html());
    $('#popupEmail .popupContent_inner > div:last').css('display', 'none');
}

function hidePopup() {
    $('#coverDiv').css('display', 'none');
    $('#popupEmail').css('display', 'none');
}

function openEmailForm() {

    /* [v.burilko 21.02.2011] HBS-57869 Bug: Contact form POP-UP */
    $("#emailArticleFormHolder").css("visibility", "visible");

    if ($.browser.msie) {
        $("#lockDiv").show();
        $("#emailArticleFormHolder").show();
        $("#emailArticleFormHolder td.content div.pageHolder div.lockAll").animate({ height: $("#leftColumn").height() + "px" }, 10);
    } else {
        $("#lockDiv").show().fadeTo(300, 0.5);
        $("#emailArticleFormHolder").delay(300, function() {
            $(this).show().fadeTo(300, 1);
        });
    }
    $.scrollTo($("body"), { duration: 300 });
}

function sendEmailForm() {
    $("#emailArticleFormHolder div.inputItem p").removeClass("notValid");
    $("#emailArticleFormHolder div.textareaItem p").removeClass("notValid");
    $("#emailArticleFormHolder p.validationAlert").hide();

    var isError = false;

    $("#emailArticleFormHolder div.inputItem input").each(function() {
        if ($.trim($(this).val()) == "") {
            $(this).parents("div.inputItem").find("p").addClass("notValid");
            isError = true;
        }
        if ($(this).attr("name").toLowerCase().indexOf("email") > -1) {
            if ($.trim($(this).val()).split("@").length > 1) {
                if ($.trim($(this).val()).split("@")[1].split(".").length == 1) {
                    $(this).parents("div.inputItem").find("p").addClass("notValid");
                    isError = true;
                }
            } else {
                $(this).parents("div.inputItem").find("p").addClass("notValid");
                isError = true;
            }
        }
    });

    if (jQuery.trim($("#emailArticleFormHolder div.textareaItem textarea").val()) == "") {
        $("#emailArticleFormHolder div.textareaItem p").addClass("notValid");
        isError = true;
    }

    if (isError) {
        $("#emailArticleFormHolder p.validationAlert").show();
        return false;
    }

    //[v.burilko 21.02.2011] HBS-57869 Bug: Contact form POP-UP 
    $("#emailArticleThanxHolder").css("visibility", "visible");

    if ($.browser.msie) {
        $("#emailArticleThanxHolder").show();
        $("#emailArticleFormHolder").hide();
    } else {
        $("#emailArticleThanxHolder").show().fadeTo(100, 1);
        $("#emailArticleFormHolder").fadeTo(100, 0, function() { $(this).hide() });
    }
}

function closeEmailForm() {
    $("#emailArticleFormHolder div.inputItem p").removeClass("notValid");
    $("#emailArticleFormHolder div.textareaItem p").removeClass("notValid");
    $("#emailArticleFormHolder p.validationAlert").hide();

    if ($.browser.msie) {
        $("#lockDiv").hide();
        $("#emailArticleFormHolder").hide();
    } else {
        $("#lockDiv").fadeTo(100, 0, function() { $(this).hide() });
        $("#emailArticleFormHolder").fadeTo(100, 0, function() { $(this).hide() });
    }
}

function closeThanxHolder() {
    if ($.browser.msie) {
        $("#lockDiv").hide();
        $("#emailArticleThanxHolder").hide();
    } else {
        $("#lockDiv").fadeTo(100, 0, function() { $(this).hide() });
        $("#emailArticleThanxHolder").fadeTo(100, 0, function() { $(this).hide() });
    }
}

function goToSearchResults(e) {
    var keynum;

    if (window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    if (keynum == 13) document.location.href = "search_results.html";
}

function emailListSend() {
    if ($.trim($("#emailListOrder input").val()).split("@").length > 1) {
        if ($.trim($("#emailListOrder input").val()).split("@")[1].split(".").length == 1) {
            $("#emailListOrder input").addClass("notValid");
            return;
        }
    } else {
        $("#emailListOrder input").addClass("notValid");
        return;
    }
    $("#emailListOrder").hide();
    $("#emailListSentOk").show();
    $("#emailListOrder").delay(5000, function() {
        $(this).show();
        $("#emailListSentOk").hide();
    });
}

function prepareCommentsFunctionality() {
    var commentsTotal = $("#leftColumn div.commentsHolder div.item").length;

    var commentsArray = new Array();
    for (var i = 0; i < commentsTotal; i++) {
        commentsArray[i] = 3;
    }

    var linkId = 0;

    $("#leftColumn div.commentsHolder div.item div.cloudHolder div.content div.title div.right a").each(
		function(i) {
		    $(this).bind("click", function() {
		        commentsArray[i]--;
		        if (commentsArray[i] == 0) {
		            $(this).parents("div.item").slideUp(200);
		        }
		    })
		}
	);
}

function addCommentFunctionality() {
    $("#leftColumn form[name=addComment] button").bind("click", function() {
        var commentItem = '<div class="item" style="display:none;"><div class="author"><b>' + $("#leftColumn input[name=comNaam]").val() + '</b><span>' + $("#leftColumn input[name=comStad]").val() + '</span><span>' + $("#leftColumn input[name=comWebsite]").val() + '</span><span>28-12-2008</span></div><div class="cloudHolder"><div class="top"></div><div class="content"><div class="title"><div class="left"></div><div class="right"><a href="javascript:void(0)">Dit is niet ok</a></div>New comment</div><div class="comment"><div class="left"></div><div class="right"></div>' + $("#leftColumn textarea[name=jouwcomment]").val() + '</div></div><div class="bottom"></div><div class="corner"></div></div><div class="Clear"></div></div>';
        $("#leftColumn div.commentsHolder").prepend(commentItem);
        $("#leftColumn div.commentsHolder div.item:first").slideDown(300);
    });
}

function validateForm1() {
    $("table.contactFormulierTable td.forTA").removeClass("notValid");
    $("table.contactFormulierTable td.title").removeClass("notValid");
    $("table.contactFormulierTable p.validationAlert").hide();

    var noError = false;

    $("table.contactFormulierTable input").each(function() {
        if (jQuery.trim($(this).val()) == "") {
            $(this).parents("td:first").prev("td.title").addClass("notValid");
            noError = true;
        }
        if ($(this).attr("name").toLowerCase().indexOf("email") > -1) {
            if ($.trim($(this).val()).split("@").length > 1) {
                if ($.trim($(this).val()).split("@")[1].split(".").length == 1) {
                    $(this).parents("div.inputItem").find("p").addClass("notValid");
                    isError = true;
                }
            } else {
                $(this).parents("div.inputItem").find("p").addClass("notValid");
                isError = true;
            }
        }
    });

    if (jQuery.trim($("table.contactFormulierTable textarea").val()) == "") {
        $("table.contactFormulierTable td.forTA").addClass("notValid");
        noError = true;
    }

    if (noError) {
        $("table.contactFormulierTable p.validationAlert").show();
        return false;
    }
}

$(document).ready(function(){
    if ($('.shopList').length != 0) {
        $('.shopList li').each(function(){
            $(this).DupeHref();     
        }); 
    }
    else { 

    }
});

jQuery.fn.DupeHref =  function(){                    
    var letterShop = $(this).find("a span").text();  
    var target = $(this).find("a").attr("href");     
    var $mapContainer = $('div.mapContainer');
 
    $('a', $mapContainer).each(function(){
        if ($(this).attr('title') == letterShop){
            $(this).attr("href", target);
        }
    });
}





