// JavaScript Document
var slidein_menu = function() {
	var mySlidein = new Fx.Slide('slidein_content').hide();
	
	$('c_toggle').addEvent('click', function(e){
		var content_status = $('slidein_content').getStyle('display');
		if (content_status == 'none') $('slidein_content').setStyle('display', 'block');
		e.stop();
		mySlidein.toggle();
	});
	
	//update the menu control - when menu is opened, show "close". when
	mySlidein.addEvent('complete', function() {
		if (mySlidein.open) {
			$('c_toggle').set('html', 'Close Menu');
		} else {
			$('c_toggle').set('html', 'Open Menu');
		}
	});	
};

var rounded_corner = function(elem) {
	//create 4 corner elements
	var myTopLeft  = new Element('div');
	myTopLeft.setStyles({
		'margin': '0px', 
		'background': 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/top_left.gif) no-repeat top left'
	});
	var myTopRight = new Element('div');
	myTopRight.setStyles({
		'margin': '0px', 
		'background': 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/top_right.gif) no-repeat top right'
	});
	var myBottomLeft = new Element('div');
	myBottomLeft.setStyles({
		'margin': '0px', 
		'background': 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/bottom_left.gif) no-repeat bottom left' 
	});
	var myBottomRight = new Element('div');
	myBottomRight.setStyles({
		'margin': '0px', 
		'background': 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/bottom_right.gif) no-repeat bottom right',
		'padding': '5px 12px 5px 8px'
	})
	
	//copy element content
	var content_copy = elem.get('html');
	
	elem.empty();
	elem.grab(myTopLeft);
	myTopLeft.grab(myTopRight);
	myTopRight.grab(myBottomLeft);
	myBottomLeft.grab(myBottomRight);
	myBottomRight.set('html',content_copy);
};

var rounded_corner_bg = function(elem) {
	//create 4 corner elements
	var myTopLeft  = new Element('div');
	myTopLeft.setStyles({
		'margin': '0px', 
		'background': 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/top_left_bg.jpg) no-repeat top left', 
		'margin-top': '10px'
	});
	var myTopRight = new Element('div');
	myTopRight.setStyles({
		'margin': '0px',	
		'background': 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/top_right_bg.jpg) no-repeat top right'
	});
	var myBottomLeft = new Element('div');
	myBottomLeft.setStyles({
		'margin': '0px', 
		'background': 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/bottom_left_bg.jpg) no-repeat bottom left'
	});
	var myBottomRight = new Element('div');
	myBottomRight.setStyles({
		'margin': '0', 
		'background': 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/bottom_right_bg.jpg) no-repeat bottom right', 
		'padding' : '5px 7px 5px 11px'
	});
	
	//copy element content
	var content_copy = elem.get('html');
	
	elem.empty();
	elem.grab(myTopLeft);
	myTopLeft.grab(myTopRight);
	myTopRight.grab(myBottomLeft);
	myBottomLeft.grab(myBottomRight);
	myBottomRight.set('html',content_copy);
};

var scroll_bar = function(content, control_up, control_down) {
	var scroll = new Fx.Scroll(content, {
		wait: false,
		duration: 4000,
		offset: {'x': 0, 'y': 0},
		wheelStops: true,
		transition: Fx.Transitions.Quad.easeInOut
	});
	 
	$(control_up).addEvent('mouseover', function(event) {
		event = new Event(event).stop();
		scroll.toTop();
	});
	
	$(control_up).addEvent('mouseleave', function(event) {
		event = new Event(event).stop();
		scroll.pause();
	});
	 
	$(control_down).addEvent('mouseover', function(event) {
		event = new Event(event).stop();
		scroll.toBottom();
	});
	
	$(control_down).addEvent('mouseleave', function(event) {
		event = new Event(event).stop();
		scroll.pause();
	});	
}

