function setStatusMessage(msg) {
	var box = jQuery("#status_box");
	box.html(msg);
	box.show(); 
}

function hideStatusMessage() {
	var box = jQuery("#status_box")[0];
	box.inner_html = "";
	jQuery(box).hide(); 
}

/* search(): The advanced search box disable/enable. */
jQuery(document).ready(function() {
	jQuery("#advanced_search_toggle").click(function() {
		jQuery("div").filter("#advanced_search").toggle();
	});
});

function setCoverQuickZoom() {
    jQuery(".cover_pic_cell").tooltip({ 
		bodyHandler: function() {
			var mid = jQuery(this).attr("id").split("_", 2)[1];
    		return "<img src='/movie/cover/" + mid + "?size=medium'/>";
		}, 
		showURL: false,
		track: true
	});
}

function updateMovieListAJAX() {
    hideStatusMessage();
	jQuery("a").filter(".res_nav").click(function() {
		var divs = 
			jQuery(this).parents().filter(".movie_list");
		if (divs.length == 0)
			return true;
		div = divs[0];
		var id = div.id;
		var link = jQuery(this)[0].href;
		setStatusMessage("Haetaan...");
		jQuery(div).load(link + " #" + id, {}, updateMovieListAJAX);
		return false;
	});
	setCoverQuickZoom();		
}
/* make (some of the) movie list AJAX-browseable */
jQuery(document).ready(function() {
	updateMovieListAJAX();
});

/* 	news(): The news text toggle. 

	The parent() chaining is ugly (breaks when HTML is modified),
	try to replace with something more sensible. */
	
jQuery(document).ready(function(){
       jQuery("a").filter('.text_toggle').toggle(function() {
			jQuery(this).parent().parent().next().show();
          }, function(){
			jQuery(this).parent().parent().next().hide();
          });
   
       jQuery("a").filter('.more_toggle').toggle(function() {
            jQuery(this).parent().parent().parent().parent().parent().children().filter('.hidden_row').show();
            jQuery(this).html('[vain uusimmat]');
          }, function(){
            jQuery(this).parent().parent().parent().parent().parent().children().filter('.hidden_row').hide();          
            jQuery(this).html('[näytä kaikki]');
          });
              
       return true;
});

// The fancy zoom for the movie image.
jQuery(document).ready(function(){

	jQuery(function() {
		//Set the default directory to find the images needed
		//by the plugin (closebtn.png, blank.gif, loading images ....)
		jQuery.fn.fancyzoom.defaultsOptions.imgDir = '/img/fancyzoom/'; 	
		// Select all links with tozoom class, set the open animation time to 1000
		jQuery('#cover_img').fancyzoom({Speed:1000, overlay:0.8});
	});
	return true;
});
