

function getFeed(sender, uri) {
    jQuery.getFeed({
        url: '/wp-content/themes/shinnyo-en/proxy.php?url=' + uri,
        success: function(feed) {

            var html = '<ul>';

            for(var i = 0; i < feed.items.length && i < 6; i++) {

                var item = feed.items[i];

                html += '<li>'
                + '<a href="'
                + item.link
                + '" title="'
                + item.title
                + '">'
                + Truncate(item.title, 55)
                + '</a>'
                + '</li>';
            }
            html += '</ul>';

            jQuery(sender).append(html);
        }
    });
}

function Truncate(string, length, stopanywhere) {
    //truncates a string to a certain char length, stopping on a word if not specified otherwise.
    if (string.length > length) {
        //limit hit!
        string = string.substring(0,(length-3));
        if (stopanywhere) {
            //stop anywhere
            string += '...';
        } else{
            //stop on a word.
            string = string.substring(0, string.lastIndexOf(' '))+'...';
        }
    }
    return string;
}


/* usatoday */
function printArticle() {
	if (window.print) {
		setTimeout('window.print();', 333);
	}
	else {
		alert("Press 'Ctrl+p' on your keyboard to print article.")
	}
}


/*
http://labnol.blogspot.com/2006/01/add-to-favorites-ie-bookmark-firefox.html
*/
function CreateBookmarkLink() {

 title = document.title;
 url = window.location.href;

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}


/**
 * Show / Hide "Search" field text
 * thanks to nymag.com
*/

jQuery.fn.labelOver = function(overClass) {
	return this.each(function(){
		var label = jQuery(this);
		var f = label.attr('for');
		if (f) {
			var input = jQuery('#' + f);

			this.hide = function() {
			  label.css({ textIndent: -10000 })
			}

			this.show = function() {
			  if (input.val() == '') label.css({ textIndent: 0 })
			}

			// handlers
			input.focus(this.hide);
			input.blur(this.show);
		  	label.addClass(overClass).click(function(){ input.focus() });

			if (input.val() != '') this.hide();
		}
	})
}
function sefSearchLabel () {
  jQuery('.label-search').labelOver('label-over');
}
jQuery(sefSearchLabel);

/*
  function to add top level menu item to drop down menu
*/

$(document).ready(function(){
  jQuery('ul.nav li.top').each( function() {
    var main_li = jQuery(this);
    var tocopy = main_li.children('a').clone();
    var new_li = jQuery('<li></li>').addClass('page_item');
    new_li.append( tocopy );
    main_li.children('div.child_menu').children('ul').prepend( new_li );
  });
});




function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=1000,height=550,left = 460,top = 325');");
}