window.addEvent('domready', function() {
	/*	======== slidein menu ========	*/
	slidein_menu();
	
	/* ======== accordion ======== */
	if($('accordion_nav') != null) {
		var myAccordion = new Accordion($('accordion_nav'), 'div.an_toggler_handle', 'div.an_toggler_content', {
			opacity: false,
			display: 2,
			onActive: function(toggler, element){
				toggler.setStyle('background', 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/minus_short.jpg) no-repeat');
			},
			onBackground: function(toggler, element){
				toggler.setStyle('background', 'url(http://www.dental.umaryland.edu/dentalimages/template09/background_img/plus_short.jpg) no-repeat');
			}
		});
	}
	
	/*	======== rounded corner ======== */
	$$('.quick_links_section').each(function(item) {
		rounded_corner_bg($(item).getElement('div'));
	});
	
	if($('highlights_content') != null) rounded_corner_bg($('highlights_content'));
	
	if($('news_headlines') != null) rounded_corner($('news_headlines'));
	
	/* ======== tooltip ======== */
	var customTips = $$('.tooltip');
	var toolTips = new Tips(customTips, {
		className: 'custom_tip'
	});

	
	/*	======== Calendar bar ========	*/
	scroll_bar($('news_headlines_wrapper'), $('up'), $('down'));
	
	/*	======== news bar ======== 
	credit to: noobSlide - http://www.efectorelativo.net/laboratory/noobSlide/
	 	======== news bar ========	*/
	var newsObjectItems =[
		{title:'Student Earns Merit Scholarships', description: '', link:'http://www.dental.umaryland.edu/events_news/index.html?ViewStatus=FullArticle&articleDetail=15955'},
		{title:'3M Donation Enhances Curriculum', description: '', link:'http://www.dental.umaryland.edu/events_news/index.html?ViewStatus=FullArticle&articleDetail=15895'},
		{title:'Marrazzo Earns Merit Scholarship', description: '', link:'http://www.dental.umaryland.edu/events_news/index.html?ViewStatus=FullArticle&articleDetail=15755'},
		{title:'Faculty Profile: Carl Driscoll, DMD', description: '', link:'http://www.dental.umaryland.edu/events_news/index.html?ViewStatus=FullArticle&articleDetail=15735'},
		{title:'Biga Earns Merit Scholarship', description: '', link:'http://www.dental.umaryland.edu/events_news/index.html?ViewStatus=FullArticle&articleDetail=15695'},
		{title:'Continuing Education', description: 'Check Out Our 2012 Courses', link:'http://www.dental.umaryland.edu/dentaloffices/alumni/continuing_education/main.html'}
			];	
		
		var info = $('info_area').set('opacity',1);
		//var more_info = $('more_info_area').set('opacity',1);
		//var gift = $('giving_button').set('opacity', 1);
		var ns = new noobSlide({
			mode: 'horizontal',
			box: $('news_box'),
			items: newsObjectItems,
			size: 586,
			handles: $$('#news_handles div'),
			handle_event: 'click',
			addButtons: {
				previous: $('news_prev'),
				next: $('news_next')
			},
			button_event: 'click',
			fxOptions: {
				duration: 1000,
				//transition: Fx.Transitions.Back.easeOut,
				wait: false
			},
			onWalk: function(currentItem,currentHandle){
				info.empty();
				//more_info.empty();
				//gift.empty();
				new Element('h4').set('html',currentItem.title).inject(info);
				new Element('p').set('html',currentItem.description).inject(info);	
				new Element('div').set('html','<a href="'+currentItem.link+'">More <img src=http://www.dental.umaryland.edu/dentalimages/template09/icon/events_button.gif border=0  align=absmiddle /></a>').inject(info);
				//new Element('h4').set('html','<a href="https://cf.umaryland.edu/lpc/30006_lcfx/dental/give_online/"><img src="http://www.dental.umaryland.edu/dentalimages/template09/icon/ss_donate_button.png" border="0" onmouseover="javascript:this.src=\'http://www.dental.umaryland.edu/dentalimages/template09/icon/ss_donate_button_rollover.png\'" onmouseout="javascript:this.src=\'http://www.dental.umaryland.edu/dentalimages/template09/icon/ss_donate_button.png\'" /></a>').inject(more_info);
				//new Element('div').set('html', '<a href="https://cf.umaryland.edu/lpc/30006_lcfx/dental/give_online/"><img src="http://www.dental.umaryland.edu/dentalimages/template09/icon/giftbutton_slideshow.png" border="0" alt="Gift icon" /></a>').inject(gift);
				this.handles.set('opacity',0.4);
				currentHandle.set('opacity',1);
			}
		});
		ns.walk(0);
		
		
		/* ======== slim gallery========
		credit to: slimbox - http://www.digitalia.be/software/slimbox
		======== slim gallery========*/
				
		$('slimbox_gallery').addEvent('click',function(){
			Slimbox.open(imgs, 0);
		});		
});

