window.addEvent('domready',init);

function init(){
	initDropdowns();
	initFinishTips();
	initCollectionTips();
	initDomRollovers();
}

//Image rollovers
initDomRollovers = function() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1]);
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}

initDropdowns = function(){
	var d_container = $('dropdown_container')
	var d_buttons = $$('.dropdownButton');
	var d_menus = $$('.menu');
	
	var d_timer;
	var b_timer;
	var d_function;
	var b_function;
	var current_active;
	
	d_buttons.getElement('img').setStyle('visibility','hidden');
	
	d_buttons.addEvents({
		'mouseenter': function(){
			d_timer = $clear(d_timer)
			b_timer = $clear(b_timer)
			
			if(current_active){
				if(this!=current_active){
					current_active.getElement('img').setStyle('visibility','hidden');	
				}
			}
			
			d_container.setStyle('visibility','visible');
			this.getElement('img').setStyle('visibility','visible');
			
			adjustSize(this.name);
			
		},
		'mouseleave': function(){
			current_active = this;
			
			d_function = function(){
				d_container.setStyle('visibility','hidden');
				current_active.getElement('img').setStyle('visibility','hidden');
			}
			d_timer = d_function.delay(300);
				
		}
		
	});
	
	d_menus.addEvents({
		'mouseenter': function(){
			d_timer = $clear(d_timer)
		},
		'mouseleave': function(){
			d_entered=false;
			
			b_function = function(){
				d_container.setStyle('visibility','hidden');
				current_active.getElement('img').setStyle('visibility','hidden');
			}			
			b_timer = b_function.delay(300);
		}
		
	});
	
}

adjustSize=function(which){
	
	$('d_collections').setStyle('display', 'none');
	$('d_finishes').setStyle('display', 'none');
	$('d_newproducts').setStyle('display', 'none');
	$('d_about').setStyle('display', 'none');
	
	switch(which){
		case "collections":
		$$('.menu').setStyle('width', 860);
		$$('.menu').setStyle('height', 280);
		$$('.menu').setStyle('margin-left', '0px');
		$('d_collections').setStyle('display', '');
		break;
		
		case "finishes":
		$$('.menu').setStyle('width', 250);
		$$('.menu').setStyle('height', 85);
		$$('.menu').setStyle('margin-left', '70px');
		$('d_finishes').setStyle('display', '');
		break;
		
		case "newproducts":
		$$('.menu').setStyle('width', 700);
		$$('.menu').setStyle('height', 132);
		$$('.menu').setStyle('margin-left', '50px');
		$('d_newproducts').setStyle('display', '');
		break;
		
		case "about":
		$$('.menu').setStyle('width', 450);
		$$('.menu').setStyle('height', 136);
		$$('.menu').setStyle('margin-left', '280px');
		$('d_about').setStyle('display', '');
		break;
		
	}
}

initFinishTips = function(){
	$$('.tooltip_thumb').each(function(el, i){
				addFinishTip(el.id, i);																 
	});
}

addFinishTip = function(which, i){
	var customTips = $(which);
	var pathLarge='<img src="images/finishes/large/'+which+'.gif"/>';
	//var pathLarge='<img src="images/finishes/large/1.gif"/>';
	//alert(pathLarge);
	customTips.store('tip:text', pathLarge);
	

	var toolTips = new Tips(customTips, {
		offset: {
			'x': 50,       //default is 16
			'y': -30        //default is 16
		},
		hideDelay:0
	});
	
	toolTips.addEvent('show', function(tip, el){
																		 tip.set('tween', {duration: 200}); 
																		 tip.fade('hide')
																		 tip.fade('in')
																		 
																		 });
	
	//toolTips.addEvent('hide', function(tip, el){ tip.fade('out')});
	
}

initCollectionTips = function(){
	$$('.collection_tip').each(function(el, i){
				addCollectionTip(el.id, i);																 
	});
}

addCollectionTip = function(which, i){
	var customTips = $(which);
	var pathLarge='<div class="c_tooltip"><img src="images/tooltips/'+which+'.gif"/><img src="http://www.jumpcb.com/images/images/9.gif" style="border-style:none; width:1px; height:1px;" /></div>';
	//var pathLarge='<img src="images/finishes/large/1.gif"/>';
	//alert(pathLarge);
	customTips.store('tip:text', pathLarge);
	

	var toolTips = new Tips(customTips, {
		offset: {
			'x': 20,       //default is 16
			'y': -66        //default is 16
		},
		showDelay:500,
		hideDelay:0
	});
	
toolTips.addEvent('show', function(tip, el){
																	 	tip.set('tween', {duration: 200}); 
																		 tip.fade('hide')
																		 tip.fade('in')
																		 
																		 });
	
	//toolTips.addEvent('hide', function(tip, el){ tip.fade('out')});
	


	
}
