_uacct = "UA-2336657-1";
if (!!window.urchinTracker) urchinTracker();


document.observe('dom:loaded', function() {
	$$('.navlink[rel]').invoke('observe', 'click', function(event) {
		event.element().blur();
		event.stop();
		if ($(this.rel)) {
		if (Prototype.Browser.IE6) $(this.rel).scrollTo();
		else new Effect.ScrollTo(this.rel, { duration: 0.6 });
		}
	});
	
	// feature tips
	var featureZIndex = 200;
	function showFeature(element) {
		featureZIndex++;
		this._feature.setStyle({ zIndex: featureZIndex });
		if (this._featureEffect) this._featureEffect.cancel();
		this._featureEffect = new Effect.Appear(this._feature, { duration: 0.5 });
	}
	function hideFeature(element) {
		if (this._featureEffect) this._featureEffect.cancel();
		this._featureEffect = new Effect.Fade(this._feature, { duration: 0.7, afterFinish: function() {featureZIndex--} });
	}	
	
	$('intro').select('.tipped[title]').each(function(element) {
      element.identify();
	  var title = element.getAttribute('title');
	      wrap = new Element('div', { className: 'featureExplained' }).update(title).hide();
	  wrap.insert({ top: new Element('h2').update(element.down('span').innerHTML.replace(':', '')) });
	  
	  //element.observe('mouseover', 
	  /*new Tip(element, wrap, { className: 'featureTip', border: 0, radius: 0, target: 'featuresImage', hook: { target: 'topRight', tip: 'topRight' }, effect: 'appear', delay: 0.2, hideAfter: 0.8, hideOn: false, duration: 0.3, viewport: false });*/
	  element._feature = wrap;
	  $('featuresImage').insert(wrap);
	  element.observe('mouseover', showFeature)
	         .observe('mouseout', hideFeature);
	  
	  element.writeAttribute('title', '');
    });
	
	Projects.createIdeas('lightview');

	// supported browsers
	new Tip('supportedBrowsersTooltip', $$('.supportedBrowsers')[0].cloneNode(true), {
		hook: { target: 'topRight', tip: 'bottomLeft' },
		stem: 'bottomLeft',
		width: 'auto'
	});

	// changelog
	new Ajax.Request('../lightview/changelog/?format=json', {
		method: 'get',
		onComplete: function(transport) {
			var firstEntry = transport.responseJSON.first(),
			txt = firstEntry.title + '<br\/>\n' + firstEntry.description;
			txt = txt.gsub('\r\n', '<br/>');
			txt = txt.gsub(/\s\s/, '&nbsp;&nbsp;');
			$('download').down('.changelog .code .padder').update(txt);
		}
	});

	// alternating rows in docs
	$$('#documentation .functions .function:nth-child(odd)').invoke('addClassName', 'alt');
});