// // jQuery SWFObject v1.1.1 MIT/GPL @jon_neal
// http://jquery.thewikies.com/swfobject
(function (f, h, i) {
    function k(a, c) {
        var b = (a[0] || 0) - (c[0] || 0);
        return b > 0 || !b && a.length > 0 && k(a.slice(1), c.slice(1))
    }
    function l(a) {
        if (typeof a != g) return a;
        var c = [],
            b = "";
        for (var d in a) {
            b = typeof a[d] == g ? l(a[d]) : [d, m ? encodeURI(a[d]) : a[d]].join("=");
            c.push(b)
        }
        return c.join("&")
    }
    function n(a) {
        var c = [];
        for (var b in a) a[b] && c.push([b, '="', a[b], '"'].join(""));
        return c.join(" ")
    }
    function o(a) {
        var c = [];
        for (var b in a) c.push(['<param name="', b, '" value="', l(a[b]), '" />'].join(""));
        return c.join("")
    }
    var g = "object",
        m = true;
    try {
        var j = i.description ||
        function () {
            return (new i("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")
        }()
    } catch (p) {
        j = "Unavailable"
    }
    var e = j.match(/\d+/g) || [0];
    f[h] = {
        available: e[0] > 0,
        activeX: i && !i.name,
        version: {
            original: j,
            array: e,
            string: e.join("."),
            major: parseInt(e[0], 10) || 0,
            minor: parseInt(e[1], 10) || 0,
            release: parseInt(e[2], 10) || 0
        },
        hasVersion: function (a) {
            a = /string|number/.test(typeof a) ? a.toString().split(".") : /object/.test(typeof a) ? [a.major, a.minor] : a || [0, 0];
            return k(e, a)
        },
        encodeParams: true,
        expressInstall: "expressInstall.swf",
        expressInstallIsActive: false,
        create: function (a) {
            if (!a.swf || this.expressInstallIsActive || !this.available && !a.hasVersionFail) return false;
            if (!this.hasVersion(a.hasVersion || 1)) {
                this.expressInstallIsActive = true;
                if (typeof a.hasVersionFail == "function") if (!a.hasVersionFail.apply(a)) return false;
                a = {
                    swf: a.expressInstall || this.expressInstall,
                    height: 137,
                    width: 214,
                    flashvars: {
                        MMredirectURL: location.href,
                        MMplayerType: this.activeX ? "ActiveX" : "PlugIn",
                        MMdoctitle: document.title.slice(0, 47) + " - Flash Player Installation"
                    }
                }
            }
            attrs = {
                data: a.swf,
                type: "application/x-shockwave-flash",
                id: a.id || "flash_" + Math.floor(Math.random() * 999999999),
                width: a.width || 320,
                height: a.height || 180,
                style: a.style || ""
            };
            m = typeof a.useEncode !== "undefined" ? a.useEncode : this.encodeParams;
            a.movie = a.swf;
            a.wmode = a.wmode || "opaque";
            delete a.fallback;
            delete a.hasVersion;
            delete a.hasVersionFail;
            delete a.height;
            delete a.id;
            delete a.swf;
            delete a.useEncode;
            delete a.width;
            var c = document.createElement("div");
            c.innerHTML = ["<object ", n(attrs), ">", o(a), "</object>"].join("");
            return c.firstChild
        }
    };
    f.fn[h] = function (a) {
        var c = this.find(g).andSelf().filter(g);
        /string|object/.test(typeof a) && this.each(function () {
            var b = f(this),
                d;
            a = typeof a == g ? a : {
                swf: a
            };
            a.fallback = this;
            if (d = f[h].create(a)) {
                b.children().remove();
                b.html(d)
            }
        });
        typeof a == "function" && c.each(function () {
            var b = this;
            b.jsInteractionTimeoutMs = b.jsInteractionTimeoutMs || 0;
            if (b.jsInteractionTimeoutMs < 660) b.clientWidth || b.clientHeight ? a.call(b) : setTimeout(function () {
                f(b)[h](a)
            }, b.jsInteractionTimeoutMs + 66)
        });
        return c
    }
})(jQuery, "flash", navigator.plugins["Shockwave Flash"] || window.ActiveXObject);;
(function($) {
	$.fn.youTubeEmbed = function(settings) {
		// Settings can be either a URL string or an object
		if (typeof settings == 'string') {
			settings = {'video' : settings}
		}
		
		// Default values
		var def = {
			width		: 640,
			progressBar	: true
		};
		
		settings = $.extend(def, settings);
		
		var elements = {
			originalDIV	: this,	// The "this" of the plugin
			container	: null,	// A container div, inserted by the plugin
			control		: null,	// The control play/pause button
			player		: null,	// The flash player
			progress	: null,	// Progress bar
			elapsed		: null	// The light blue elapsed bar
		};

		try {	
			settings.videoID = settings.video.match(/v=(.{11})/)[1];
			// The safeID is a stripped version of the
			// videoID, ready for use as a function name
			settings.safeID = settings.videoID.replace(/[^a-z0-9]/ig,'');
		
		} catch (e) {
			// If the url was invalid, just return the "this"
			return elements.originalDIV;
		}

		// Fetch data about the video from YouTube's API
		var youtubeAPI = 'http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc';

		$.get(youtubeAPI, {'q':settings.videoID}, function(response) {
			var data = response.data;
			if (!data.totalItems || data.items[0].accessControl.embed!="allowed") {
				// If the video was not found, or embedding is not allowed;
				return elements.originalDIV;
			}

			// data holds API info about the video:
			data = data.items[0];
			settings.ratio = 3/4;
			if (data.aspectRatio == "widescreen") {
				settings.ratio = 9/16;
			}
			
			settings.height = Math.round(settings.width * settings.ratio);

			// Creating a container inside the original div, which will
			// hold the object/embed code of the video

			elements.container = $('<div>',{className:'flashContainer',css: {
				width	: settings.width,
				height	: settings.height
			}}).appendTo(elements.originalDIV);

			// Embedding the YouTube chromeless player
			// and loading the video inside it:
			elements.container.flash({
				swf			: 'http://www.youtube.com/apiplayer?enablejsapi=1&version=3',
				id			: 'video_'+settings.safeID,
				height		: settings.height,
				width		: settings.width,
				allowScriptAccess:'always',
				wmode		: 'transparent',
				flashvars	: {
					"video_id"		: settings.videoID,
					"playerapiid"	: settings.safeID
				}
			});

			// We use get, because we need the DOM element
			// itself, and not a jquery object:
			elements.player = elements.container.flash().get(0);

			// Creating the control Div. It will act as a ply/pause button
			elements.control = $('<div>',{className:'controlDiv play'}).appendTo(elements.container);

			// If the user wants to show the progress bar:
			if (settings.progressBar) {
				elements.progress =	$('<div>',{className:'progressBar'}).appendTo(elements.container);
				elements.elapsed =	$('<div>',{className:'elapsed'}).appendTo(elements.progress);
				elements.progress.click(function(e) {
					// When a click occurs on the progress bar, seek to the
					// appropriate moment of the video.
					var ratio = (e.pageX-elements.progress.offset().left)/elements.progress.outerWidth();
					elements.elapsed.width(ratio*100+'%');
					elements.player.seekTo(Math.round(data.duration*ratio), true);
					return false;
				});
			}

			var initialized = false;
			
			// Creating a global event listening function for the video
			// (required by YouTube's player API):
			window['eventListener_' + settings.safeID] = function(status) {
				var interval;
				// video is loaded 
				if (status == -1) {
					// Listen for a click on the control button:
					if (!initialized) {
						elements.control.click(function() {
							if (!elements.container.hasClass('playing')) {
								// If the video is not currently playing, start it:
								elements.control.removeClass('play replay').addClass('pause');
								elements.container.addClass('playing');
								elements.player.playVideo();
								
								if (settings.progressBar) {
									interval = window.setInterval(function() {
										elements.elapsed.width(((elements.player.getCurrentTime() / data.duration) * 100) + '%');
									},1000);
								}
							} else {
								// If the video is currently playing, pause it:
								elements.control.removeClass('pause').addClass('play');
								elements.container.removeClass('playing');
								elements.player.pauseVideo();
								
								if (settings.progressBar) {
									window.clearInterval(interval);
								}
							}
						});
						
						initialized = true;
					}
					else {
						// This will happen if the user has clicked on the
						// YouTube logo and has been redirected to youtube.com
						if (elements.container.hasClass('playing')) {
							elements.control.click();
						}
					}
				}
				
				if (status==0) { // video has ended
					elements.control.removeClass('pause').addClass('replay');
					elements.container.removeClass('playing');
				}
			}
			
			// This global function is called when the player is loaded.
			// It is shared by all the videos on the page:
			if (!window.onYouTubePlayerReady) {				
				window.onYouTubePlayerReady = function(playerID) {
					document.getElementById('video_' + playerID).addEventListener('onStateChange','eventListener_' + playerID);
				}
			}
		},'jsonp');

		return elements.originalDIV;
	}
})(jQuery);;
// http://tutorialzine.com/2010/07/youtube-api-custom-player-jquery-css/
(function ($) {
	if ($("#sidebar-second").height() < $("window").height()){
		 $("#sidebar-second").height($("window").height()) ;
	}

	/*$('#player').youTubeEmbed('http://www.youtube.com/watch?v=0NcJ_63z-mA');
	
	/*$('#player').youTubeEmbed({
		video		: 'http://www.youtube.com/watch?v=DmcRnBYAhbU',
		width		: 430, 		// Height is calculated automatically
		progressBar	: true	// Hide the progress bar
	}); //*/
	
	$('#player').youTubeEmbed({
		video		: 'http://www.youtube.com/watch?v=0NcJ_63z-mA',
		width		: 518, 		// Height is calculated automatically
		progressBar	: true	// Hide the progress bar
	}); //*/
}(jQuery));;
window.onload =function () {
	var new_height = jQuery('#block-system-main').height();
	if (jQuery("#sidebar-second").height() < new_height + 100){
		 jQuery("#sidebar-second").height(new_height + 100) ;
	}

    // This breaks if the height ever changes (e.g., due to dynamic content coming in)
	// if (jQuery("#content .section").height() < new_height + 100){
	// 	 jQuery("#content .section").height(new_height + 100) ;
	// }
};;

