// site specific javascript

if(!jQuery.browser.safari)
{
	jQuery(document).ready(function(){
		behavior_binder();
	});
} else {
	jQuery(window).load(function(){
		behavior_binder();
	});
}


/*
Binds behaviors
** can be re-run whenever there are DOM changes
*/
var GENRE_ACCORION_HEIGHT=false;
function behavior_binder(){

/* DRAWS THE FONT IMAGE FOR THE TARGETED ELEMENT
	*/
	
	jQuery('.module_header h2').drawFont();
	jQuery('.module_title').drawFont();
	
/* TURNS ON INTERNAL TABS
	(requires jquery-ui-tabs.js)
	*/
	jQuery("ul.module_tabs").tabs();

	jQuery('div#scifi_daily div.scifi_daily_row').each(function(){by_genre_accordion_init(this);});

	jQuery('ul.star_rating').snasRate();
	jQuery('div.module_article_comments').snasCommenting();
	jQuery('.comments_counter').numComments();
}

function nav_select(this_section){
	jQuery('#navigation .selected').removeClass('selected');
	jQuery('#'+this_section).addClass('selected');
}
function by_genre_accordion_init(row){
	if(jQuery('li',row).length>4){
		jQuery(row).append('<p class="accordion_btn"><a href="javascript:void()" class="more_btn">more</a><p>');
		jQuery('p.accordion_btn a',row).toggle(function(e){expand_genre_accordion(e)},function(e){shrink_genre_accordion(e)});
		if(jQuery('li:gt(3)',row).is('.selected')){
			jQuery('p.accordion_btn a',row).click();
		}
	}
}
function expand_genre_accordion(e){
	var list=jQuery(e.target).parent().parent();
	if(GENRE_ACCORION_HEIGHT===false){
		GENRE_ACCORION_HEIGHT=jQuery(list).css('height');
	}
	jQuery(list).css({height:'auto'});
	jQuery('p.accordion_btn a',list).addClass('back_btn');
	jQuery('p.accordion_btn a',list).removeClass('more_btn');
}
function shrink_genre_accordion(e){
	var list=jQuery(e.target).parent().parent();
	jQuery(list).css({height:GENRE_ACCORION_HEIGHT});
	jQuery('p.accordion_btn a',list).addClass('more_btn');
	jQuery('p.accordion_btn a',list).removeClass('back_btn');
}
jQuery(document).ready(function(){
	jQuery('ul#video_category_menu li.expand').each(function() {	
		jQuery(this).children('a').attr({href: 'javascript: void(0);'});
		jQuery(this).children('a').click(function() {
			jQuery(this).parent().children('ul').toggle();
		});
	});
});

