//----------------------------------------
//
//	Article Tools javascript
//	created for NYTRNG
//
//----------------------------------------

//	toolsToggle
//	Used for animated slidedown options on article tools (requires prototype and scriptaculous)
function toolsToggle( element, ID, imgName ){
	new Effect.toggle(ID, 'blind', {duration: .2});
	if($(ID).style.display == 'none'){
		element.getElementsByTagName('img')[0].src = '/graphics/article_tools/'+imgName+'2.gif';
	}else{
		element.getElementsByTagName('img')[0].src = '/graphics/article_tools/'+imgName+'.gif';
	}
}

//	emailArticle
//	AJAX request that emails an article to someone
function emailArticle( url, permalink, title, category, categoryid, from, fromemail, toemail){
	
	// if all boxes not filled in, display error and quit
	if(!from || !fromemail || !toemail){
		Element.show('email_warning');
		return;
	}else{
		Element.hide('email_warning');
	}
	
	// shows loading image
	Element.show('email_loading');
	
	// disables form elements
	Form.disable('email_article_form');
	
	// creates vars to be passed
	var vars = 'link=' + permalink;
	vars += '&tittel=' + title;
	vars += '&articlecategory=' + category;
	vars += '&categoryid=' + categoryid;
	vars += '&from=' + from;
	vars += '&fromemail=' + fromemail;
	vars += '&to=' + toemail;
	vars += '&title=' + from + ' wanted to show you an article';
	vars += '&message=';
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: vars, 
			onComplete: emailArticleComplete
		});
		
	function emailArticleComplete(originalRequest){
		
		// closes email toolbox
		if($('email_article').style.display != 'none'){
			new Effect.toggle('email_article', 'blind', {duration: .2});
			var element = $('email_article_link').getElementsByTagName('img')[0];
			element.src = '/graphics/article_tools/email.gif';
		}

		// shows loading image
		Element.hide('email_loading');
		
		// re-enables and clears form elements
		Form.enable('email_article_form');
		Form.reset('email_article_form');
	}
}

//	enlargeText
//	enlarges/shrinks text in `articleText` DIV
function enlargeText(element){
	if( Element.getStyle('articleText', 'fontSize') == '16px' ){
		$('articleText').style.fontSize = '12px';
		element.innerHTML = '<img src="/graphics/article_tools/largetext.gif" alt="" />LARGE TEXT';
	}else{
		$('articleText').style.fontSize = '16px';
		element.innerHTML = '<img src="/graphics/article_tools/largetext2.gif" alt="" />SMALL TEXT';
	}
}

//	printPage
//	prints page if it can. else it alerts user on how to print.
function printPage(){
	if (!window.print) {
		alert('To print this article, open the file menu and choose Print.');
	} else {
		setTimeout("window.print();", 500);
	}
}

//vars needed for photo tools hover
var photoToolsInterval = new Array();
var photoToolsHidden = new Array();

//	showPhotoTools
//	shows photo tools
function showPhotoTools(elementId){
	if(photoToolsHidden[elementId]==undefined){
		photoToolsHidden[elementId] = true;
	}
	clearInterval(photoToolsInterval[elementId]);
	Element.setOpacity(elementId, 0.7);
	if( photoToolsHidden[elementId] ){
		new Effect.BlindDown(elementId, {duration: .2, queue:'end'});
		photoToolsHidden[elementId] = false;
	}
}

//	hidePhotoTools
//	sets photo tools to hide after a certain time limit
function hidePhotoTools(elementId){
	clearInterval(photoToolsInterval[elementId]);
	photoToolsInterval[elementId] = setInterval("hidePhotoToolsOnInterval('"+elementId+"');", 500);
}

//	hidePhotoToolsOnInterval
//	hides photo tools
function hidePhotoToolsOnInterval(elementId){
	clearInterval(photoToolsInterval[elementId]);
	photoToolsHidden[elementId] = true;
	new Effect.BlindUp(elementId, {duration: .2, queue: 'end'});
}