$(document).ready(function() {

    //$(".taletid .image a").css("margin-top", (100-$(this+" .simage".height()))/2+"px");

    $(".taletid .image").find("a").each(function(i) {
        $(this).css("margin-top", (100-$(this).children(".simage").height())/2);
    });
    $(".listtelephonewrapper .image").find("a").each(function(i) {
        $(this).css("margin-top", (100-$(this).children(".simage").height())/2);
    });
    $(".bdealers .de .dealerimg").find("a").each(function(i) {
        $(this).css("margin-top", (60-$(this).children("img").height())/2);
    });
    $(".largeimage").find("a").each(function(i) {
        $(this).css("margin-top", (200-$(this).children("img").css("height").replace("px",""))/2);
    });
    $(".plargeimage").find("a").each(function(i) {
        $(this).css("margin-top", (200-$(this).children("img").css("height").replace("px",""))/2);
    });
    $(".focusimage").find("a").each(function(i) {
        $(this).css("margin-top", (100-$(this).children("img").css("height").replace("px",""))/2);
    });
    $(".bredband .image").find("a").each(function(i) {
        $(this).css("margin-top", (100-$(this).children("img").height())/2);
    });
    $(".dealername").find("a").each(function(i) {
        $(this).css("margin-top", (100-$(this).children("img").height())/2);
    });

//    console.log($(".taletid .image a .simage").height());
//    $(".taletid .image a").css("margin-top", $(this).children(".simage").css("height")+"px");
//    $(".taletid .image a").css("margin-top", "20px");

    $("#footerlist .tablewrapper").columnize({lastNeverTallest: true, width: 208});

    $('a').click(function(){
        if (this.href.match(/display.php/)) {
            window.open(this.href);
            return false;
        }
        if (this.href.match(/goto.php/)) {
            window.open(this.href);
            return false;
        }
        if (this.href.match(/^(^\/)/)) {
            window.open(this.href);
            return false;
        }
        
    });

    $(".addnews").click( function(e) {
        $("#overlay").css("height", (document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px');
        $("#newsletter").show();
        $("#overlay").show();
    });

    $(".closebtn").click(function(e) {
        $("#overlay").click();
    });

    $("#overlay").click( function(e) {
        $("#newsletter").hide();
        $("#overlay").hide();
    });

    $("#searchbutton").click( function(e) {
        $("#searchform").submit();
    });

    $(".image").mouseenter( function (e) {
        $(".largeimage").hide();
        $(this).parent().children(".largeimage").show(); 
        $(this).parent().parent().children(".largeimage").show(); 
    });
    $(".image").mouseleave( function (e) {
        $(".largeimage").hide();
    });
    $(".pimage").mouseenter( function (e) {
        $(".plargeimage").hide();
        $(this).parent().children(".plargeimage").show(); 
        $(this).parent().parent().children(".plargeimage").show(); 
    });
    $(".pimage").mouseleave( function (e) {
        $(".plargeimage").hide();
    });
    /*
    $(".simage").mouseenter( function (e) {
        $(".largeimage").hide();
        $(this).parent().parent().children(".largeimage").show(); 
        $(this).parent().parent().parent().children(".largeimage").show(); 
    });
    */
    /*
    $(".simage").mouseleave( function (e) {
        $(".largeimage").hide();
    });
    */
    $(".largeimage").mouseleave( function (e) {
        $(this).hide();
        $(this).parent().parent().children(".largeimage").hide(); 
        $(this).parent().parent().parent().children(".largeimage").hide(); 
    });
    /*
    $(".simage").mousemove( function (e) {
        $(this).parent().parent().parent().children(".largeimage").css('top', e.clientY+10).css('left', e.clientX+10);
    });
    */
    /*
    $(".simage").mouseleave( function (e) {
        $(this).parent().parent().children(".largeimage").hide(); 
        $(this).parent().parent().parent().children(".largeimage").hide(); 
    });
    */
/*
    $(".email").focusout( function (e) {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = $(this).val();
        if (reg.test(address) == false) {
            alert("Indtast en gyldig emailadresse");
            $(".pricesubmit").hide();
            $(this).focus();
        } else {
            $(".pricesubmit").show();
        }
    });    
*/
    $(".goleft").click( function(e) {
        var $active = $(".active");
        var $next = $active.prev().length ? $active.prev() : $(".focusitem:last");

        $active.removeClass('active');
        $active.addClass('notactive');
        $next.addClass('active');
        $next.removeClass('notactive');
    });

    $(".goright").click( function(e) {
        var $active = $(".active");
        var $next = $active.next().length ? $active.next() : $(".focusitem:first");

        $active.removeClass('active');
        $active.addClass('notactive');
        $next.addClass('active');
        $next.removeClass('notactive');
    });

});

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}
