/*—~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ M A I N.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

mainClass = new Class({

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I N I T.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INITIALIZE.
	initialize: function() {
		// Preload.
		new Asset.images(["/images/homeEnter_out.png", "/images/homeEnter_over.png", "/images/menuFooterFrame-branch-token.png"]);
		// XHR Options.
		xhrOptions = {
			url: "siteData.php",
			method: "post",
			encoding: "utf-8",
			urlEncoded: true,
			link: "ignore"
		};
		// Init.
		this.fontEmbeddingCufon();
		this.mainRolloverImage();
		this.frameInit();
		this.googleAnalyticsInit();
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FRAMES.
	frameInit: function() {
		if ($chk($('homeFrame'))) {
			//galleryHandler = new galleryClass();
			pictureGalleryHomeObj = new gallery($('pictureGalleryHome'), {
				delay: 3000,
				timed: true,
				showArrows: false,
				showCarousel: false,
				showInfopane: false,
				imageSelector: "img.pictureBig"
			});
		}
		else if ($chk($('pictureFrame'))) {
			pictureFrameMorph = new Fx.Morph('pictureFrame', {duration: "normal", transition: Fx.Transitions.Sine.easeOut}); //Fx.Transitions.Cubic.easeOut
			if ($('pictureGallery').getFirst('div.pictureSet')) {
				pictureFrameMorph.set({
					left: 20,
					width: 848
				});
				albumGallery = new gallery($('pictureGallery'));
			}
		}
		/*else if ($chk($('biographyFrame'))) {
			$('mediasList').getElements('li').each(function(tagObj, i) {
				if (i == 0)
					tagObj.setStyle('padding-left', '0px');
				tagObj.set('opacity', 0.5);
				tagObj.addEvents({
					'mouseenter': function() {
						tagObj.fade(1);
					},
					'mouseleave': function(){
						tagObj.fade(0.5);
					}
				});
			});
		}*/
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GOOGLE ANALYTICS.
	googleAnalyticsInit: function() {
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		new Asset.javascript(gaJsHost + "google-analytics.com/ga.js", {
			onload: function() {
				var pageTracker = _gat._getTracker("UA-2001926-2");
				pageTracker._initData();
				pageTracker._trackPageview();
			}
		});
	},


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ F O N T   E M B E D D I N G.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	fontEmbeddingCufon: function() {
		var cufonOptions = {
			fontFamily: "Ameretto Extended Bold",
			forceHitArea: true,
			separate: "characters",
			hover: {
				color: "-linear-gradient(#b3b3b3, #393939)"
			}			
		};
		Cufon.replace('h1, h4', $merge(cufonOptions, {textShadow: "#444444 1px 1px"}));
		Cufon.replace('h2, h3', $merge(cufonOptions, {textShadow: "#222222 1px 1px"}));
	},
	
	fontEmbeddingSifr: function() {
		var replacementFlashMovie = {src: "images/Ameretto-Extended.swf"};
		var replacementFlashCss = {
			'.sIFR-root': {'color':"#ffffff", 'font-weight':"bold"},
			'a': {'color':"#ffffff", 'text-decoration':"none"},
			'a:hover': {'color':"inherit", 'text-decoration':"underline"},
			'del': {'color':"#b3b3b3", 'display':"inline"},
			'dfn': {'color':"#b3b3b3", 'display':"inline"}
		};
		sIFR.activate(replacementFlashMovie);
		sIFR.replace(replacementFlashMovie, {
			selector: "h1, h2",
			css: replacementFlashCss,
			wmode: "transparent",
			selectable: true,
			filters: {
				Glow: {
					strength: 0.5,
					blurY: 6,
					blurX: 6,
					knockout: false,
					inner: false,
					quality: 3,
					alpha: 100,
					color: "#ffffff"
				}
			}
		});
		sIFR.replace(replacementFlashMovie, {
			selector: "h3, h4",
			css: replacementFlashCss,
			wmode: "transparent",
			selectable: true
		});
	},


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ R O L L — O V E R S.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~ ROLL-OVER BACKGROUND EFFECT – ADD.
	mainRolloverFxBackground: function(tagObj, colorOver) {
		if (!$chk(tagObj.colorOut))
			tagObj.colorOut = tagObj.getStyle('background-color');
		//if (!$chk(tagObj.colorOver))
		tagObj.colorOver = colorOver;	
		tagObj.fx = new Fx.Tween(tagObj, {
			property: "background-color",
			duration: "short",
			link: "cancel"
		});
		if ((tagObj.get('tag') == "input") && (tagObj.get('type') == "text")) {
			tagObj.addEvents({
				focus: function() {
					fieldOnFocus(tagObj);
					tagObj.fx.start(tagObj.colorOver);
				},
				blur: function() {
					tagObj.fx.start(tagObj.colorOut);
				}
			});
		}
		else {
			tagObj.addEvents({
				mouseenter: function() {
					tagObj.fx.start(tagObj.colorOver);
				},
				mouseleave: function() {
					if (tagObj != menuHandler.menuAccordionCurrent)
						tagObj.fx.start(tagObj.colorOut);
				}
			});
		}
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~ ROLL-OVER BACKGROUND EFFECT – REMOVE.
	mainRolloverFxBackgroundRemove: function(tagObj) {
		delete tagObj.colorOut;
		delete tagObj.colorOver;
		delete tagObj.fx;
		if ((tagObj.get('tag') == "input") && (tagObj.get('type') == "text")) {
			tagObj.removeEvents('focus');
			tagObj.removeEvents('blur');
		}
		else {
			tagObj.removeEvents('mouseenter');
			tagObj.removeEvents('mouseleave');
		}
	},


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ROLL-OVER IMAGES.
	mainRolloverImage: function() {
		$('mainFrame').getElements('img').each(function(imgObj, i) {
			imgSrc = imgObj.get('src');
			if (imgSrc.test("_out")) {
				var imgPath = imgSrc.substring(0, imgSrc.lastIndexOf('_'));
				var imgExtension  = imgSrc.substr(imgSrc.lastIndexOf('.'));
				var imgSize = imgObj.getSize();
				var linkObj = imgObj.getParent();
				linkObj.setStyles({
					position: "relative"
				});
				linkObj.outObj = imgObj;
				linkObj.overObj = new Element('img', {
					src: imgPath+"_over"+imgExtension,
					styles: {
						'position': "absolute",
						'top': 0+"px",
						'left': 0+"px",
						'z-index': 10
					}
				}).inject(linkObj).fade('hide');
				linkObj.addEvents({
					mouseenter: function() {
						linkObj.overObj.fade('in');
						//linkObj.outObj.fade('out');
					},
					mouseleave: function() {
						linkObj.overObj.fade('out');
						//linkObj.outObj.fade('in');
					}
				});
			}
		});
	}

});



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ O N   D O M   R E A D Y.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
window.addEvent('domready', function() {
	mainHandler = new mainClass();
});

