/*!
 * jquery.overlay 1.0.1. Overlay HTML with eyecandy.
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/overlay.html
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Launch  : March 2008
 * Version : 1.0.1 - Wed Feb 18 2009 05:18:27 GMT-0000 (GMT+00:00)
 */
(function(c){var d=[];function b(j,h,f,e){var i=j[h];if(c.isFunction(i)){try{return i.call(f,e)}catch(g){if(j.alert){alert("Error calling overlay."+h+": "+g)}else{throw g}return false}}return true}function a(i,e){var q=this;var k=null;var n=c(window);var j=e.target||i.attr("rel");var h=j?c(j):null;if(!h){h=i}else{k=i}var m=h.attr("overlay");if(!m){m=h.css("backgroundImage");m=m.substring(m.indexOf("(")+1,m.indexOf(")"));h.css("backgroundImage","none");h.attr("overlay",m)}if(!m){throw"background-image CSS property not set for overlay element: "+j}m=m.replace(/\"/g,"");if(e.preload){c(window).load(function(){setTimeout(function(){var o=new Image();o.src=m},2000)})}var p=h.outerWidth({margin:true});var g=h.outerHeight({margin:true});var l=c('<img src="'+m+'"/>');l.css({border:0,position:"absolute"}).width(p).hide();c("body").append(l);l.hide();if(k){k.bind("click.overlay",function(o){q.load(o.pageY-n.scrollTop(),o.pageX-n.scrollLeft());return o.preventDefault()})}if(!e.close||!h.find(e.close).length){h.prepend('<div class="close"></div>');e.close="div.close"}var f=h.find(e.close);c.extend(q,{load:function(t,s){if(q.isOpened()){return q}if(e.oneInstance){c.each(d,function(){this.close()})}if(b(e,"onBeforeLoad",q)===false){return q}t=t||e.start.top;s=s||e.start.left;var o=e.finish.top;var r=e.finish.left;if(o=="center"){o=Math.max((n.height()-g)/2-30,0)}if(r=="center"){r=Math.max((n.width()-p)/2,0)}if(!e.start.absolute){t+=n.scrollTop();s+=n.scrollLeft()}if(!e.finish.absolute){o+=n.scrollTop();r+=n.scrollLeft()}l.css({top:t,left:s,width:e.start.width,zIndex:e.zIndex}).show();l.animate({top:o,left:r,width:p},e.speed,function(){h.css({position:"absolute",top:o,left:r});var u=l.css("zIndex");f.add(h).css("zIndex",++u);h.fadeIn(e.fadeInSpeed,function(){b(e,"onLoad",q)})});return q},getBackgroundImage:function(){l.show();return l},getContent:function(){return h},getTrigger:function(){return k},isOpened:function(){return h.is(":visible")},getConf:function(){return e},close:function(){if(!q.isOpened()){return q}if(b(e,"onClose",q)===false){return q}if(l.is(":visible")){l.hide();h.hide()}return q},getVersion:function(){return[1,0,0]},expose:function(){l.expose()}});f.bind("click.overlay",function(){q.close()});n.bind("keypress.overlay",function(o){if(o.keyCode==27){q.close()}});if(e.closeOnClick){n.bind("click.overlay",function(o){if(!h.is(":visible, :animated")){return}var r=c(o.target);if(r.attr("overlay")){return}if(r.parents("[overlay]").length){return}q.close()})}}jQuery.prototype.overlay=function(f){var g=this.eq(typeof f=="number"?f:0).data("overlay");if(g){return g}var e=c(window);var h={start:{top:Math.round(e.height()/2),left:Math.round(e.width()/2),width:0,absolute:false},finish:{top:"center",left:"center",absolute:false},speed:"normal",fadeInSpeed:"fast",close:null,oneInstance:true,closeOnClick:true,preload:true,zIndex:9999,target:null,alert:true};if(c.isFunction(f)){f={onBeforeLoad:f}}c.extend(true,h,f);this.each(function(){var i=new a(c(this),h);d.push(i);c(this).data("overlay",i)});return this}})(jQuery);

$(document).ready(function(){
	$("a[rel=overlay]").each(function(i){
		$(this).overlay({oneInstance: false, preload: false, target: '#overlay', 
			onLoad: function() {
					$("#videoframe").attr("data-returnurl", $("#videoframe").attr("src"));
					$("#videoframe").attr("src",this.getTrigger().attr("href"));
					$("#surveyframe").attr("data-returnurl", $("#surveyframe").attr("src"));
					$("#surveyframe").attr("src",this.getTrigger().attr("href").replace(/^.*\?id=([0-9]*)&name=(.*)$/gi, $("#surveyframe").attr("data-returnurl")+"?video=$2%20%23$1"));
					},
			onBeforeClose: function() {
				$("#videoframe").attr("src",$("#videoframe").attr("data-returnurl"));
				$("#surveyframe").attr("src",$("#surveyframe").attr("data-returnurl"));
				},
			onClose: function() {
				$("#videoframe").attr("src",$("#videoframe").attr("data-returnurl"));
				$("#surveyframe").attr("src",$("#surveyframe").attr("data-returnurl"));
				}
			});
	});
});
function drawVimeo(video, div, width, height){if(!width){width="400";}if(!height){height="290";}swfobject.embedSWF(generateVideoUrl(video), div, width, height, "9.0.0", "", {}, {allowfullscreen:"true",allowscriptaccess:"always"}, {id: div});}
function generateVideoUrl(i){return "http://vimeo.com/moogaloop.swf?clip_id="+i+"&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1&amp;autoplay=1";}
