theme = '/wp-content/themes/abby/';

window.addEvent('domready', function() {

	/* Q & A page functions */
	$$('body.qanda').each(function() {
		showmsg = '&raquo; show answer';
		hidemsg = '&laquo; hide answer';
	
		fshow = function(id) {
			$$('#'+id+' .a').setStyle('display', 'block');
			$('a'+id).set('html',hidemsg);
			$('a'+id).removeEvents('click');
			$('a'+id).addEvent('click', fhide.pass(id)); 
			return false;
		};

		fhide = function(id) {
			$$('#'+id+' .a').setStyle('display', 'none');
			$('a'+id).set('html',showmsg);
			$('a'+id).removeEvents('click');
			$('a'+id).addEvent('click', fshow.pass(id)); 
			return false;
		};	
	
		$$('p.q').each(function(q) {
			div = q.getParent();
			
			ashow = new Element('a');
			$(ashow).set('id', 'a'+div.id);			
			$(ashow).set('href', '#');
			$(ashow).set('html', showmsg);					
			$(ashow).addEvent('click', fshow.pass(div.id)); 
			ashow.inject(q, 'after');
			
/*			a = div.getElement('p.a');
			a.setStyle('display', 'none');
			a.appendText(' ');	
			ahide= new Element('a');
			$(ahide).set('href', '#');
			$(ahide).set('html', hidemsg);					
			$(ahide).set('onclick', 'hide(\'' + div.id+'\'); return false;');
			ahide.inject(a, 'bottom');			*/
		});	

	});		
	
	
	/* Tutorial pages functions */
	$$('body.tutorials').each(function() {
		show = function(e) {
			boxh = 250;
			boxw = 400;
			cc = $('tipinject').getChildren();
			cc.each(function(d){
				d.dispose();
			});
			this.each(function(i) {
				i.inject($('tipinject'));
			});
			
			ah = new Element('a', {
				'href': '#',
				'html': 'click to close',
				'events': {'click': hide}			
			}); 

			pa = new Element('p', {
				'styles': {'text-align': 'right'}
			});
			ah.inject(pa);
			pa.inject($('tipinject'));
			
			t = e.page.y-20;
		/*	w = window.getSize();
			maxhead = e.client.y - boxh;
			if (t+boxh > e.client.y && maxhead > 0) {			
			}*/	
			l = e.page.x;
			if (l>boxw) { 
				l = l-(boxw+20);
				l = Math.max(l,10);
			} else {
				l += 20;
			}
		
			$('tipnotes').setStyles({
				display: 'block',
				top: t +'px',
				left: l+'px'
				});	
			return false;
		};
		
		hide = function(e) {
			e.stop();
			$('tipnotes').setStyle('display', 'none');
			cc = $('tipinject').getChildren();
			cc.each(function(d){
				d.dispose();
			});
		};
		
		showScreen = function(idx) {
			$('screen' +idx).setStyle('display', 'block');
			$$('.screen').each(function(s) {
				if (s.id.indexOf(idx)==-1) {
					s.setStyle('display', 'none');
				}
			});
		};
		
		$$('body.tutorials #tipnotes').each(function(tn) {
			myDrag = new Drag(tn, {handle: 'hand'});
			myDrag.attach();
			tna = tn.getElements('a')
			tna.each(function(ac) {
				ac.addEvent('click', hide);
			});			
		});	
	});
	
	$$('body.tutorials .tip').each(function(tip) {
		w = $(tip).getStyle('width');
		h = $(tip).getStyle('height');
		t = $(tip).getStyle('top');
		l = $(tip).getStyle('left');
		
		c = tip.getChildren();		
		
		a = new Element('a', {
			'href': '#tip',
			'class': 'tipa',
			'styles': {	
				'width': w,
				'height': h,
				'top': t,
				'left': l
				},
			'events': {
				'click': show.bind(c)
			}			
		}); 
		if (Browser.Engine.trident) {
			//for IE only
			im = new Element('img', {
				'src': theme +'images/x.gif',
				'styles': {	
					'width': w,
					'height': h,
					'border': 0
				}			
			});
			im.inject(a);	
		}			
		p = tip.getParent();
		a.inject(p);
		
	});	
	
	$$('body.tutorials').each(function() {		
		$('loadstat').setStyle('display', 'none');
		$('loadready').setStyle('display', 'block');
	});	
});



function bookmark(url, description) {
	crtl = 'CRTL';
 	if (Browser.Platform.mac) {
 		crtl = 'Command';
 	}
	if (Browser.Engine.trident) {
         window.external.AddFavorite(url, description);	
	} else {
		alert('Click OK and then press '+crtl+'+D to bookmark to this site.');
	}

/* link looks like this:
<p class="caps"><a href="javascript:bookmark('http://www.abbyandme.com','Abby &amp; Me - Is This Thing On? - Abby Stokes');">to bookmark this site click here</a></p>
*/
}
                                       
