/**
 * Applies effects/events to various CSS classes within the given element.
 *
 * @param DOMElement|jQuery element
 * @return void
 */
// On page load
$(document).ready(function() {
guiPrep();
});
						   
function guiPrep(element)
{
	$(function() {
	$('#cinema').hide();
	$('#gallery').hide();
	
		/* PRELOAD IMAGES */
		$(window).bind("load", function() {
		$(".switch img").each(function(key, elm) {
		$().attr( "src", $(this).attr("src").replace(".png", "_on.png"));
		});
		});
		
        /*BUTTON GUI*/
        $(element).find(".switch").hover(function() {
		if ($(this).attr("src").indexOf("_on") == -1) {
			var newSrc = $(this).attr("src").replace(".png","_on.png");
			$(this).attr("src",newSrc);
			}
		},
		function() {
			if($(this).attr("src").indexOf("_on.png") != -1) {
			var oldSrc = $(this).attr("src").replace("_on.png",".png");
			$(this).attr("src",oldSrc);
			}
		});
		
			
        /*PANEL GUI*/
       	$(".thumbpanel").hover(function() {
		$(this).addClass("thumbpanelon");					
		},
		function() {
		$(this).removeClass("thumbpanelon");
		});
		
		
		/*GALLERY TOGGLE*/
        $("a.openimage").click(function() {
			$("#full").animate({
				opacity: "hide"
				}, "fast");
            $("#gallery").animate({
				opacity: "show"
				}, "fast");
			$(this).blur();
			var image = ("../images/" + $(this).attr("href") + ".jpg");
			$("#imagecontent").html("<img src=\"images/" + image + "\" alt=\"gallery image\" />");
			return false;
        });
		
		$("a.closeimage").click(function() {
            $("#gallery").animate({
				opacity: "hide"
				}, "fast");
			$("#full").animate({
				opacity: "show"
				}, "fast");
			$(this).blur();
			$("#imagecontent").html("");
			return false;
        });
		
		/*REQUIRED FORM FIELDS*/
		$(element).find(".requiredfield, .requiredfield2").each(function(i){
			$(this).parent().prev().prepend("<span class=\"yellow\">*</span> ");
		});


        /*THUMBNAIL SWITCH*/
		$("img.thumbnail").hover(function() {
		$(this).addClass("thumbnailon");					
		},
		function() {
		$(this).removeClass("thumbnailon");
		});
        
    });
}