/**
 * Javascript Core for ghyllside.com
 * 
 * Library = YUI 2.51
 * @author AppSol
 * @version 0.1
 */
var YD = YAHOO.util.Dom;
var YE = YAHOO.util.Event;
var $ = YD.get;
YAHOO.namespace('ghyllside');
YAHOO.ghyllside.content = {
		imgLinks : null,
		sideImgs : null,
		toolTip : null,
		init : function(){
			this.imgLinks = YD.getElementsByClassName('img_link', 'span', 'page_copy');
			this.sideImgs = document.getElementById('images').getElementsByTagName('img');
			YE.on(this.imgLinks, 'mouseover',this.highLight, this, true);
			YE.on(this.imgLinks, 'mouseout', this.lowLight, this, true);
			YE.on(this.imgLinks, 'click', this.panelPop, this, true);
			YE.on(this.sideImgs, 'mouseover', this.highLight, this, true);
			YE.on(this.sideImgs, 'mouseout', this.lowLight, this, true);
			YE.on(this.sideImgs, 'click', this.panelPop, this, true);
			this.toolTip = new YAHOO.widget.Tooltip('imgTooltip', {
				context: this.sideImgs,
				text : 'Click for a larger image',
				showDelay : 500
			});
			this.toolTip = new YAHOO.widget.Tooltip('imgTooltip', {
				context: this.imgLinks,
				text : 'Click for a larger image',
				showDelay : 500
			});
		},
		highLight : function(e){
			var source = this.imageSelect(YE.getTarget(e));
			YD.addClass(source, 'hover');
		},
		lowLight : function(e){
			var source = this.imageSelect(YE.getTarget(e));
			YD.removeClass(source, 'hover');
		},
		panelPop : function(e){
			var source = this.imageSelect(YE.getTarget(e));
			var imgDim = YD.getRegion(source);
			var imgWidth = imgDim['right'] - imgDim['left'];
			var imgHeight = imgDim['bottom'] - imgDim['top'];
			var panelWidth = imgWidth > imgHeight? 456 : 301;
			var imgSrc = String(source.src);
			var imgArr = imgSrc.split('_tmb');
			imgSrc = imgArr[0]+imgArr[1];
			var panel = new YAHOO.widget.Panel("room_view",{
				width : panelWidth+"px",
				underlay : "matte",
				fixedcenter : true,
				close : true,
				visible : true,
				draggable : false,
				modal : true,
				effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}});
			panel.setHeader(source.alt);
			panel.setBody('<img src="'+imgSrc+'" alt="'+source.alt+'" />');
			panel.render(document.body);
		},
		imageSelect : function(source){
			if(source.tagName.toLowerCase() == 'span'){
				var spanClass = source.className;
				var classNames = spanClass.split(' ');
				source = document.getElementById(classNames[0]);
			}
			return source;
		}
	}
YAHOO.util.Event.onDOMReady(YAHOO.ghyllside.content.init, YAHOO.ghyllside.content, true);