/*! NV Fonts v2.1 <http://nvinteractive.co.nz>
	Copyright (c) NV Interactive
	
	References:
		swfobject.js
		utilities.2.0.js
		jquery-1.2.6.js		
		
	Release Notes:
		2.1
		-- rewrote for jQuery
*/


var fontBasePath = "nvfonts/";
var nvfontsEnabled = true;

var fonts = new Array(
{
 	selector: "#site_title, .type_replace, .price",
	skip: true // Use to override flash replace
	}
,
{
 	selector: "#notepad h1",
	css: "div {font-family: __standard; font-size: 30px; color: #ed1c24; leading: 0px;} strong {font-family: __standard; display: inline; color: #4f5559;",
	fontFile: "handOfSean.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}	
,
{
 	selector: "h1",
	css: "div {font-family: __standard; font-size: 30px; color: #444945; leading: 0px;} strong {font-family: __standard; display: inline; color: #4f5559;",
	fontFile: "myriad.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}	
,
{
 	selector: "h2",
	css: "div {font-family: __standard; font-size: 24px; color: #f57f2a; leading: -4px;} strong {font-family: __standard; display: inline; color: #4f5559;}",
	fontFile: "myriad.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}
,
{
 	selector: "#focus h3",
	css: "div {font-family: __standard; font-size: 18px; color: #444641; leading: 0px;}",
	fontFile: "handOfSean.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}
,
{
 	selector: "#notepad h3",
	css: "div {font-family: __standard; font-size: 24px; color: #ed1c24; leading: 0px; text-align: center;}",
	fontFile: "handOfSean.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}
,
{
 	selector: "#about_note h3",
	css: "div {font-family: __standard; font-size: 18px; color: #414342; leading: 0px;}",
	fontFile: "handOfSean.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}
,
{
 	selector: ".nz_made h3",
	css: "div {font-family: __standard; font-size: 18px; color: #ca137f; leading: -8px;}",
	fontFile: "handOfSean.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}
,
{
 	selector: ".feature_tile h3",
	css: "div {font-family: __standard; font-size: 18px; color: #ed1c24; leading: -8px;}",
	fontFile: "handOfSean.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}
,
	
{
 	selector: "#about h3",
	css: "div {font-family: __standard; font-size: 19px; color: #ed1c24; leading: -8px;}",
	fontFile: "handOfSean.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}
,
{
 	selector: "h4",
	css: "div {font-family: __standard; font-size: 18px; color: #4f5559; leading: 0px;}",
	fontFile: "myriad.swf",
	textThickness: 0,
	aaType: "normal",
	defaultInteraction: false
	}		
	
);

	nvfonts = function() {

	    var SAFARI_DISABLE = false;
	    var FLASH_VERSION = 8;

	    var fontFlashObjs;
	    var checkFlashBlockerInterval;

	    /* Hide Font html elements until we process them after domloaded */
	    if (swfobject.getFlashPlayerVersion().major >= flashVersion && fonts.length > 0) {
	        document.write('<style type="text/css">');
	        for (var g = 0; g < fonts.length; g++)
	            document.write(fonts[g].selector + " {visibility: hidden;} ");
	        document.write('</style>');
	    }

	    document.write('<style type="text/css" media="screen">');
	    document.write('.flash_block_replaced_content { display: none }');
	    document.write('</style>');

	    document.write('<style type="text/css" media="print">');
	    document.write('.flash_block { display: none !important}');
	    document.write('</style>');


	    /* ============ */
	    /* Public Methods */
	    /* ============ */
	    function addFont(fontObj) {
	        fonts.unshift(fontObj);
	    }


	    function flashCallback(flashId) {

	        Debug.addLine("nvfonts.js", "flashCallback", flashId);

	        clearInterval(checkFlashBlockerInterval);
	        var flashObj = $("#" + flashId);

	        if (flashObj.parent().attr("isPreloader")) {
	            Debug.addLine("nvfonts.js", "flashCallback - isPreLoader", flashId);
	            render(fontFlashObjs[flashObj.parent().attr("id")].fontObjs);
	            flashObj.parent().remove();
	            return;
	        }

	        Debug.addLine("nvfonts.js", "flashCallback call init", flashId);
	        flashObj.get(0).init();
	        Debug.addLine("nvfonts.js", "flashCallback init called", flashId);

	        if (flashObj.attr("defaultInteraction")) {
	            flashObj.get(0).onmouseover = function() { this.mouseover(); }
	            flashObj.get(0).onmouseout = function() { this.mouseout(); }
	        }
	    }

	    /* ============ */
	    /* Private Methods */
	    /* ============ */

	    function init() {


	        if ((!nvfontsEnabled) || (SAFARI_DISABLE && jQuery.browser.safari) || (swfobject.getFlashPlayerVersion().major < FLASH_VERSION)) {
	            return;
	        }

	        for (var j = 0; j < fonts.length; j++) {

	            var font = fonts[j];

	            font.cssOver = font.cssOver == undefined ? font.css : font.cssOver;
	            font.textThickness = font.textThickness == undefined ? 0 : font.textThickness;
	            font.textSharpness = font.textSharpness == undefined ? 0 : font.textSharpness;
	            font.aaType = font.aaType == undefined ? "advanced" : font.aaType;
	            font.skip = font.skip == undefined ? false : font.skip;
	            font.defaultInteraction = font.defaultInteraction == undefined ? false : font.defaultInteraction;
	            font.wmode = font.wmode == undefined ? "transparent" : font.wmode;

	            $(font.selector).data("font_definition", font).each(processFontObj);

	        }

	        //return;

	        preload();
	        //renderFontFlash();

	        //if (jQuery.browser.mozilla) checkFlashBlockerInterval = setInterval(checkFlashBlocker, 100);

	    }


	    function checkFlashBlocker() {

	        Debug.addLine("nvfonts.js", "checkFlashBlocker", fontFlashObjs);

	        if (fontFlashObjs == undefined) {
	            clearInterval(checkFlashBlockerInterval);
	        }

	        for (var i in fontFlashObjs) {
	            var preloaderEl = document.getElementById(i);

	            if (preloaderEl.firstChild.tagName == "DIV") {
	                preloaderEl.parentNode.removeChild(preloaderEl);
	                restoreFontHtml();
	                clearInterval(checkFlashBlockerInterval);
	            }
	        }
	    }



	    function render(fontObjs) {

	        for (var i = 0; i < fontObjs.length; i++) {
	            var fontFlashObj = fontObjs[i];
	            var el = fontFlashObj.el;
	            var fontFile = fontBasePath + fontFlashObj.fontFile;
	            var width = "100%"//fontFlashObj.width;
	            var height = fontFlashObj.height;
	            var pars = fontFlashObj.pars;
	            var flashObj = writeFlash(el, fontFile, width, height, pars);
	            fontFlashObj.id = flashObj.id;
	            flashObj.defaultInteraction = fontFlashObj.defaultInteraction;
	        }

	    }

	    /* ================================ */

	    function preload() {



	        for (var i in fontFlashObjs) {

	            var fontFile = fontBasePath + fontFlashObjs[i].fontFile;

	            var el = document.createElement("div");

	            el.id = i;
	            $(el).css({
	                position: "fixed",
	                top: "1px",
	                left: "1px"
	            });

	            $("body").append(el);
	            var pars = { wmode: "window" };
	            var preLoadObj = writeFlash(el, fontFile, 1, 1, pars, { isPreloader: true });
	        }
	    }


	    /* ================================= */

	    function processFontObj() {

	        font = $(this).data("font_definition");

	        if (this.skip) return;
	        if (font.skip) {
	            this.skip = "skip";
	            return
	        }
	        this.skip = "skip";

	        var link = "";

	        var l = this;

	        while (l.tagName != "A" && l.tagName != "BODY") l = l.parentNode;
	        if (l.tagName == "A") link = l.href;

	        //$("body").css("display", "block");
	        //$(this).css("visibility", "visible");
	        var width = $(this).width();
	        var height = $(this).height();
	        //$(this).css("visibility", "hidden");
	        //$("body").css("display", "none");

	        //Hold the element open
	        $(this).css("height", height);

	        //Pull the text out of the node
	        var content = "<div>" + getInnerHtml(this); +"</div>";

	        var flashVars = "content=" + encodeURIComponent(content) +
			"&css=" + escape(font.css) +
			"&link=" + encodeURIComponent(link) +
			"&css_over=" + escape(font.cssOver) +
			"&aa_thickness=" + font.textThickness +
			"&aa_sharpness=" + font.textSharpness +
			"&aa_type=" + font.aaType;


	        var pars = {
	            flashvars: flashVars,
	            wmode: font.wmode
	        };

	        var fontFlashObj = {
	            el: this,
	            width: width,
	            height: height,
	            fontFile: font.fontFile,
	            defaultInteraction: font.defaultInteraction,
	            pars: pars
	        };


	        //Debug.addLine("heading_replace.js", "processFontObj", flashVars);

	        //fontFlashObjs.push(fontFlashObj);
	        var fontFileId = font.fontFile.replace(".", "_");
	        if (fontFlashObjs == undefined) {
	            fontFlashObjs = new Object();
	        }
	        if (fontFlashObjs[fontFileId] == undefined) fontFlashObjs[fontFileId] = new Object({ fontFile: font.fontFile, fontObjs: [] });
	        fontFlashObjs[fontFileId].fontObjs.push(fontFlashObj);

	    }

	    return {
	        /* Public API
	        */
	        init: init,
	        addFont: addFont,
	        flashCallback: flashCallback
	    }

	} ();

function nvfontsFlashCallback(flashid){
	Debug.addLine("nvfonts.js", "nvfontsFlashCallback", flashid);
	nvfonts.flashCallback(flashid);
}


$(document).ready(nvfonts.init);

