/* HTML5 Tag render code */
document.createElement("article");
document.createElement("footer");
document.createElement("header");
document.createElement("section");
document.createElement("nav");
document.createElement("aside");

$(document).ready(function() {
	$('.faq-btn').click(function() {
        var i = parseInt(this.id.replace("faqBtn", ""));
        $(".faq").stop().slideUp();
        $("#faq" + i).stop().slideDown();
        return false;
    });
	
	// hide & show add-on library items
	$('.add-btn').click(function() {
		$(".addonClass").hide();
		var c = this.id;
		$("." + c).show();
		$('.add-btn').removeClass('activeClass');
		$(this).addClass('activeClass');
        return false;
    });	

// w3c validator doesn't allow return false on HTML5 a tags.  to that i say "f-off"
	$('.returnFalse').click(function(){
		return false;	
	});
	
// open and close cancel notification box for cpanel
	$('#cancelStart').click(function(){
		$("#cancelAccount").fadeIn(150);	
		return false;
	});
	
	$('#closeCancelBox').click(function(){
		$("#cancelAccount").fadeOut(150);
		return false;	
	});

// Login/Logout buttons
    $('#loginLink').click(function() {
        // Allow everyone but IE6 to display the faded-in login box
        if ($.browser.version != '6.0') {
            $(".loginBOX").fadeIn(150);
            $("#username", ".loginBOX").focus();
            return false;
        }
    });
	
	// closes login box if user decides not to log in
    $('.logclose-btn').click(function() {
        $(".loginBOX").fadeOut(150);
        return false;
    });
	
	// function to close the ie6 warning that shows up on the home page
	$('#ie6close').click(function() {
		$('#ie6isAwful').css({'left':'-99999px'});
		return false;
	});
	
	// function to close the ie6 warning that shows up on the home page
	$('#ie6close').click(function() {
		$('#ie6isAwful').css({'left':'-99999px'});
		return false;
	});
	
	$('#m_U')
		.focus(function(){
			$('.tripodCoUK').css({'display':'block'});
		})
		.blur(function(){
			if ($(this).val() == '') {
				$('.tripodCoUK').css({'display':'none'});
			}
		});
	
	$("#m_P")
		.focus(function() {
			$("#hiddenVerifym_PASSVERIFY").show();
		});
	
	// Basic placeholder text labels for login areas
    $(".logArea").find("label").each(function() {
        var forval = $(this).attr("for");
		var $who = $("#" + forval);
        var text = $(this).remove().text();
        $who.addClass("placeholder").val(text);

		var type = $who.attr("type");
		if(type=="password") {
			$who.hide();
			// create a new input block
			// set the value of the input block to be text
			// add to the dom after $who
			var $pwPlaceHolder = $("<input />", {"type":"text", "id": "hiddenVerify" + forval, "value":text}).insertAfter($who);

			// Silly hack for password verify on initial load.
			if ($who.attr("id") == 'm_PASSVERIFY') {
				$pwPlaceHolder.hide();
			}
			
			$pwPlaceHolder.focus(function() {
						$(this).hide();
						$who.show().focus();
			});
			// if a password, hide the input text field and replace with password field	
		}

        $who
        .focus(function() {
            $(this).removeClass("error");
            if ($(this).hasClass("placeholder")) {
                $(this).removeClass("placeholder").val('');
            }
        })
        .blur(function() {
            if (this.value == "") {
                $(this).addClass("placeholder").val(text);
				// if the type is password, hide the password field and replace with input field
				if(type=="password") {
					$(this).hide();
					$pwPlaceHolder.show();	
				}
            }
        });
    });

 // Select three random callout boxes to display in the side bar of the site
    var howManyToShow = 1;
    elementsToShow = $("div", ".randomized").get().sort(
        function() {
            return Math.round(Math.random())-0.5 
        }
    ).slice(0,howManyToShow);

    $(elementsToShow).css('display', 'block');
	// select 1 thumbnail to display for screenshots of sample websites
    var howManyToShow = 1;
    elementsToShow = $("div", ".randomized-screens").get().sort(
        function() {
            return Math.round(Math.random())-0.5 
        }
    ).slice(0,howManyToShow);

    $(elementsToShow).css('display', 'block');
	
	// sign up reg box
	var SPEED = 400;

$(document).ready(function() {
    $(".regSignUpLink").click(function() {
        $("<div></div>").attr("id", "backdrop").appendTo("body").fadeIn(SPEED);
        var $w = $("<div></div>").attr("id", "windowbox-wrapper").appendTo("body").fadeIn(SPEED);
        var $c = $("<div></div>").attr("id", "windowbox-outer").appendTo($w);
        var $a = $("<a></a>").addClass("close-btn").appendTo($c).html("X").attr("href", "#");
        var $i = $("<iframe></iframe>").attr("id", "windowbox-content").appendTo($c);
		var url = this.href.replace(/\/$/, "") + "&m_i'm view=iframe";
        $i.attr("src", url);
        $a.click(function() {
            $("#windowbox-wrapper").add("#backdrop").fadeOut(SPEED, function() { $(this).remove(); });
        });

        return false;
    });
	
	if (top.location!= self.location) {
          top.location = self.location.href;}
});
	
});
