/**
 * Common Javascript methods
 *
 * @author 		Paul Campbell
 * @copyright 	Copyright (c) 2009,  All rights reserved.
 */
/**
 * Apply custom methods
 */
//alert(delicious);
delicious.initialize();

function debug ( ) {
	var overlay = $("#page").append('<img id="overlay" src="images/overlay.jpg" />').find("#overlay");
}
//debug();

/**
 * IE CSS pseudo-class exceptions
 */
if($.browser.msie && $.browser.version < 8) {
	
	// Input focus 
	$("input[type=text]").focus(function() {
		$(this).addClass( delicious.classes.focus );
	}).blur(function() {
		$(this).removeClass( delicious.classes.focus );
	});
	
	// Hover
	$("#primary > li").hover(function () {
		$(this).addClass( delicious.classes.hover );
	}, function () {
		$(this).removeClass( delicious.classes.hover );	
	});
}

/**
 * Enhanced style additions
 */
$("#primary-nav li ol li:not(:last-child), #cookbook li:not(:last-child), #global-nav li:not(:last-child), #recipe-summary li:not(:last), #comments ul li:not(:last-child)").append("&#124;");
$("#cookbook h5, .quick-recipe-list li:last-child").append("&#32;&#187;");
$(".breadcrumb li:not(:last)").append("&#62;");
/**
 * Open external links in a new window
 */	
$("a[@rel*=external]").click(function() {
	window.open(this.href);
	return(false);
});

/**
 * Additional pseudo classes (W3C abiding)
 */
$("#primary-nav li ol li:first, .sidebar-component:first").addClass("first");
$("..quick-recipe-list-list li:last-child, .paging:last").addClass("last");
// $("").addClass("stripe");


//Run on load to add target to all links
function addLinkTarget() {
    var url = document.URL.split("//"); // split at protocol
    var arrUrl = (url[1] ? url[1] : url[0]).split("/");
    var host = arrUrl[0];

    var links = document.getElementsByTagName("a");
    var length = links.length;
    for (i = 0; i < length; i++) {
        if (!links[i].href.match(/^javascript/i) && !links[i].href.match(host)) {
            links[i].target = "_blank";
        }
    }
}