// JavaScript Document
function stageload() {
	var leftheight = $('body_left').getStyle('height').toInt();
	var rightheight = $('body_right').getStyle('height').toInt();
	if (leftheight > rightheight) {
		$('body_right').setStyle('height', leftheight);
	}
	var myTips = new Tips($$('.toolTipElement'), {
		timeOut: 700,
		maxTitleChars: 50,
		maxOpacity: .7
	});
}
function tipsecho () {
	if ($('acc_body').getStyle('height').toInt() > 0) {
		$('acc_title').store('tip:title', 'Details');
 		$('acc_title').store('tip:text', "Click on the accessories below to get more details.");
		$('comp_title').store('tip:title', 'Expand');
 		$('comp_title').store('tip:text', "Click here to view the computer sets.");
	} else if ($('comp_body').getStyle('height').toInt() > 0) {
		$('comp_title').store('tip:title', 'Details');
 		$('comp_title').store('tip:text', "Click on the computers below to get more details.");
		$('acc_title').store('tip:title', 'Expand');
 		$('acc_title').store('tip:text', "Click here to view the accessories.");
	}
}
function menuhover() {
	$$('.menu_body').addEvents({
		'mouseenter': function(){
			this.setStyles({'cursor': 'pointer','background-color': '#e2d5bf'});
		},
		'mouseleave': function(){
			this.setStyle('background-color', '');
		},
		'click': function() {
			var url = this.getChildren('a').get('href');
			location.href = url;
		}
	});	
}
function accordprev () {
	var compheight = $('comp_body').getStyle('height');
	var accheight = $('acc_body').getStyle('height');
	var windowwidth = $(document.body).getSize().x;
	var popwidth = ((40*windowwidth)/100).toInt();
	var css = $('linker_css').get('class');
	var srollpos = 0;
	$('comp_body').tween('height', 0);
	//preview titles
	$$('.prev_title').addEvents ({
		'mouseleave': function(){
			this.setStyle('cursor', 'pointer');
			tipsecho();
		},
		'mouseenter': function(){
			this.setStyle('cursor', 'pointer');
			tipsecho();
		},
		'click': function () {
			if ($('acc_body').getStyle('height').toInt() > 0) {
				$('acc_arrow').set('src', 'images/'+css+'/prevclosed.gif');
				$('comp_arrow').set('src', 'images/'+css+'/prevopen.gif');
				new Fx.Tween('comp_body').start('height', compheight);
				new Fx.Tween('acc_body').start('height', 0).chain(function() {
					tipsecho();
				});
			} else if ($('comp_body').getStyle('height').toInt() > 0) {
				$('acc_arrow').set('src', 'images/'+css+'/prevopen.gif');
				$('comp_arrow').set('src', 'images/'+css+'/prevclosed.gif');
				new Fx.Tween('comp_body').start('height', 0).chain(function() {
					tipsecho();
				});
				new Fx.Tween('acc_body').start('height', accheight)
			}
		}
	});
	//preview body
	$$('.prev_hands').addEvents ({
		'mouseenter': function(){
			this.setStyle('cursor', 'pointer');
		},
		'click': function() {
			$('messpop_content').addClass('ajaxload');
			$('blocker').setStyles({'display': 'block', 'height': $(document.body).getScrollSize().y+'px', 'opacity': 0});
			new Fx.Tween('blocker').start('opacity', .5);
			srollpos = $(document.body).getScroll().y;
			new Fx.Scroll(window).toTop();
			$('messpop_wrapper').setStyles({'display': 'block', 'opacity': 0});
			$('messpop_wrapper').morph({
				'opacity': .9,
				'width':[0,popwidth]
			});
			var catreq = this.getParent('div').get('id');
			var itemreq = this.getParent('tr').get('id');
			new Request.HTML({
				url: 'ajaxvault/popmsg.php?category='+catreq+'&item='+itemreq,
				onSuccess: function(HTML) {
					$('messpop_content').removeClass('ajaxload');
					$('messpop_content').adopt(HTML);
				}
			}).send();
		}
	});
	$('mess_close').addEvents ({
		'mouseenter': function() {
			this.setStyle('cursor', 'pointer');
		},
		'click': function() {
			$('messpop_content').empty().addClass('ajaxload');
			new Fx.Morph('messpop_wrapper').start({
				'width':0,
				'opacity': 0
			}).chain(function() {
				new Fx.Tween('blocker').start('opacity', 0);
				new Fx.Scroll(window).start(0, srollpos);
				$('blocker').setStyle('display', 'none');
				$('messpop_wrapper').setStyle('display', 'none');
			});
		}
	});
}
window.addEvent('domready', function(){stageload(),tipsecho(),menuhover(),accordprev()});