/* 
 * GravityFreeGraphix.com custom javascript
 * Author: Ian Carlson, Xantek Inc.
 */

var cacheButtonImages = [];


/**
 * Entry point for GravityFreeGraphix.com custom interaction
 */
function initGravityFreeGraphix()
{
    /* init button */
    $('.toggleButton img').hover(buttonOver, buttonOut);
    $('.toggleButton img').each(preloadHoverButtonImages);
    $('a.toggleButton').click(buttonClicked);
}

/**
 * Toggle button image to hover version
 */
function buttonClicked(event)
{
	if( 'old-index.html' == $(this).attr('href')) {
		
	}else{

	}
}

/**
 * Toggle button image to hover version
 */
function buttonOver(event)
{
    var imageUrl = $(this).attr('src');
    imageUrl = imageUrl.replace('_hover.png', '.png');
    imageUrl = imageUrl.replace('.png', '_hover.png');
    $(this).attr('src', imageUrl);
}

/**
 * Toogle button image back to default
 */
function buttonOut(event)
{
    var imageUrl = $(this).attr('src');
    imageUrl = imageUrl.replace('_hover.png', '.png');
    $(this).attr('src', imageUrl);
}

/**
 * Preload button hover image for smooth mouse overs
 */
function preloadHoverButtonImages(index, value)
{
    if ( null != $(this).attr('src') ){
        var cacheImage = document.createElement('img');
        cacheImage.src = $(this).attr('src').replace('.png', '_hover.png');
        cacheButtonImages.push(cacheImage);
    }
}
