
/*global jQuery */

(function ($, window, document) {

	'use strict';

	if (typeof $ === 'undefined') {
		return;
	}

	var root = new $.prototype.init(document),
		head,
		body;



	$.prototype.vimeoPlayer = function () {

		return this.each(function () {
			var vimeo = $(this);

			vimeo.empty().flash({
				swf: 'http://vimeo.com/moogaloop.swf',
				flashvars: {
					clip_id: vimeo.dataAttr('video-id'),
					server: 'vimeo.com',
					show_title: 1,
					show_byline: 1,
					show_portrait: 0,
					fullscreen: 1
				},
				params: {
					allowfullscreen: true,
					allowscriptaccess: 'always',
					wmode: 'transparent'
				},
				height: 415,
				width: 520,
				wmode: 'transparent'
			});
		});
	};



	$.prototype.scribdDocument = function () {

		return this.each(function () {
			var scribd = $(this);

			scribd.empty().flash({
				swf: 'http://d1.scribdassets.com/ScribdViewer.swf',
				flashvars: {
					document_id: scribd.dataAttr('scribd-id'),
					access_key: 'key-1r8kuhf9srhdao6m3x39',
					page: 1,
					viewMode: 'list'
				},
				params: {
					allowfullscreen: true,
					allowscriptaccess: 'always',
					bgcolor: '#ffffff',
					wmode: 'opaque'
				},
				height: 673,
				width: 520,
				wmode: 'opaque'
			});
		});

	};



	$.prototype.selectSubmit = function () {

		return this.bind('change', function () {
			if (this.value !== '-') {
				var rel = $(this).attr('rel');
				window.location = '/library/' + rel + '/' + this.value;
			}
		});

	};



	$.prototype.slideShareEmbed = function () {

		return this.each(function () {
			var slideshare = $(this);

			slideshare.empty().flash({
				swf: 'http://static.slideshare.net/swf/ssplayer2.swf?doc=' + slideshare.dataAttr('doc'),
				params: {
					allowfullscreen: true,
					allowscriptaccess: 'always',
					wmode: 'transparent'
				},
				height: 415,
				width: 520,
				wmode: 'transparent'
			});
		});

	};

	root.ready(function () {

		head = root.find('head');
		body = root.find('body');

		body.addClass('js');

		body.find('p.vimeo').vimeoPlayer();
		body.find('p.scribd').scribdDocument();
		body.find('p.slideshare').slideShareEmbed();
		body.find('.select_submit').selectSubmit();

		body.find('p.captcha input').attr('maxlength', 2);

		body.find('.library_graphics li:nth-child(3n+1)').addClass('new_row');

	});

}(jQuery, this, this.document));

