var $$$ = jQuery;

/*  -------------------------------------------------------------------
    External Link ----------------------------------------------------- */
    
    var allowedDomains = [location.hostname, "http://www.forewordthinking.dev", "http://www.forewordthinking.com"];

    $$$(function() {
	$$$("a[@href^=http]:not(.internal)")
	.filter(function(el){
	for ( var i=0; i < allowedDomains.length; i++ )
	    if ( this.href.indexOf(allowedDomains[i])>-1 ) return false;
		return true;
	    })
	.addClass('external')
	.bind("click", function(){ return !window.open(this.href); });
    });
    
    
/*  ---------------------------------------------------
    First Li in Shownotes UL -------------------------- */
   
	$$$(function() {
		$$$("div.shownotes ul li:first").addClass("first");
		$$$("#previous_post li:last").addClass("last");
		$$$("#comments ul li:last").addClass("last");
		$$$("li:last", "ul.list_post").addClass("last");
	});
    
/*  ---------------------------------------------------
    Rollovers ----------------------------------------- */

    $$$(function(){
        $$$(".rollover")	
            .bind("mouseover",function(){
                imgPath = this.src.split("/");
                imgName = imgPath[imgPath.length-1].split(".");
                imgPathBegin = this.src.split(imgPath[imgPath.length-1]);
                imgOver = imgPathBegin[0] + imgName[0] + "_o." + imgName[1];
                this.src = imgOver;
            })
            .bind("mouseout",function(){
                this.src = this.src.replace(/_o\./i,".");
            });
    });
    
    
/* ---------------------------------------------------
   Blockquote ---------------------------------------- */
   
	$$$(function(){
		$$$("div.entry-content blockquote").each(function(){
			this.innerHTML = this.innerHTML.replace('"','');
			this.innerHTML = this.innerHTML.replace('"','');
			$$$(this).prepend('<span class="quote_l">&ldquo;</span>');
			$$$(this).append('<span class="quote_r">&rdquo;</span>');
		});
	});


/* ---------------------------------------------------
   :Focus :Blur :OnMouseOver :OnMouseOut on input ---- */
   
    $$$(function(){
        $$$("input[@type*='text']")
        .bind("focus",function(){$$$(this).addClass("focus");})
        .bind("mouseover",function(){$$$(this).addClass("hover");})
        .bind("mouseout",function(){$$$(this).removeClass("hover");})
        .bind("blur",function(){$$$(this).removeClass("focus");});
    });
    
    
/* ---------------------------------------------------
   Open player --------------------------------------- */
   
	$$$(function(){
		$$$(".b_openplayer").each(function(){
			var myId = this.id.split("-");
			$$$(this).bind("click",function(){
				popitup("/dynamic/player.asp?id="+myId[1]);
				//WindowObjectReference  = window.open("/dynamic/player.asp?id="+myId[1],"HC" + myId[1], "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,width=440,height=57");
				return false;
			});
		});
	});
	
	
/*  ---------------------------------------------------
    Pop up -------------------------------------------- */	
	
	var newwindow = '';

	function popitup(url) {
		if (!newwindow.closed && newwindow.location) {
			newwindow.location.href = url;
		}
		else {
			newwindow = window.open(url,'name','height=57,width=440');
			if (!newwindow.opener) newwindow.opener = self;
		}
		if (window.focus) {newwindow.focus()}
		return false;
	}
	
/*  -------------------------------------------------------------------
    Google Analytics -------------------------------------------------- */

	$(function() {
		_uacct = "UA-796315-4";
		urchinTracker();
	});