$(document).ready(function() {
   // do stuff when DOM is ready
   $('#myForm').ajaxForm(function() { 
        alert("Thank you for your comment!"); 
    });
   flojax_init();
   $.localScroll();
   $('#bboxy').boxy();
   Boxy.DEFAULTS.title = 'Naomi Beinart';

   $('.round_bottom').corner({
	  tl: { radius: 0 },
	  tr: { radius: 0 },
	  bl: { radius: 8 },
	  br: { radius: 8 },
	  antiAlias: true,
	  autoPad: false,
	  validTags: ["div"] });
   //$('.round').corner();
   $('.round_top').corner({
	  tl: { radius: 8 },
	  tr: { radius: 8 },
	  bl: { radius: 0 },
	  br: { radius: 0 },
	  antiAlias: true,
	  autoPad: false,
	  validTags: ["div"] });
   /*$(".expandcontent").expandable({ tooltip: "Click to expand"});*/
   
   // qTip
   $.fn.qtip.styles.mystyle = { // Last part is the name of the style
   		name: 'dark', 
		border: {
			width: 7,
			radius: 5,
			color: '#333333'
		},
		tip: true
	}
   $('.qtip').qtip({
	   show: 'mouseover',
	   hide: 'mouseout',
	   style: {name: 'mystyle'}
	})
	$('a[title]').qtip({ style: { name: 'mystyle' } })
	$('img[title]').qtip({ style: { name: 'mystyle' } })
});

function flojax_clicked() {
    var link = $(this);
    var parent = link.parent('.' + link.attr('rel'));

    function successCallback(data, textStatus) {
        parent.replaceWith(data);
        flojax_init();
    }
    function errorCallback(request, textStatus, errorThrown) {
    	add_notification('There was an error in performing the requested operation')
	}

    $.ajax({
        'url': link.attr('href'),
        'type': 'POST',
        'data': '',
        'success': successCallback,
        'error': errorCallback
    });

    return false;
}

function flojax_init() {
    $('a.flojax').live('click', flojax_clicked);
}

function add_notification(message) {
    if($('.messages').length > 0) {
        $('.messages').append('<li><span>' + message + '</span></li>');
    }
    else {
        $('#bd').before('<ul class="messages"><li><span>' + message + '</span></li></ul>');
    }
};

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("topNav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
window.onload=startList;