//------------------------------------------------------------------
// Helper functions
//------------------------------------------------------------------

//---------------------------------
// ROLLOVER SCRIPT
//---------------------------------

function imghighlight(whichimg) {
	var imgsrc = new String(whichimg.src);
	imgsrc = imgsrc.replace(new RegExp('_off\.','g'),'_on\.');
	whichimg.src = imgsrc;
}

function imgnohighlight(whichimg) {
	var imgsrc = new String(whichimg.src);
	imgsrc = imgsrc.replace(new RegExp('_on\.','g'),'_off\.');
	whichimg.src = imgsrc;
}
	
//---------------------------------
// LEFT NAV ACCORDION
//---------------------------------

function Hide(DivID){
//alert('hide'+DivID);
	$(DivID).style.display = 'none';
}

function Show(DivID){
//alert('show'+DivID);
	$(DivID).style.display = 'block';
	//$(DivID).style.zIndex = '100';
}

//---------------------------------
// SELECT DROPDOWN
//---------------------------------

function pulldownGoTo(thePulldown) {
var theUrl = thePulldown.options[thePulldown.selectedIndex].value;
	if(theUrl != '@')	{
		window.location = theUrl;
	}
	else {
	}
}

//------------------------------------------------------------------------------

function dialogManager( plan ) {
	mdl.modalShow({ 'hideOnClick': false, 'modalStyle': { 'opacity':.80, 'background-color':'#000000', 'z-index': 1000 } });
	var req = new Request.HTML({url : plan.dialogInclude, 
		onSuccess: function(html) {
			$('dialogContainer').set('text', '').adopt(html);

			plan.init();
			new Hash(plan.methods).each( function(methodFunction, key) {
				$(key).onclick = $lambda(methodFunction);
			}); // each
		} // onSuccess
	}).send();
} // function..dialogManager

//------------------------------------------------------------------
// Dialog "Plans"
//------------------------------------------------------------------

var mdl = new Modalizer();

var shareLinkPlan = {
	dialogInclude : '/_includes/code/dialogs/share_dialog.inc',
	init : function() {
		$('recipents').focus();
		$('urlTitle').value = window.document.title;
		$('url').value = window.location;
	},
	methods : {
		dialogSendButton : function() {
			$$('.dialogStep2').setStyle('display','inline');
	
			$('shareDialog').get('send',{
				method: 'post',
				onSuccess: function(wsResult){
					var jsonResult = JSON.decode(wsResult);
					if(!jsonResult.success) {
						new Hash(jsonResult.messages).each( function(value, key) {
							if(value=='') {
								$(key).empty();
							} else {
								$(key).set('html',value);
							} // if..else
						}); // each
		
						$$('.dialogStep2').setStyle('display','none');
						$('dialogSendButton').set('src', '/_media/images/utility/submit_btn.jpg');
						$('dialogCancelButton').set('src', '/_media/images/utility/cancel_btn.jpg');
						$$('.dialogStep1 input', '.dialogStep1 textarea').set('disabled', false);
					} else {
						if(pageTracker) pageTracker._trackPageview('/_ws/share_link.php'); //-- for Google Analytics

						$$('.dialogStep1').setStyle('display','none');
						$$('.dialogStep3').setStyle('display','block');
					} // if..else
				}
			}).send();
	
			//-- disable AFTER asynchronous XHR request is sent
			$('dialogSendButton').set('src', '/_media/images/utility/submit_btn.jpg');
			$('dialogCancelButton').set('src', '/_media/images/utility/cancel_btn.jpg');
			$$('.dialogStep1 input', '.dialogStep1 textarea').set('disabled', true);
		}, // dialogSendButton
		dialogCancelButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		}, // dialogCancelButton
		dialogCloseButton : function() {
			$('dialogContainer').empty();
			mdl.modalHide();
		}, // dialogCloseButton
		dialogSendAnotherLink : function() {
			$('dialogContainer').empty();
			dialogManager(shareLinkPlan);
		} // dialogSendAnotherLink
	} // methods
} // shareLinkPlan

//------------------------------------------------------------------
// Behaviors
//------------------------------------------------------------------

window.addEvent('domready', function() {
	//---------------------------------
	// SUBNAV SLIDER
	//---------------------------------
	if($('v_toggle')){
		var status = {
			'false': '<img src="/_media/images/common/leftnav/arrow_down.gif" alt="" width="8" height="9" border="0" />',
			'true': '<img src="/_media/images/common/leftnav/arrow_right.gif" alt="" width="8" height="9" border="0" />'
		};
	
		//-vertical
		var myVerticalSlide = new Fx.Slide('manuSubnav');
		$('v_toggle').addEvent('click', function(e){
			if(e) e.stop();
			$('vertical_status').set('html', status[myVerticalSlide.open]);
			$('industryNav').setStyle('height','');
			myVerticalSlide.toggle();
		});
		myVerticalSlide.hide(); 
	}

	//---------------------------------
	// PRINT BUTTON
	//---------------------------------
	$$('.bvPrintLink').each( function(el) {
		el.onclick = function() {
			window.print(); return false;
		} // onclick
	}); // bvPrintLink

	//---------------------------------
	//-- Dialog for "Email link" method
	//---------------------------------
	$$('.bvShareLink').each( function(el) {
		el.onclick = function() { dialogManager(shareLinkPlan); }
	}); // bvShareLink

	//---------------------------------
	//-- LeftNav Chevron Rollover
	//---------------------------------
	$$('.bvLeftRoll').each( function(el) {
		el.onmouseover = function() {
			this.getElements('span').set('html','&nbsp;&#x3E;&#x3E;');
		}
		el.onmouseout = function() {
			this.getElements('span').set('html','&nbsp;&nbsp;&nbsp;&nbsp;');
		}
	}); // bvLeftRoll

}); // domready

//---------------------------------
// Pop Up
//---------------------------------
function popwin(loc,winname,w,h,scroll,resize) {
	var newwin = window.open( loc, winname, "width="+w+",height="+h+",top="+((screen.height - h) / 2)+",left="+((screen.width - w) / 2)+",location=no,scrollbars="+scroll+",menubar=no,toolbar=no,resizable="+resize);
} // function..popwin

//------------------------------------------------------------------
