// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var ResizeSlider = Class.create();
ResizeSlider.prototype = {
	initialize: function() {
		this.timer = null;
		this.WINDOW_RESIZE_INTERVAL = new Date().getTime();
		this.INTERVAL = 100;
	},
	prepare: function() {
		if (!this.timer)
			this.timer = setInterval(this.onTimerEvent.bind(this), this.INTERVAL);
		this.WINDOW_RESIZE_INTERVAL = new Date().getTime();
	},
	show: function() {

		var o = $("hm").cumulativeOffset();
		var d = $("hm").getDimensions();
		Element.setStyle($("slider1"), {
		left:o[0] + "px",
		top:o[1] + d.height + "px"
		});
		Element.setStyle($("slider2"), {
		left:o[0] + "px",
		top:o[1] + d.height + "px"
		});
		Element.setStyle($("slider3"), {
		left:o[0] + "px",
		top:o[1] + d.height + "px"
		});
		Element.setStyle($("slider4"), {
		left:o[0] + "px",
		top:o[1] + d.height + "px"
		});
		Element.setStyle($("slider5"), {
		left:o[0] + "px",
		top:o[1] + d.height + "px"
		});	
	},

	onTimerEvent: function() {
		if (this.INTERVAL < new Date().getTime() - this.WINDOW_RESIZE_INTERVAL) {
			this.show();
			clearInterval(this.timer);
			this.timer = null;
		}
	}
}

