// replace fonts (cufon)
Cufon.replace('#menu .menu-option .title a', { fontFamily: 'ATRotisSemiSans-ExtraBold', hover: true });
Cufon.replace('#accordion h3.accordion-bar a', { fontFamily: 'ATRotisSemiSans-ExtraBold' });
if (!(jQuery.browser.msie && jQuery.browser.version < 7)) {
	Cufon.replace('.content-order .nodes .label', { fontFamily: 'ATRotisSemiSans-ExtraBold' });
	Cufon.replace('.content-cart .steps .label', { fontFamily: 'ATRotisSemiSans-ExtraBold' });
}

$(document).ready(function() {
    var ordermachtiging = $('a.order[href=/winkelwagen/IncassoMachtiging]').length;
    if(ordermachtiging > 0){
	    window.open("/winkelwagen/IncassoMachtiging");
    }

    // set target for external links
    $("a[href^='http://']").click(function() {
        window.open(this.href);
        return false;
    });

    $("a[href^='https://']").click(function() {
        window.open(this.href);
        return false;
    });

    // set icons for links
    //$("a[href^='http://']:not(:has(img))").addClass('external');
    //$("a[href^='https://']:not(:has(img))").addClass('external');

    $('a[href$=".doc"]').addClass('icon-doc').click(function() {
        window.open(this.href);
        return false;
    });
    $('a[href$=".pdf"]').addClass('icon-pdf').click(function() {
        window.open(this.href);
        return false;
    });
    $('a[href$=".xls"]').addClass('icon-xls').click(function() {
        window.open(this.href);
        return false;
    });

    // add javascript dependant stuff
    $('#search-box-link').html('<a href="#" onclick="Search_Click();" id="search-link"><span>Zoek</span></a>');
    $('#text-size-links').html('Tekstgrootte <a href="#" id="text-size-regular" title="normaal">A</a> | <a href="#" id="text-size-medium" title="middel">A</a> | <a href="#" id="text-size-large" title="groot">A</a><br />');

    // search box
    var searchBoxDummy = document.getElementById('search-box');
    var searchBox = document.getElementById(searchBoxDummy.value);

    if (searchBox != null) {
        searchBox.onfocus = function() { if (this.value == 'Vul een zoekterm in...') { this.value = ''; } }
        searchBox.onblur = function() { if (this.value == '') { this.value = 'Vul een zoekterm in...'; } }
    }

    //$('.Street').parent('.input').addClass('Adress');

    $('#content-main #category>div').hover(function(){
	$('#content-main #category>div').removeClass('hover');
	$(this).addClass('hover');
	$(this).find('.cat-hover').show();
    },function(){
	$(this).removeClass('hover');
	$(this).find('.cat-hover').hide();
    });

    // reset font size
    var originalFontSize = $('html').css('font-size');
    $('#text-size-regular').click(function() {
        $('#content').css('font-size', originalFontSize);
    });
    // medium font size
    $('#text-size-medium').click(function() {
        var originalFontSizeNum = parseFloat(originalFontSize, 10);
        var newFontSize = originalFontSizeNum * 1.2;
        $('#content').css('font-size', newFontSize);
        return false;
    });
    // large font size
    $('#text-size-large').click(function() {
        var originalFontSizeNum = parseFloat(originalFontSize, 10);
        var newFontSize = originalFontSizeNum * 1.4;
        $('#content').css('font-size', newFontSize);
        return false;
    });

    // init homepage accordion
    if (!activeAccordionIndex)
        var activeAccordionIndex = false;
    $('#accordion').accordion({ autoHeight: false, collapsible: true, active: activeAccordionIndex });

    // init teaser submit buttons
    initSubmitButtons('#content-right .teaser');
    initSubmitButtons('#content-main .product-options');
    initSubmitButtons('#content-main .info-block');
    initSubmitButtons('.content-order');

});

function initSubmitButtons(selector) {
    // init submit buttons
    $(selector).each(function() {
        $(this).find("input[type='submit']").each(function() {
            $(this).parent().prepend('<a onclick="Submit_Click(\'' + $(this).attr('id') + '\');" class="' + $(this).attr('class') + ' submit-link"><span>' + $(this).attr('value') + '</span></a>');
            $(this).css({ 'display': 'none' });
        });
    });
}

function Submit_Click(id) {
	$('#' + id).click();
}

// fire search postback on link click
function Search_Click() 
{
	var searchBtnDummy = document.getElementById('search-btn');
        var searchBtn = document.getElementById(searchBtnDummy.value);
	searchBtn.click();       
}
