///////////////////////////////////////////////////////////////////////////////

Fx.BgY = Fx.Base.extend({

	initialize: function(el, options){
		this.element = $(el);
		this.setOptions(options);
		return this;
	},

	increase: function(){
		this.setStyle(this.element, 'backgroundPosition', 'center '+this.now);
	}

});

///////////////////////////////////////////////////////////////////////////////

function subnav()
{
	
	if(window.ie6) return false;
	
	var timer_bubble_on, timer_bubble_off, timer_ajax;
	var loading = '<div class="loading">Loading&hellip;</div>';

	var bubble = new Element('div').setProperty('id', 'js-bubble').setStyle('display', 'none');
	new Element('div').setProperty('id', 'js-bubble-top').injectInside(bubble);
	bubble.mid = new Element('div').setProperty('id', 'js-bubble-mid').setHTML(loading).injectInside(bubble);
	new Element('div').setProperty('id', 'js-bubble-bot').injectInside(bubble);
	bubble.injectInside(document.body);
	
	$$('div#nav ul.main li').each(function(li){
		
		li.a = $E('a.product', li);
		li.ul = $E('ul', li);
		
		if(li.ul) li.addClass('js-has-child');

		li.addEvent('mouseover', function(e){
			e = new Event(e);
			if(e.target != this) {
				e.stop();
				
				this.addClass('js-hover');
				
				if(this.a && !this.ul) {
					timer_bubble_on = (function(){
						this.addClass('js-bubble');
						var coor = this.getCoordinates();
						bubble.setStyles({
							display:'block',
							left:	coor.left+coor.width-20+'px',
							top:	coor.top-30+'px'
						});
						timer_ajax = (function(){
							new Ajax(
								webroot+'/products/util_brief'+this.a.href.substring(this.a.href.lastIndexOf('/')),
								{method: 'get', update: bubble.mid}
							).request();
						}).delay(250, this);
					}).delay(500, this);
				}
				
			}
		});

		li.addEvent('mouseout', function(e){
			e = new Event(e);
			if(e.target != this) {
				e.stop();
				
				$clear(timer_bubble_on);
				$clear(timer_ajax);
				this.removeClass('js-hover');
				
				timer_bubble_off = (function(){
					this.removeClass('js-bubble');
					bubble.setStyle('display', 'none');
					bubble.mid.setHTML(loading);
				}).delay(100, this);
				
			}
		});
		
	});
	
}

///////////////////////////////////////////////////////////////////////////////

function flashBanner(show_flash) {
	
	if(show_flash) {
		var so = new SWFObject(webroot+"/files/flash/banner"+(webroot != "" ? ".local" : "")+".swf", "banner-swf", "740", "140", "8", "#ffffff");
		so.addParam("wmode", "opaque");
		so.write("banner");
	} else {
		banner.setHTML(banner.html);
		banner.onclick = function(){ flashBanner(true) };
	}

}

///////////////////////////////////////////////////////////////////////////////

var webroot = (location.host == '192.168.1.3') ? '/DerrickCorpequipment.com' : '';
var banner;

Window.onDomReady(function(){
	
	subnav();
	
	banner = $('banner');
	if(banner) {
		banner.html = banner.innerHTML;
		flashBanner(true);
	}

});

