/**
 * Saunier Duval
 *
 * Conmmon functions for navigation, language selection, dealer search 
 *
 * @version 1.0
 * @copyright 2009 kernpunkt GmbH
 * created: 02.02.2009
 */

var currentNavigation = null;
var activeNavigation = null;
var closeNavigationTimer = null;

function setActiveNavigation(elementId)
{
	currentNavigation = document.getElementById(elementId);
	activeNavigation = currentNavigation;
	restoreDefault();
}


function setCurrentNavigation(elementId)
{
	currentNavigation = document.getElementById(elementId);
	activeNavigation = currentNavigation;
}

function stopCloseTimer()
{
	if (closeNavigationTimer != null)
	{
		window.clearInterval(closeNavigationTimer);
	}
}

function startCloseTimer()
{
	closeNavigationTimer = window.setInterval('restoreDefault()', 20);
}

function showNavigation(elementId)
{
	stopCloseTimer();

	var navigation = document.getElementById(elementId);
	if (navigation == currentNavigation) return;

	selectNavigation(navigation);
}


function restoreDefault()
{
	stopCloseTimer();

	selectNavigation(activeNavigation);
}

function selectNavigation(newNavigation)
{
	if (currentNavigation != null)
	{
		currentNavigation.style.display  = 'none';
	}

	currentNavigation = newNavigation;

	if (currentNavigation != null)
	{
		currentNavigation.style.display  = 'block';
	}
}


$(document).ready(function()
{
	/**
	 * Sprachwechsel
	 */
	$('#languageSelectorContainer').hover(function()
	{
		var ul = $('ul', this);

		ul.fadeIn('slow');
	},
	function()
	{
		var ul = $('ul', this);

		ul.fadeOut('slow');
	});

});

/**
 * Dealersearch: open distributor in new window
 */
$(document).ready(function()
{
    // open link in new window
    $('#dealersearch_results a.distributor_sd').click(
        
        function() {
            var distributorURL = $(this).attr('href');
            window.open(distributorURL);
            return false;
        }
        
    );
});

/**
 * Product accessories
 */
$(document).ready(function()
{
    // button event to link to the product
    $('div.accessorieButton').click(
        
        function() {  
            var productLink = $(this).find('a');
            window.location.href = $(productLink).attr('href');  
        }
        
    );
});


/**
 * 04.05.09 ckrohn: Make the whole preselector-area clickable (see issue 1974).
 */
$(document).ready(function()
{
	$('#preselector').click(function(event)
	{
		document.location.href = $('a', this).attr('href');
	});
});


/*
try
{
    GLOBALS.isIE == true;
}
catch (exc)
{
    var GLOBALS = {
        isIE : false,
        isIE6: false,
        isIE7: false
    };
}

$(document).ready(
    function()
    {
        GLOBALS.webBasepath = '';

        // fix transparent png's for best pal IE6
        if(GLOBALS.isIE6)
        {
            $.ifixpng(GLOBALS.webBasepath+ '/resources/gfx/dot/alpha.gif');
            $('img.alpha').ifixpng();
        }

    }
);
*/

