//////////////////////////////////////////////////
// Quick Search                                 //
//////////////////////////////////////////////////
// This script first causes the Quick Search    //
// to slide out of the way 4 seconds after      //
// the element loads, then causes it to         //
// slide back in when rolled over, and finally  //
// slide slide back out again when it           //
// has been moused out.	                        //
//////////////////////////////////////////////////

// This section lists all images with a id of 'feature#'
// and fades them into each other continuously to make
// a slideshow.
// It works, don't touch.
function images(){
	
	for(var i=0; i<imgs.length; i++){
   		if(imgs[i]!=='feature1'){
    		mult = (i+1)*3;
    		im = $(imgs[i]);
    		var make = fade_img.delay(mult, im);
    	}else{
    		end_mult = imgs.length*3;
    		for(var l=0; l<imgs.length; l++){
    			if(imgs[l]!=='feature1'){
    				var end_im = $(imgs[l]);
    				var bring = unfade_img.delay(end_mult, end_im);
    			}
    		}
    	}
	}
}

function unfade_img(va){
	var func2 = new Effect.Appear(va, {afterFinish: function(){
		if(va.id == 'feature2'){
			images();
		}
	}});
}

function fade_img(slide){
	new Effect.Fade(slide);
}



// This section is all for the sliding quick search menu. 
// It works, don't touch.
var currentState = 'showing';

function show(){
	if(currentState!=='hidden'){
		return false;
	}else{
		new Effect.Morph('quick_search_box', {style: 'left: 0px;', duration: 0.7});
		currentState = 'showing';
	}
}

function clear(){
	if(currentState!=='showing'){
		return false;
	}else{
		new Effect.Morph('quick_search_box', {style: 'left: 249px;', duration: 0.7});
		currentState = 'hidden';
	}
}



function watch_form(){
	Event.observe('new', 'click', update_form);
	Event.observe('used', 'click', update_form);
	Event.observe('make', 'change', get_models);
	Event.observe('model', 'change', update_form);
}

// This section observes the states of loading and sets everything in motion.
// It works, don't touch.
Event.observe(window, 'load', function(){
	var m = setTimeout(clear, 3000);
	images();
	//watch_forms();

	Event.observe('quick_search', 'mouseover', show);
	
	Event.observe('header', 'mouseover', clear);
	Event.observe('networks', 'mouseover', clear);
	Event.observe('content', 'mouseover', clear);
});