var Atmo = function() {
	var	DOMReady = function() {
		_uacct = "UA-1910703-3";
		urchinTracker();
	};
	return {	
		init: function() {
			O.addOnDOMReady(DOMReady);
			Atmo.contentFilter.init();
			Atmo.clipHover.init();
			Atmo.sIFR.init();
			Atmo.shareLinks.init();
			Atmo.embedMovie.init();
			//Atmo.toggleNewsletterForm.init();
		}
	};
}();


Atmo.shareLinks = function() {
	return {
		init: function() {
			O.eventHandler.register("click", ".share A", function() {
				window.open(this.href, "_blank");
			});
		}
	}
}();


Atmo.contentFilter = function() {
	var duration = 1000;
	var delay = 50;

	return {
		init: function() {
			O.eventHandler.register("click", "A.content-filter", function() {
				var anchorElm = this;
				var searchFor = O.getClassNameValue(anchorElm, "show");
				var searchIn = O.getClassNameValue(anchorElm, "search");
				var filterAmong = O.getClassNameValue(anchorElm, "filter");
				
				$("." + searchIn + " ." + filterAmong).each(function() {
					elm = $(this);
					if(searchFor == "all" || elm.hasClass(searchFor)) {
						elm.setStyle(DOMEffects.getOpacityRule(0));
					} else {
						elm.setStyle("display", "none");
					}
				});
				
				var elms = 0;
				$("." + searchIn + " ." + filterAmong).each(function() {
					var elm = $(this);
					if(searchFor == "all" || elm.hasClass(searchFor)) {
						elm.setStyle("display", "block");
						setTimeout(function() { elm.show( { duration: duration,  easing: O.easing.expoOut } ) }, elms*delay);
						elms++;
					}
				});
				
				$("A.content-filter").each(function() {
					$(this).removeClass("content-filter-active");
				});
				$(anchorElm).addClass("content-filter-active");
			});
		}
	}
}();


/*Atmo.embedMovie = function() {
	var video;
	var url;
	var pos;
	var movieContainer;
	var volumeBarContainer;
	var volumeBar;
	var volumeBarLength = 40;
	var volumeBarX = 0;
	var volume = 50;
	var positionBarContainer;
	var positionBar;
	var positionBarLength = 500;
	var positionBarX = 0;
	var position = 0;

	var togglePlay = function(initPos) {
		if (!video) {
			var loader = movieContainer.create("div", { id: "loader" }, true, "loading");
			video = soundManager.createVideo({
			    id: "movie",
			    url: url,
			    volume: 0,
			    autoPlay: false,
			    autoLoad: true,
			    whileplaying: updatePosition,
			    onfinish: finish,
			    onload: show
			});
			video.setVolume(0);
		}

		if (video.loaded && video.playState === 0) {
			video.setPosition(0);
			video.play();
		} else {
			if (video.paused) {
				video.resume();
			} else {
				video.pause();
			}
		}
		togglePlayButton();
	};

	var show = function() {
		video.setPosition(0);
		video.setVolume(volume);
		video.play();
		soundManager.oMC.style.width = "600px";
		soundManager.oMC.style.height = "338px";
		soundManager.oMC.style.left = pos.x + "px";
		soundManager.oMC.style.top = pos.y + "px";
	};

	var togglePlayButton = function() {
		var playButton = $$("play-movie-button");
		if (playButton.hasClass("play")) {
			playButton.className = "pause";
			playButton.innerHTML = "Pause";
		} else {
			playButton.className = "play";
			playButton.innerHTML = "Play";
		}
	};

	var updatePosition = function() {
		if (video.loaded) {
			var length = Math.round(positionBarLength*(this.position/this.duration));
			if (length != position) {
				positionBar.setStyle("width", length + "px");
				position = length;
			}
		}
	};

	var finish = function() {
		togglePlayButton();
		video.stop();
	}

	var setVolume = function(volume) {
		var l = Math.ceil(volumeBarLength*(volume/100));
		volumeBar.setStyle("width", l + "px");
		if (video) {
			video.setVolume(volume);
		}
		O.writeCookie("video-volume", volume, 14);
	};

	var getClickPosition = function(e) {
		var posx = 0;
		var posy = 0;
		if (e.pageX || e.pageY) 	{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		return { x: posx, y: posy };
	};

	return {
		init: function() {
			soundManager.url = "/www.secure/flash/soundManager/";
			soundManager.flashVersion = 9;
			soundManager.useMovieStar = true;
			soundManager.useVideo = true;
			soundManager.allowFullScreen = true;
			//soundManager.debugMode = false;
			soundManager.onload = function() {
				movieContainer = $$("movie");
				if(movieContainer) {
					url = O.getClassNameValue(movieContainer, "src");
					pos = O.getPosition(movieContainer);
					var controls = movieContainer.create("div", { id: "movie-controls" }, true);
					var html = "<a href=\"#\" id=\"play-movie-button\" class=\"play\">Play</a>";
					html += " <span id=\"movie-position\"><span></span></span>";
					html += " <span class=\"txt\">Vol:</span> <span id=\"movie-volume\"><span></span></span>";
					controls.innerHTML = html;
					O.eventHandler.register("click", "#play-movie-button", function() {
						togglePlay();
					});

					// position bar handling
					positionBarContainer = $$("movie-position");
					positionBarLength = O.stripPx(positionBarContainer.getStyle("width"));
					positionBar = $($("#movie-position span")[0]);
					positionBarX = O.getPosition($$("movie-position")).x;
					O.eventHandler.register("click", "#movie-position", function(e) {
						if (!e) var e = window.event;
						if (video) {
							var pos = 0;
							var posInBar = ((getClickPosition(e).x - positionBarX)/positionBarLength);
							if (posInBar > 0.01) {
								pos = Math.floor(video.duration * posInBar);
							}
							video.setPosition(pos);
						}
					});
					
					// volume bar handling
					volumeBarContainer = $$("movie-volume");
					volumeBar = $($("#movie-volume span")[0]);
					volumeBarLength = O.stripPx(volumeBarContainer.getStyle("width"));
					volumeBarX = O.getPosition(volumeBarContainer).x;
					O.eventHandler.register("click", "#movie-volume", function(e) {
						if (!e) var e = window.event;
						var pos = 0;
						var posInBar = ((getClickPosition(e).x - volumeBarX)/volumeBarLength);
						var volume = Math.ceil(posInBar*100);
						volume = volume > 97 ? 100 : (volume < 10 ? 0 : volume);
						setVolume(volume);
					});
					
					// check if volume is preset in a cookie
					var preSetVolume = O.readCookie("video-volume");
					if (preSetVolume) { setVolume(preSetVolume); }
				}
			}
		}
	};
}();*/

