jQuery(function($) {

	// Fix background image caching problem in IE
    if (jQuery.browser.msie) {
        try { 
            document.execCommand("BackgroundImageCache", false, true); 
        } catch(err) {}
    }
    
	// Set image as full BG
	$(".bg-img-wrap img").addClass("bg-image");
	$(".bg-image").fullBg();
	
	// Categories dropdown	
	$('ul.options li a').hide(); // Hide categories for javascript users
	$("div.active").toggle( // Set the categories area to act like a toggle switch
		function() { // Initial click
			$(this).parent().find("ul li a").slideDown('medium').show(); // Show the categories
		},
		function() { // Secondary click
			$(this).parent().find("ul li a").slideUp('slow').show(); // Hide categories
		}
	);
	
	// Dynamic GUI elements	
	jQuery('.gui-control').css('display','block'); //Show gui appearance button for javascript users
	
	var bfpGui = $.cookie("bfpGui"); //Set cookie variable, check state and then act accordingly
    if (bfpGui == "closed") {
        $(".dynamic,.tags").hide();
		$(".gui-control div").addClass("gui-arrow-down");
	};

	$(".gui-control").click( function() { //Set click actions
		if ( $(".dynamic").is(":visible") ) { //If dynamic content is shown, then hide it and set the cookie
			$(this).parent().find(".gui-control div").addClass('gui-arrow-down'); 
			$(".tags").animate({height: "toggle" }, { duration: 500, complete: function () { 
				$(this).hide();
				}
			}); 
			$(".dynamic").animate({height: "toggle" }, { duration: 500, complete: function () { 
				$(this).hide();
				}
			});
			$.cookie("bfpGui","closed", {path: '/'});
		};
		if ( $(".dynamic").is(":hidden") ) { // If dynamic content is hidden, then show it and set the cookie
			$(this).parent().find(".gui-control div").removeClass('gui-arrow-down');
			$.cookie("bfpGui","open", {path: '/'});
			$(".tags").animate({height: "toggle" }, { duration: 500, complete: function () {
				$(this).show();
				}
			}); 
			$(".dynamic").animate({height: "toggle" }, { duration: 500, complete: function () {
				$(this).show();
				}
			}); 
		};
	});		
});