(function($) {

$.fn.ApplicationAndEndProducts = function() {
    return $(this).each(function() {
        var root = $(this);
        
        function setSelected(item) {
            var match = $("a", item).attr("href").match(/^([^#]*)(?:#(.*))?$/);
            if (!match)
                return;
            
            $("ul.applications li", root).removeClass("active");
            item.addClass("active");
            
            $("h2.currentappname", root).text($("a", item).text());
            $("img.table", root).attr("src", match[1]);
            
            $("ul.endproducts li", root).removeClass("active");
            if (match[2]) {
                $.each(match[2].split(","), function() {
                    $("ul.endproducts li.endproduct" + this, root).addClass("active");
                });
            }
        };
        
        setSelected($("ul.applications li:first", root));
        
        $("ul.applications li a", root).click(function() {
            setSelected($(this).parent());
            return false;
        });
    });
};

$.fn.ArizonaLogin = function() {
    return $(this).each(function() {
        var topbar = $(this);
        var box = topbar.find("div.loginbox");
        
        $("#wrap").append(box);
        
        $(document).click(function(e) {
            var node;
            for (node = e.target; node; node = node.parentNode) {
                if (node == box[0])
                    return;
            }
            box.hide();
            topbar.removeClass("loginopen");
        });
        
        topbar.find("a.topbar-login").click(function() {
            box.toggle();
            if (box.is(":visible")) {
                topbar.addClass("loginopen");
                box.find("div.loginerror").remove();
                box.find("input:first").focus();
            } else {
                topbar.removeClass("loginopen");
            }            
            return false;
        });
    });
};

$.fn.HoveredContent = function(selector) {
    $(this).each(function() {
        var root = $(this);        
        var sel = $(selector);        
        if(!sel.length) return;
        var posX  = sel.position().left;
        var posY = sel.position().top;
        var t = null;
        root.hide();
        //$('body').append(root);
        root.css('position', 'absolute').css('left', posX + sel.width()).css('top', posY + (sel.height() / 2 - 10)).css('width', root.width() + 15).css('z-index', '10');
        $(selector).add(root).bind('focus click mouseover', function(e) {
            //$('body').append(root);
            root.show();                                   
            clearTimeout(t);
            e.preventDefault();
        }).bind('mouseout blur', function() {
            t = setTimeout(function() { 
                root.fadeOut(1000,function() {                
                     //root.remove();
                });
            
            }, 1000);
        });                    
    
    });
    
};

$.fn.hoverPopup = function(linkSelector, popupSelector) {
    return $(this).each(function() {
        var root = $(this);
        var link = root.find(linkSelector);
        var popup = root.find(popupSelector);
        
        var pos = link.position();
        popup.css({
            "position": "absolute",
            "left": pos.left + link.width(),
            "top": pos.top + (link.height() / 2 - 10),
            "z-index": 10
        }).hide();
        
        link.mouseenter(function() {
            popup.show();
        }).click(function(e) { e.preventDefault(); });
        root.mouseleave(function() {
            popup.hide();
        });
    });
};

$.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: '/Templates/Arizona/Styles/img/x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};

})(jQuery);


Cufon.replace("#fpintro h1, #fpintro p, h1.stripeheading, h2.rightcolheading, .fieldlabel, .userprofile .formfield strong, .userprofile table label");
Cufon.replace("#mainnavi a, div.fpbox h2", {hover: true});