﻿jQuery(document).ready(function init(){

	setupConfiguratorLinks();

});

function setupConfiguratorLinks() {
    initConfiguratorLinks('#nav a');
    initConfiguratorLinks('#nextstep a');
    initConfiguratorLinks('#promoBox a');
}

function initConfiguratorLinks(csspath) {
    jQuery(csspath).each(function(el) {
        if (this.href.indexOf('/buyingamazda/Konfigurator/') > -1) {
            openConfigurator(this);
        }
    }
	);
}

function openConfigurator(elem) {
    var konfigAnchor = jQuery(elem);
    konfigAnchor.click(function() {
        var properties = 'scrollbars=yes, resizable=yes, left=350';
        var h = 670;
        var w = 1024;
        var leftPos = (screen.width) ? (screen.width - w) / 2 : 0;
        var topPos = (screen.height) ? (screen.height - h) / 2 : 0;
        var settings =
			'height=' + h + ',width=' + w + ',top=' + topPos + ',left=' + leftPos + ',' + properties;
        var newWindow = window.open('http://www.mazda.de/Konfigurator/KonfiguratorSL.aspx', 'Konfigurator', settings);

        if (newWindow) {
            top.newWindow = true;
            return false;
        }
    }
	);
}
