﻿$('span.mailme').each(function() {
    //    var at = / at /;
    //    var dot = / dot /;
    //    var dot = / dot /;
    //    var addr = $(this).text().replace(at, "@").replace(dot, ".");
    var addr = $(this).text().split(",")[0] + '@' + $(this).text().split(",")[1] + '.' + $(this).text().split(",")[2];
    var displayedText = $(this).text().split(",")[3];
    $(this).after('<a href="mailto:' + addr + '">' + displayedText + '</a>');
    //.hover(function() { window.status = "Send a letter!"; }, function() { window.status = ""; });
    $(this).remove();
});

$('a').click(function(event) {
    var url = $(this).attr("href");
    ReloadLocationComplete(url, false, event);
})

//$('a').click(function(event) {
//    var url = $(this).attr("href");
//    if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
//        $("body", "html").css({ height: "100%", width: "100%" });
//        $("html").css("overflow", "hidden");

//        //if (document.getElementById("akBoxHideSelect") === null) {//iframe to hide select elements in ie6
//        $("body").append("<iframe class='akBoxHideSelectClass' id='akBoxHideSelect'></iframe><div class='akBoxOverlayClass akBoxOverlayBg' id='akBoxOverlay'></div>");
//        //}
//    } else {//all others
//        //if (document.getElementById("akBoxOverlay") === null) {
//        $("body").append("<div class='akBoxOverlayClass akBoxOverlayBg' id='akBoxOverlay' style='opacity: 0.1'></div>");
//        //}
//    }

//    var d = getWindowDimensions();
//    var top = d.height / 2 - 100 / 2;
//    var left = d.width / 2 - 100 / 2;

//    $("body").append('<div style="position: fixed; top: ' + top + 'px; left: ' + left + 'px;width:100px;height:100px"><img src="/images/ajax-loader_big.gif" alt="" /></div>');

//    /*if (detectMacXFF()) {
//    overlay.addClass("akBoxOverlayMacFFBGHack"); //use png overlay so hide flash
//    } else {
//    overlay.addClass("akBoxOverlayBg"); //use background and opacity
//    }*/


//}
//)

function getWindowDimensions() {
    var dimensions = {};
    if (typeof (window.innerWidth) == 'number') {//Non-IE
        dimensions.height = window.innerHeight;
        dimensions.width = window.innerWidth;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {//IE 6+ in 'standards compliant mode'
        dimensions.height = document.documentElement.clientHeight;
        dimensions.width = document.documentElement.clientWidth;  
    }
    return dimensions;
}


/* Search field */
var searchFieldDefault = $('input[name=searchField]').val();
$('input[name=searchField]').focus(function() {
    if ($(this).val() == searchFieldDefault || $(this).val() == '') {
        $(this).val('');
    }
}).blur(function() {
    if ($(this).val() == '') {
        $(this).val(searchFieldDefault);
    }
});



/* Newsletter field */
var newsletterFieldDefault = $('input[name=newsletter]').val();
$('input[name=newsletter]').focus(function() {
    if ($(this).val() == newsletterFieldDefault || $(this).val() == '') {
        $(this).val('');
    }
}).blur(function() {
    if ($(this).val() == '') {
        $(this).val(newsletterFieldDefault);
    }
});



/* Detail search field */
var detailFieldDefault = $('input[name=detailSearch]').val();
$('input[name=detailSearch]').focus(function() {
    if ($(this).val() == detailFieldDefault || $(this).val() == '') {
        $(this).val('');
    }
}).blur(function() {
    if ($(this).val() == '') {
        $(this).val(detailFieldDefault);
    }
});



/* Menu top */
var menuTopOld = false;
$('#header .menuTop .item').hover(function() {
if (!$(this).hasClass('orange') && !$(this).hasClass('red') && !$(this).hasClass('selected')) {
        menuTopOld = $(this).attr('class');
        $(this).attr('class', 'item over');
    }
    else {
        menuTopOld = false;
    }
}, function() {
    if (menuTopOld) {
        $(this).attr('class', menuTopOld);
    }
});


/* Back to top */
$('.backToTop a').click(function(e) {
    e.preventDefault();
    $('html,body').animate({ 'scrollTop': '0px' });
});


/* Basket button */
$('.searchBox .basket button').hover(function() {
    $(this).addClass('hover');
}, function() {
    $(this).removeClass('hover');
});


/* All category */

var allCategoryP = false;

$('.leftColumn .title.all').click(function() {
    if (!allCategoryP) {
        $('.menuLeft.all').css({ top: $(this).position().top + 25 }).show();
        allCategoryP = true;
    }

    if ($(this).hasClass('down')) {
        $(this).removeClass('down').addClass('up');
        $('.menuLeft.all').show();
    }
    else {
        $(this).removeClass('up').addClass('down');
        $('.menuLeft.all').hide();
    }
});

$('.menuLeft.all').hover(function() { }, function() {
    $(this).hide();
    $('.leftColumn .title .arrow').removeClass('up').addClass('down');
});


$('.filterBox .dropdownList .title').click(function() {
    if ($(this).hasClass('close')) {
        $(this).parent().hide();
    }
    else {
        var p = $(this).position();
        $(this).next().css({ top: p.top, left: p.left - 6 }).show();
    }
});

/*$('.filterBox .dropdownList .list .item a').click(function (){
$(this).parent().parent().hide();
});*/


// template checkout
$('.report input[name=deliveryAddress]').click(function() {
    var div = $(this).parent().next();
    if (div.hasClass('hidden')) {
        div.removeClass('hidden');
    }
    else {
        div.addClass('hidden');
    }
});

// template myAccount
$('.textContent input[name=deliveryAddress]').click(function() {
    var div = $(this).parent().parent().next();
    if (div.hasClass('hidden')) {
        div.removeClass('hidden');
    }
    else {
        div.addClass('hidden');
    }
});

/* Advanced search */
$('#advancedSearchButton a').click(function() {
    $('.advancedSearchBox').toggle();
});

$('.advancedSearchBox .close a').click(function() {
    $('.advancedSearchBox').toggle();
});


/* Text tab bar */
var selectedTab = false;
$('.textTabBar .item').hover(function() {
    if (!$(this).hasClass('on')) {
        $(this).addClass('on');
    }
    else {
        selectedTab = true;
    }
}, function() {
    if (!selectedTab) {
        $(this).removeClass('on');
    }
    else {
        selectedTab = false;
    }
});


/* My order Page tables */

$('.textContent table td.arrow div').click(function() {
    if ($(this).parent().hasClass('down')) {
        $(this).parent().removeClass('down').addClass('up');
        $(this).parent().parent().children('td[class!=arrow up]').children('div').show();
    }
    else {
        $(this).parent().removeClass('up').addClass('down');
        $(this).parent().parent().children('td[class!=arrow down]').children('div').hide();
    }
});

function adaptColumn() {
    if ($.browser.msie && $.browser.version < 7) {
        return;
    }
    else
    {
        var leftColumn = $('#content .leftColumn');
        var rightColumn = $('#content .rightColumn');
        var centerColumn = $('#content .centerColumn');
        
        if (leftColumn.height() > centerColumn.height()) {
            centerColumn.css('height', leftColumn.height());
        }
        if (rightColumn.height() > centerColumn.height()) {
            centerColumn.css('height', rightColumn.height());
        }
    }
}