// On page load
$(document).ready(function() {
guiPrep();
});
						   
function guiPrep(element)
{
	$(function() {
	
		/* PRELOAD IMAGES */
		$(window).bind("load", function() {
		$(".headerleft img").each(function(key, elm) {
		$().attr( "src", $(this).attr("src").replace(".png", "_on.png"));
		});
		});
		
        /*MENU GUI*/
        $(".button").hover(function() {
		$(this).animate({ 
			top: "0px"
			}, 100 );
		},
		function() {
		$(this).animate({ 
			top: "-8px"
			}, 300 );
		});
		
		
		$(".button").click(function() {
		$(this).blur();
		});
		
		
		/*SWITCH GUI*/
		$(".switch").hover(function() {
		$(this).addClass("switchon");					
		},
		function() {
		$(this).removeClass("switchon");
		});
		
		
		/*GLOW GUI*/
		$(".glow").hover(function() {
		$(this).addClass("glowon");					
		},
		function() {
		$(this).removeClass("glowon");
		});


		/*THUMB GUI*/
		$(".thumb").hover(function() {
		$(this).addClass("thumbon");
		},
		function() {
		$(this).removeClass("thumbon");
		});
		
		
		/*REQUIRED FORM FIELDS*/
		$(element).find(".requiredfield, .requiredfield2").each(function(i){
			$(this).parent().prev().prepend("<span class=\"highlight\">*</span> ");
		});
		
			
        /*SLIDESHOW GUI*/
		$('#slideshow').slideshow();
        
    });
}

/*SLIDESHOW FUNCTION*/
jQuery.fn.slideshow = function(options) {
	var settings = {
		timeout: '5000',
		type: 'sequence',
		pauselink: null,
		playcallback: null,
		pausecallback: null
	}
	if(options)
		jQuery.extend(settings, options);
	
	var pauseState = 0;
	var current = 1;
	var last = 0;
	var timer = '';
	
	var change = function () {
		if ( pauseState == 0 ) {
			for (var i = 0; i < slides.length; i++) {
				jQuery(slides[i]).css('display', 'none');
			}
			jQuery(slides[last]).css('display', 'block').css('zIndex', '0').fadeOut('fast');
			jQuery(slides[current]).css('zIndex', '1').fadeIn('slow');
			
			if ( settings.type == 'sequence' ) {
				if ( ( current + 1 ) < slides.length ) {
					current = current + 1;
					last = current - 1;
				}
				else {
					current = 0;
					last = slides.length - 1;
				}
			}
			else if ( settings.type == 'random' ) {
				last = current;
				while (	current == last ) {
					current = Math.floor ( Math.random ( ) * ( slides.length ) );
				}
			}
			else {
				alert('type must either be \'sequence\' or \'random\'');
			}
			timer = setTimeout(change, settings.timeout);
		}
	}
	
	var pause = function() {
		if ( pauseState == 0 ) {
			pauseState = 1;
			clearTimeout(timer);
			if ( settings.playcallback != null ) {
				settings.pausecallback(jQuery('#' + settings.pauselink));
			}
		}
		else {
			pauseState = 0;
			change();
			if ( settings.playcallback != null ) {
				settings.playcallback(jQuery('#' + settings.pauselink));
			}
		}
		return false;
	}
	
	this.css('position', 'relative');
	var slides = this.find('.slide').get();
	jQuery.each(slides, function(i){
		jQuery(slides[i]).css('zIndex', slides.length - i).css('position', 'absolute').css('top', '0').css('left', '0');
	});
	if ( settings.type == 'sequence' ) {
		timer = setTimeout(change, settings.timeout);
	}
	else if ( settings.type == 'random' ) {
		do { current = Math.floor ( Math.random ( ) * ( slides.length ) ); } while ( current == 0 )
		timer = setTimeout(change, settings.timeout);
	}
	else {
		alert('type must either be \'sequence\' or \'random\'');
	}
	
	if ( settings.pauselink != null ) {
		jQuery('#' + settings.pauselink).click(pause);
	}
	
	return this;
};


function submitOrder(choiceQuantity) {
var choiceSet = 0;

	if (document.setform.choice) {
	
		for (var i = 0; i < document.setform.choice.length; i++) {
		
			if (document.setform.choice[i].checked == true) {
			document.orderform.choice.value = document.setform.choice[i].value;
			choiceSet = 1;
			break;
			}
		
		}
	
		if (!choiceSet) {
		alert('Please select a product choice.');
		return false;
		}
	
	}

	if (document.setform.discount) {
	document.orderform.discountcode.value = document.setform.discount.value;
	}

document.orderform.submit();
return true;
}
