Event.observe(window, 'load', function() {
	//Set active menu-item
	$$("#hummelMenu li").each(function(s) {
		if (s.firstChild.href == window.location) {
			s.addClassName('active');
		}
	});
	//eoSet active menu-item
	
	//Add extra features to frontpage
 	pathname = new Flog.UriParser(window.location).pathname;
	if (pathname == "/") {
		$('block556973').insert({bottom: new Element('a', {href: '/channel/556971/latestvideos', 'class': 'gotoAll'}).update("See all")});
		// $('block559153').insert({bottom: new Element('a', {href: '/channel/543426/category-1', 'class': 'gotoAll'}).update("See all")});
		// $('block559155').insert({bottom: new Element('a', {href: '/channel/556945/category-2', 'class': 'gotoAll'}).update("See all")});
		// $('block559156').insert({bottom: new Element('a', {href: '/channel/556946/category-3', 'class': 'gotoAll'}).update("See all")});
		// $('block559157').insert({bottom: new Element('a', {href: '/channel/556947/category-4', 'class': 'gotoAll'}).update("See all")});
		
	  $$('div#contentsub div.block-tube-new-videos:nth-child(even)').each(function(s) {
	      s.addClassName('left-column');
	  });

	  $$('div#contentsub div.view-item-sub:nth-child(even)').each(function(s) {
	      s.addClassName('left-image');
	  });		
	}	
	//eoAdd extra features to frontpage

	//Format rating
	$$("div.view-rating").each(function(s) {
			strTemp = s.innerHTML;
			//s.innerHTML = formatPercentageRating((strTemp*10), null);
			s.innerHTML = formatPercentageRating((strTemp), null);
	});	
	//eoFormat rating

	//Remove unnessesary code
  i = 0;
  $$('.video-overview-item table tr td').each(function(s) {
      i++;
      if (s.innerHTML == "&nbsp;") {
          Element.remove(s);
      }
  });

  i = 0;
  $$('#sidebar-videos-popular div table tr td').each(function(s) {
      i++;
      if (s.innerHTML == "&nbsp;") {
          Element.remove(s);
      }
  });

  i = 0;
  $$('.video-channels table tr td').each(function(s) {
      i++;
      if (s.innerHTML == "&nbsp;") {
          Element.remove(s);
      }
  });
	//eoRemove unnessesary code

	//Add extra text to upload-page
	if (pathname == "/upload/open/556727/8b0ae27394ec9dbf") {
		$$('.form-button span').first().insert("<br /><br />Please make sure that you have the rights to any material used in your video. By uploading a video to the site you also take responsibility for the use of material in said video. For more information and links to sites that distribute music for use under Creative Commons licens, have a look at our <a href='/page/guidelines/'>guidelines</a>");
	}
	//eoAdd extra text to upload-page


    /* if (visual.photos.length) {
      str1 = "";
      for (i = 0; i < visual.photos.length; i++) {
          str1 += visual.photos[i].photo_id.toString() + " - " + visual.photos[i].view_count.toString() + "<br />"
      }

      visual.photos.sort(sortMostViewedDescHandler);
      str2 = "<br /><br />";
      for (i = 0; i < visual.photos.length; i++) {
          str2 += visual.photos[i].photo_id.toString() + " - " + visual.photos[i].view_count.toString() + "<br />"
      }
      $('item_556956').update(str1 + str2);


  } else {
      alert('length null');
  }*/
});

// function sortMostViewedDescHandler(thisObject, thatObject) {
//     if (parseInt(thisObject.view_count) > parseInt(thatObject.view_count)) {
//         return - 1;
//     } else if (parseInt(thisObject.view_count) < parseInt(thatObject.view_count)) {
//         return 1;
//     }
//     return 0;
// }

















/**
 * FlogUriParser is freely distributable under the terms of an MIT-style license.
 * 
 * Copyright (c) 2006 Adam Burmister, Original author Poly9.com
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * ------------------------------------------------------------------------------------
 *
 * @author Adam Burmister, adam.burmister@gmail.com, www.flog.co.nz
 * @version 0.1
 * @namespace Flog
 *
 * Based on the Poly9.com url parser, modified to Prototype class and javascript conventions
 * 
 * Usage: var p = new Flog.UriParser('http://user:password@flog.co.nz/pathname?arguments=1#fragment');
 * p.host == 'flog.co.nz';
 * p.protocol == 'http';
 * p.pathname == '/pathname';
 * p.querystring == 'arguements=1';
 * p.querystring[arguements] | p.querystring.arguements == 1
 * p.fragment == 'fragment';
 * p.user == 'user';
 * p.password == 'password';
 *
 */

/* Fake a Flog.* namespace */
if(typeof(Flog) == 'undefined') var Flog = {};

Flog.UriParser = Class.create();

/* A prototype modification of poly9.com's original parser */
Flog.UriParser.prototype = {
	_regExp : /^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/,
	username : null,
	password : null,
	port : null,
	protocol : null,
	host : null,
	pathname : null,
	url : null,
	querystring : {},
	fragment : null,
	
	initialize: function(uri) {
		if(uri) this.parse(uri);	
	},
	
	_getVal : function(r, i) {
		if(!r) return null;
		return (typeof(r[i]) == 'undefined' ? null : r[i]);
	},
	
	parse: function(uri) {
		var r = this._regExp.exec(uri);
		if (!r) throw "FlogUriParser::parse -> Invalid URI"
		this.url		= this._getVal(r,0);
		this.protocol	= this._getVal(r,2);
		this.username	= this._getVal(r,4);
		this.password	= this._getVal(r,5);
		this.host		= this._getVal(r,6);
		this.port		= this._getVal(r,7);
		this.pathname	= this._getVal(r,8);
		this.querystring= new Flog.UriParser.QueryString(this._getVal(r,9));
		this.fragment	= this._getVal(r,10);
		return r;
	}
};

/* Querystring sub class */
Flog.UriParser.QueryString = Class.create();
Flog.UriParser.QueryString.prototype = {
	rawQueryString : '',
	length : 0,
	initialize : function(qs) {
		if(!qs) { 
			this.rawQueryString = '';
			this.length = 0;
			return;
		}
		this.rawQueryString = qs;
		var args = qs.split('&');
		this.length = args.length;
		for (var i=0;i<args.length;i++) {
			var pair = args[i].split('=');
			this[unescape(pair[0])] = ((pair.length == 2) ? unescape(pair[1]) : pair[0]);
		}
	},
	toString : function() {
		return this.rawQueryString;	
	}
}

function formatPercentageRating(rating, blockID) {
  //fiveStarRating = (rating/2.0) + 0.5;
  //return('(' + Math.floor(fiveStarRating*10.0)/10.0 + ')');
  return('Avg. rating: ' + Math.round(rating*5*10)/10);
}

/*function formatRating(rating, blockID) {
  return '('+rating+')';
}*/