Atmo.embedMovie = function() {
	var playerPath = "/www.secure/flash/player.swf";
	var skinPath = "/www.secure/flash/dangdang.swf";
	
	var params = {
		allowfullscreen: "true",
		allowscriptaccess: "always"
	};
	
	var settings = {
		author: "Atmo",
		file: "",
		image: "",
		duration: "0",
		skin: skinPath,
		stretching: "exactfit"
	};
	
	var DOMReady  = function() {
		var movieContainer = $$("movie");
		if(movieContainer) {
			settings.file = O.getClassNameValue(movieContainer, "src");
			settings.image = $("#movie img")[0].src;
			settings.duration = O.getClassNameValue(movieContainer, "duration");
			swfobject.embedSWF(playerPath, "movie", "600", "368", "9", "", settings, params, false);
		}
	}

	return {
		init: function() {
			O.addOnDOMReady(DOMReady);
		}
	}
}();



/*Atmo.toggleNewsletterForm = function() {
	var duration = 500;
	return {
		init: function() {
			O.eventHandler.register("click", ".toggle-newsletter-form", function() {
				var elm = $($("#newsletter form")[0]);
				if(elm.getStyle("height") == "0px") {
					elm.animate({"height": 70}, {duration: duration, easing: O.easing.expoOut, callback: function() {
						$$("newsletter-email").focus();
					}});
				} else {
					elm.animate({"height": 0}, {duration: 1});
				}
			});
		}
	}
}();*/


Atmo.clipHover = function() {
	return {
		init: function() {
			O.eventHandler.register("mouseover", ".clips .teaser", function() {
				$(this).addClass("hover");
			});
			O.eventHandler.register("mouseout", ".clips .teaser", function() {
				$(this).removeClass("hover");
			});
		}
	}
}();


Atmo.sIFR = function() {
	var publico = {	src: "/www.secure/flash/publico.swf" };
	var publicoRatios = [9, 1.16, 16, 1.09, 24, 1.06, 37, 1.04, 74, 1.02, 1.01];
	var DOMReady = function() {	render(); };

	var render = function() {
		if (typeof sIFR !== "undefined") {
			sIFR.replace(publico, {
			    selector: '#header .news li',
				css: [ 
					"a { color: #000000; text-align: right; text-decoration: none; }",
					".entry-word { color: #ff0000; }",
					"a:hover { color: #ff0000; }"
				],
				ratios: publicoRatios
			});
			sIFR.replace(publico, {
			    selector: '.extra-teaser',
				css: [ 
					"a { color: #000000; text-decoration: none; margin-right: 50px; }",
					".entry-word { color: #ff0000; }",
					"a:hover { color: #ff0000; }"
				],
				ratios: publicoRatios
			});
		}
	};

	return {
		init: function() {
			if (typeof sIFR !== "undefined") {
				sIFR.activate(publico);
				O.addOnDOMReady(DOMReady);
			}
		}
	};
}();


Atmo.init();