var JSHelper = {
	slider: function() {
		var n = document.getElementsByClassName("slider_menu");
		if (n.length) {
			for (var i = 0; i < n.length; i++) {
				n[i].href = "javascript:void(0)";
				Event.observe(n[i].firstChild, "dblclick", function() {
					Event.stopObserving(this, "click", function(){}, false);
					return false;
				}, false);
				Event.observe(n[i].firstChild, "click", function() {
					JSHelper.sliderClose(this.parentNode.title);
					/*
					new Effect.Opacity(this.parentNode.title, { 
					from:0.5,
					to:0.999999,
					delay:1,
					beforeStartInternal: function(effect) { 
						var n = document.getElementsByClassName("slider_close");
						if (n) {
							for (var i = 0; i < n.length; i++) {
								Element.hide(n[i]);
							}
						}
					}, 
					afterFinishInternal: function(effect) {
						var n = document.getElementsByClassName("slider_close");
						if (n) {
							for (var i = 0; i < n.length; i++) {
								Element.show(n[i]);
							}
						}
					}
					});
					*/
					var o = $("hm").cumulativeOffset();
					var d = $("hm").getDimensions();
					Element.setStyle($(this.parentNode.title), {
					left:o[0] + "px",
					top:o[1] + d.height + "px"
					});
					//close
					if (this.parentNode.getAttribute("open") == "true") {
						this.parentNode.setAttribute("open", "false");
						Element.setStyle($(this.parentNode.title), {display:"none", visibility:"hidden"});
						//new Effect.SlideUp(this.parentNode.title);
						var suffix = ".gif";
						this.onmouseout = function() { 
							var img = new Image();
							img.src = this.getAttribute("file") + ".gif" + "?" + new Date().getTime();
							img.onload = (function(i){
								return function(e) {
									i.src = this.src; 
								}
							})(this);
						};
						this.onmouseover = function() { 
							var img = new Image();
							img.src = this.getAttribute("file") + "-on.gif" + "?" + new Date().getTime();
							img.onload = (function(i){
								return function(e) {
									i.src = this.src; 
								}
							})(this);
						};
					//open
					} else {
						this.parentNode.setAttribute("open", "true");
						Element.setStyle($(this.parentNode.title), {display:"block", visibility:"visible"});
						//new Effect.SlideDown(this.parentNode.title);
						if (this.parentNode.title == "slider1") {
							cd.get();
						}

						var suffix = ".gif";
						var img = new Image();
						img.src = this.getAttribute("file") + "-op" + suffix + "?" + new Date().getTime();
						img.onload = (function(i){
							return function(e) {
								i.src = this.src;
							}
						})(this);
						/*
						Event.observe(img, "load", (function(i){
							return function(e) {
								alert(this.src);
								i.src = this.src;
							}
						})(this), false);
						*/
						this.onmouseout = function(){};
						this.onmouseover = function(){};
					}
				}, false);
			}
		}
	},
	sliderOpen: function(title) {
		JSHelper.sliderClose();
		var n = document.getElementsByClassName("slider_menu");
		if (n.length) {
			for (var i = 0; i < n.length; i++) {
				if (n[i].title == title) {
					var suffix = ".gif";
					var img = new Image();
					img.src = n[i].firstChild.getAttribute("file") + "-op" + suffix + "?" + new Date().getTime();
					img.onload = (function(i){
						return function(e) {
							i.src = this.src;
						}
					})(n[i].firstChild);
					n[i].firstChild.onmouseover = function(){};
					n[i].firstChild.onmouseout = function(){};
					//new Effect.Opacity(title, {from:0.1, to:0.999999});
					var o = $("hm").cumulativeOffset();
					var d = $("hm").getDimensions();
					Element.setStyle(title, {
					left:o[0] + "px",
					top:o[1] + d.height + "px"
					});
					n[i].setAttribute("open", "true");
					Element.setStyle($(title), {display:"block", visibility:"visible"});
					//new Effect.SlideDown(title, {from:0.9, to:0.999999});
					if (title == "slider1") {
						cd.get();
					}
				}
			}
		}
	},


	sliderClose: function(title) {
		var n = document.getElementsByClassName("slider_menu");
		if (n.length) {
			for (var i = 0; i < n.length; i++) {
				if (n[i].title != title) {
					n[i].setAttribute("open", "false");
					Element.setStyle($(n[i].title), {display:"none", visibility:"hidden"});
					//new Effect.SlideUp(n[i].title);
					var file = n[i].firstChild.getAttribute("file");
					var suffix = ".gif";
					n[i].firstChild.setAttribute("src", file + suffix);
					var img = new Image();
					img.src = file + suffix;
					Event.observe(img, "load", (function(i) {
						return function(e) {
							i.src = this.src; 	
						}
					})(n[i].firstChild), false);
					n[i].firstChild.onmouseout = function() { 
						var img = new Image();
						img.src = this.getAttribute("file") + ".gif" + "?" + new Date().getTime();
						img.onload = (function(i){
							return function(e) {
								i.src = this.src; 
							}
						})(this);
					};
					n[i].firstChild.onmouseover = function() {
						var img = new Image();
						img.src = this.getAttribute("file") + "-on.gif" + "?" + new Date().getTime();
						img.onload = (function(i){
							return function(e) {
								i.src = this.src; 
							}
						})(this);
					};
				}
			}
		}
	},


	lightbox: function(li, lp) {
		
		var n = document.getElementsByName("lightboxitem");
		if (n.length) {
			for (var i = 0 ; i < n.length; i++) {
				n[i].setAttribute("title", n[i].getAttribute("href"));
				n[i].setAttribute("href", "javascript:void(0)");
				Event.observe(n[i], "click", (function(li) {
					return function(e) {
						LBItem(this.getAttribute("title"));
					}
				})(li), false);
			}
		}
		
		//var n = document.getElementsByClassName("lightboxpage");
		var n = document.getElementsByName("lightboxpage");
		if (n.length) {
			for (var i = 0 ; i < n.length; i++) {
				n[i].setAttribute("title", n[i].getAttribute("href"));
				n[i].setAttribute("href", "javascript:void(0)");
				Event.observe(n[i], "click", (function(lp) {
					return function(e) {
						lp.show(this.getAttribute("title"));
					}
				})(lp), false);
			}
		}
	},
	
	flash1: function() {
		var src = "";
		var MM_contentVersion = 8;
		 
		var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
		if ( plugin ) {
				var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			    for (var i = 0; i < words.length; ++i)
			    {
				if (isNaN(parseInt(words[i])))
				continue;
				var MM_PluginVersion = words[i]; 
			    }
			var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
		}
				
		src +='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		src +=' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
		src +=' ID="index" WIDTH="100%" HEIGHT="330px">';
		src +=' <PARAM NAME=movie VALUE="/swf/main.swf"> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=scale VALUE=noscale>  <PARAM NAME=bgcolor VALUE=#000000> <param NAME=wmode VALUE=transparent>';
		src +=' <EMBED src="/swf/main.swf" menu=false quality=high scale=noscale bgcolor=#000000 wmode=transparent';
		src +=' swLiveConnect=FALSE WIDTH="100%" HEIGHT="330px" NAME="index" ';
		src +=' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.adobe.com/go/getflashplaye"> ';
		src +=' </EMBED> ';
		src +=' </OBJECT> ';
		if ($("flash"))
			$("flash").innerHTML = src;		
	},
	
	flash2: function() {
		var src = "";
		var MM_contentVersion = 8;
		var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
		if ( plugin ) {
				var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			    for (var i = 0; i < words.length; ++i)
			    {
				if (isNaN(parseInt(words[i])))
				continue;
				var MM_PluginVersion = words[i]; 
			    }
			var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
		}
		src +='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		src +=' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
		src +=' ID="index" WIDTH="100%" HEIGHT="152px">';
		src +=' <PARAM NAME=movie VALUE="/swf/under.swf"> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=high> <PARAM NAME=scale VALUE=noscale>  <PARAM NAME=bgcolor VALUE=#191919> <param NAME=wmode VALUE=transparent>';
		src +=' <EMBED src="/swf/under.swf" menu=false quality=high scale=noscale bgcolor=#191919 wmode=transparent';
		src +=' swLiveConnect=FALSE WIDTH="100%" HEIGHT="152px" NAME="index"  align="middle" ';
		src +=' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.adobe.com/go/getflashplaye"> ';
		src +=' </EMBED> ';
		src +=' </OBJECT> ';
		
		if ($("itemArea"))
			$("itemArea").innerHTML = src;	
	}
}



var LBItem = function(url) {
	if (window.location.pathname == "/")
		cd.clear();
	li.show(url);
}
var LBPage = function(url) {
	lp.show(url);
}
var Recalc = function() {
	document.recalc(true);
}

var OverlayContainerDialog = null;
var DisabledWindowDialog = function() {
	if (!OverlayContainerDialog) {
		Control.Overlay.load();
		Control.Overlay.show("0.6");
		OverlayContainerDialog = Control.Overlay.container;
		Event.observe(OverlayContainerDialog, "click", function() {
			this.parentNode.removeChild(this);
			OverlayContainerDialog = null;
			delete OverlayContainerDialog;
		}, false);
	}
}

var DisabledWindowDialogClose = function() {
	if (OverlayContainerDialog) {	
		OverlayContainerDialog.parentNode.removeChild(OverlayContainerDialog);
		OverlayContainerDialog = null;
		delete OverlayContainerDialog;
	}
}

var DisabledWindowSearch = function() {
	Control.Overlay.load();
	Control.Overlay.show("0.6");
}
