/**
 * Global JS for Spraynique(requires jQuery)
 *    (c) Lee Caine 2010
 **/

var preloadedImages = {}; //For storing mouseover images

/**
 * Invoked when page has loaded
 **/
var onLoad = function() {
	//Preload mouseover images...
	preloadImages();
	//Setup mouseover effects for top right tabs...
	$('#find_button').mouseover(function() {
		$(this).attr('src', preloadedImages['find_mouseover'].src);
	}).mouseout(function() {
		$(this).attr('src', preloadedImages['find'].src);
	});
	$('#contact_button').mouseover(function() {
		$(this).attr('src', preloadedImages['contact_mouseover'].src);
	}).mouseout(function() {
		$(this).attr('src', preloadedImages['contact'].src);
	});
	//Mouseover for search button..
	$('#search_button').mouseover(function() {
		$(this).css({
			'background-image': "url('" + preloadedImages['search_mouseover'].src + "')"
		});
	}).mouseout(function() {
		$(this).css({
			'background-image': "url('" + preloadedImages['search'].src + "')"
		});
	});
	//Mouseover for left tabs..
	$('#about_button').mouseover(function() {
		$(this).attr('src', preloadedImages['about_mouseover'].src);
	}).mouseout(function() {
		$(this).attr('src', preloadedImages['about'].src);
	});
	$('#gallery_button').mouseover(function() {
		$(this).attr('src', preloadedImages['gallery_mouseover'].src);
	}).mouseout(function() {
		$(this).attr('src', preloadedImages['gallery'].src);
	});
	//'To the top' button mouseover..
	$('#top_button').mouseover(function() {
		$(this).attr('src', preloadedImages['top_button_mouseover'].src);
	}).mouseout(function() {
		$(this).attr('src', preloadedImages['top_button'].src);
	});
	//Slide show(banners homepage)
	$('#image_viewer ul').innerfade({
		speed: 2000,
		timeout: 9000,
		type: 'sequence'
	});
};

/**
 * Preloads several images for mouseover effects
 **/
var preloadImages = function() {
	var images = [
		'find_mouseover',
		'contact_mouseover',
		'search_mouseover',
		'about_mouseover',
		'gallery_mouseover',
		'top_button_mouseover',
		'find',
		'contact',
		'search',
		'about',
		'gallery',
		'top_button'
	];
	for(var x = 0; x < images.length; x++) {
		preloadedImages[images[x]] = new Image();
		preloadedImages[images[x]].src = 'media/img/' + images[x] + '.png';
	}
};

$(function() { onLoad(); });

