/*
$(document).ready(function() {
	
	var email= $("#signup-email:input",this).serialize(); 
	var postdata= $("#email-signup-form form").serialize(); 
	alert(postdata);
	var triggers = $("input.modalInput").overlay( {
		expose : {
			color : '#333',
			loadSpeed : 200,
			opacity : 0.8
		},

		onBeforeLoad: function() { 
            var wrap = this.getContent().find("#contentWrap");
            wrap.load(base_href + 'subscribe/?' + email); 
        }, 
        closeOnClick: false 
	});
	
	$('#close').click(function(e){
			triggers.close();
	});

});
*/

$(document).ready(function() {
	$("a.videopreview").click(function (){
	   var link = $(this);
        $("#overlay").overlay({ 
		    expose: { 	 
		        color: '#000', 
		        loadSpeed: 200, 
		        opacity: 0.5 
		    },
		    closeOnClick: true, 
            onBeforeLoad: function() {
                var flashvars = { 'src':link.attr("rel"),'name':link.attr("title") };
				var params = {'allowScriptAccess':'always', 'allowFullScreen':'true'};
				swfobject.embedSWF("./flash/vidplayer.swf", "swfwrap", "699", "502", "9.0.115", null, flashvars, params, false);
            },
            api: true  
        }).load();
    }); 
	$("#email-signup-form").submit(function(e){
	
		var api = $("#prompt").overlay({
			// custom top position 
		    top: 272, 
		    expose: { 	 
		        // you might also consider a "transparent" color for the mask 
		        color: '#000', 
		        // load mask a little faster 
		        loadSpeed: 200, 
		        // highly transparent 
		        opacity: 0.5 
		    },  
		    onBeforeLoad: function() { 
		    	  var wrap = $("#contentWrap"); 
		    	  var postdata= $("#email-signup-form").serialize();
		    	  wrap.load(base_href + 'subscribe/?' + postdata );
	        },
		    // disable this for modal dialog-type of overlays 
		    closeOnClick: true, 
		    // we want to use the programming API 
		    api: true 
		// load it immediately after the construction 
		});
		
		api.load();
		
		return false;
	});
	
	$('#close').click(function(e){
		 $("#prompt").overlay().close(); 
	});

});

function doSignup() {
	var subscribe = true;
	if ($("#unsubscribe") == true) {
		subscribe = false;
	}

	var data = $("#email-popup-form").serialize()
	$.post(base_href + "subscribe/", {
		'data' : data,
		'subscribe' : subscribe,
		'ajax' : true
	}, function(transport) {
		var result = transport;
		if (result.msg != "OK") {
			var html = "";
			var errors = result.error;
			$.each(errors, function() {
				html += "<li>" + this + "</li>"
			});

			$("#errors").html("<ul>" + html + "</ul>");
			$("#errors").show();

		} else {

			$("#content_area").hide();
			$("#content_msg").html("<p>" + result.content + "</p>");
			$("#content_msg").show();
		}
	}, "json");
}
