var addthis_config = {
	ui_offset_top: 0,
	ui_offset_left: 0,
	ui_header_color: "#ffffff",
	ui_header_background: "#8E8E8E",
	services_compact: 'favorites, email, facebook, twitter, digg, delicious, google, bitly',
	services_expanded: 'favorites, email, facebook, twitter, digg, delicious, google, bitly'
}


window.addEvent("domready", function(){

	//Init Google Analytics
	//_uacct = "UA-1122165-1";urchinTracker();
	try{
		var pageTracker = _gat._getTracker("UA-1122165-1");
		pageTracker._setDomainName("none");
		pageTracker._trackPageview();
	}catch(err){}


	var Entries = $$('.entry');

	EntryEvents = function(){
		$$('.media').removeEvents('mouseover');
		$$('.media').removeEvents('mouseout');

		$$('.media').addEvents({
			'mouseover': function(e){
				Entries.morph({'opacity':0.3});
				this.getParent('.entry').morph({'opacity':1});
				if(!this.getParent('.entry').hasClass('current')){
					this.getParent('.entry').tween('height','300px');
					this.tween('height','300px');
					this.getElement('img').tween('margin-top','0px');
				}
			},
			'mouseout': function(e){
				Entries.morph({'opacity':1});
				if(!this.getParent('.entry').hasClass('current')){
					this.getParent('.entry').tween('height','175px');
					this.tween('height','175px');
					this.getElement('img').tween('margin-top','-65px');
				}
			}
		});
		


	};


	var showfeatured = false;
	if($$('#entries .featured').length > 2){
		var featuredli = new Element('li').inject($$('.pagenav')[0], 'bottom');
		var featuredlink = new Element('span', {'html':'Only show featured entries','id':'showfeatured'}).injectInside(featuredli);
		$('showfeatured').addEvent('click', function(e){
			e.stop();
			if(!showfeatured){
	
				Entries.each(function(item, index){
					if(!item.hasClass('featured')){
						item.set('tween', {'link':'ignore'});
						item.tween('height', '0px');
					}
				});
				$$('.firstentries', '.moreentries').each(function(item, index){
					var tmp = item.getElements('.featured');
					var th = tmp.length * 175;
					
					if(tmp.getElements('.current').length){
						th+=125;
					}
					item.set('style', {'height': th + 'px'});
				});
				
				showfeatured = true;
				this.set('html','Show all entries');
			}else{
				
				Entries.each(function(item, index){
					if(!item.hasClass('featured')){
						item.set('tween', {'link':'cancel'});
						if(item.hasClass('current')){
							item.tween('height', '300px');
						}else{
							item.tween('height', '175px');
						}
					}
				});
				$$('.firstentries', '.moreentries').each(function(item, index){
					var th=item.getElements('.entry').length * 175;
					if(item.getElements('.current').length){
						th+=125;
					}
					item.setStyle('height', th + 'px');
				});
				
				showfeatured = false;
				this.set('html','Only show featured entries');
			}
		});
	}



	$$('#mast h1 a, .detailpage h2 a').addEvents({
		'mouseover': function(){
			this.tween('background-position','0px -40px');
		},
		'mouseout': function(){
			this.tween('background-position','0px 0px');
		}
	});


	EntryEvents();
	
	
});
