/*jslint vars: true, undef: true, browser: true */
/*global jQuery, $, Modernizr, Placeholder, Shadowbox, window, Lectric, helpers, methods, $f */

$(document).ready(function () {
	"use strict";

	/* Kod för nyhetsbrev */
	$("#subForm").submit(function (e) {
		e.preventDefault();

		$.ajax({
			type: "POST",
			url: $("#subForm").attr('action'),
			cache: false,
			data: $(this).serialize(),

			complete: function (html) {
				$("#successForm").show();
			}
		});

		$("#subForm").hide();
		return false;
	});


	/* Kod för bildspel + flowplayer */
	Shadowbox.init({
		showMovieControls: false,
		player: ['qt'],
		animate: false,
		overlayOpacity: 0.7,
		onFinish: function (el) {
			if (el.player === 'qt') {
				var videoWidth = el.width;
				var videoHeight = el.height;
				$("#sb-body-inner").html('<a id="videoCanvas" href="' + el.content + '" style="display: block; width: ' + videoWidth + 'px; height: ' + videoHeight + 'px"></a>');
				$f("videoCanvas", "/flash/flowplayer.commercial-3.2.7.swf", {
					key: '',
					clip: {
						autoPlay: true,
						autoBuffering: true,
						scaling: "fit",
						clip : el.content
					},

					// some styling for the controlbar
					plugins: {
						controls: {
							borderRadius: "0px",
							timeColor: "#ffffff",
							buttonOffColor: "rgba(130,130,130,1)",
							bufferGradient: "none",
							zIndex: 1,
							sliderColor: "#000000",
							backgroundColor: "rgba(0, 0, 0, 0)",
							scrubberHeightRatio: 0.6,
							tooltipTextColor: "#ffffff",
							volumeSliderGradient: "none",
							sliderGradient: "none",
							spacing: {
								time: 6,
								volume: 8,
								all: 2
							},
							timeBorderRadius: 20,
							timeBgHeightRatio: 0.8,
							volumeSliderHeightRatio: 0.6,
							progressGradient: "none",
							height: 26,
							volumeColor: "#ACB700",
							tooltips: {
								marginBottom: 5,
								buttons: false
							},
							timeSeparator: " ",
							name: "controls",
							volumeBarHeightRatio: 0.2,
							opacity: 1,
							timeFontSize: 12,
							left: "50pct",
							tooltipColor: "rgba(0, 0, 0, 0)",
							volumeSliderColor: "#ffffff",
							bufferColor: "#a3a3a3",
							border: "0px",
							buttonColor: "#ffffff",
							durationColor: "#ACB700",
							autoHide: {
								enabled: true,
								hideDelay: 500,
								hideStyle: "fade",
								mouseOutDelay: 500,
								hideDuration: 400,
								fullscreenOnly: true
							},
							backgroundGradient: "none",
							width: "100pct",
							display: "block",
							sliderBorder: "1px solid rgba(128, 128, 128, 0.7)",
							buttonOverColor: "#ffffff",
							url: "flowplayer.controls-3.2.5.swf",
							fullscreen: true,
							progressColor: "#ACB700",
							timeBorder: "0px solid rgba(0, 0, 0, 0.3)",
							timeBgColor: "rgb(0, 0, 0, 0)",
							scrubberBarHeightRatio: 0.2,
							bottom: 0,
							builtIn: false,
							volumeBorder: "1px solid rgba(128, 128, 128, 0.7)",
							margins: [2, 12, 2, 12]
						}
					}
				}).ipad({ controls: true });
			}
		},
		onClose: function (el) {
			$("#sb-body-inner").html('');
		}
	});

	$(".shadowbox_open").live('click', function (e) {
		e.preventDefault();
		var shadowBoxClick = $(this);
		$("a.shadowbox_" + shadowBoxClick.attr('data-shadowbox') + ":first").trigger('click');
	});

	/*
	$(document).keydown(function (e) {
		if (e.keyCode === 39) {
			e.preventDefault();
			if (Shadowbox.hasNext()) {
				Shadowbox.next();
			}
		} else if (e.keyCode === 37) {
			e.preventDefault();
			Shadowbox.previous();
		}
	});
	*/
});

