// JavaScript Document
function kwickies() {
	var szNormal = 164, szSmall  = 85, szFull   = 315;
 
		var kwicks = $$("#kwicks .kwick");
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 1200, transition: Fx.Transitions.Back.easeInOut});

		kwicks.each(function(kwick, i) {
			var blurb = kwick.getFirst().getNext();
			blurbx = blurb.getStyle('margin-left').toInt();
			var bfxs = new Fx.Style(blurb, 'margin-left', {duration: 400, wait: false});

			kwick.addEvent("mouseenter", function(event) {
					var o = {};
					o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
					kwicks.each(function(other, j) {
						if(i != j) {
							var w = other.getStyle("width").toInt();
							if(w != szSmall) o[j] = {width: [w, szSmall]};
						}
					});
					fx.start(o);
					bfxs.start(blurbx,blurbx-45);
			});
		});
		 
		$('kwicks').addEvent('mouseleave', function(e){			
			var obj = {};
			kwicks.each(function(other, j){
				//alert(j);
				obj[j] = {'width': [other.getStyle('width').toInt(), 164]};				
			});
			fx.start(obj);
			
			var blurs = $$('div.blurbs');
			var bx = new Fx.Elements(blurs, {wait: false, duration: 1200});
			var b = {};
			blurs.each(function(blurr,k) {	
				b[k] = {'margin-left': [blurr.getStyle('margin-left').toInt(),198]};
			});
			bx.start(b);
			
		});
}

function tabbers(id) {
	var tabs = new SimpleTabs($('tabBlock'), {
		entrySelector: 'h4.sub'
		,show: id		
	});
	var myFunction = function(){
		$('content').setStyle('visibility','visible');
	}
	myFunction.delay(2000);
}

function showSqueezeBox() {
	idx = document.locate.locator.selectedIndex;
	urll = document.locate.locator.options[idx].value;
	SqueezeBox.fromElement('webroot/locator.php?loca='+urll, {size: {x: 620, y: 350}});
}

window.addEvent('domready', function(){	
			
		var dropmenus = $$('.menu li');
		dropmenus.each(function(item){
			item.addEvent('mouseover', function(){
				if(item.getFirst().getNext()) {
					item.getFirst().getNext().setStyle('opacity',1);
					item.getFirst().setStyle('color','#F85418');
				}
				//item.setStyle('background-color','#EEEEEE');
			})
			item.addEvent('mouseleave', function(){
				if(item.getFirst().getNext()) {
					item.getFirst().getNext().setStyle('opacity',0);
					item.getFirst().setStyle('color','#999999');	
				}
				//item.setStyle('background-color','');
			})
		});
		
		if ($('kwicks')) {
			kwickies();
		}
		
		if($('tabBlock')){	
			$('content').setStyle('visibility','hidden');
			if(location.search) {
				id = location.search.substr(location.search.indexOf('=',0)+1,1);
			} else {
				id = 0;	
			}
			tabbers(id);
		}
		
		if($('accordion')){
			var accordion = new Accordion('p.toggle', 'div.accord', {
				opacity: true,
				alwaysHide: true,
				display: -1
			}, $('accordion'));
		}
				
		if($('products')) {
			SqueezeBox.initialize({
				handler:'xframe',
				ajaxOptions: {
					method: 'get'
				}
			});

			$$('a.boxed').each(function(el) {
				el.addEvent('click', function(e) {
					new Event(e).stop();
					SqueezeBox.fromElement(el);
				});
			});
			

			$$('.panel-toggler').each(function(el) {
				var target = el.getLast().setStyle('display', 'none');
				el.getFirst().addEvent('click', function() {
					target.style.display = (target.style.display == 'none') ? '' : 'none';
				});
			});	
		}
		
		if($('kwicks') || $('tabBlock')) {
			SqueezeBox.initialize({
				//size: {x: 350, y: 400},
				handler:'xframe',
				ajaxOptions: {
					method: 'get'
				}
			});

			$$('a.boxed').each(function(el) {
				el.addEvent('click', function(e) {
					new Event(e).stop();
					SqueezeBox.fromElement(el);
				});
			});
			
		}		
		
}); 