// JavaScript Document - lovekyn menu functions

function srch() {
	df=document.form;
	df.action="/used/used.php";
	df.submit();
}

function book(){
	df=document.form;
	df.action="/used/book.php";
	df.submit();
}

var targetheight;
currentheight=0;
step=20;
delay=10;

function high(el) {el.style.backgroundImage='url(/images/b_hi.gif)';}
function low(el) {el.style.backgroundImage='';}

function showmenu() {
	got("list",currentheight<1);
	targetheight=178;
	mover();
}

function hidemenu() {
	targetheight=0;
	mover();
}

function mover() {
	flg=false;
	if (currentheight<targetheight) {
		currentheight+=step;
		if (currentheight>=targetheight) currentheight=targetheight;
		if (currentheight<targetheight) flg=true;
	}
	else if (targetheight<currentheight) {
		currentheight-=step;
		if (currentheight<=targetheight) currentheight=targetheight;
		if (currentheight>targetheight) flg=true;
	}
	document.getElementById("extramenu").style.height=currentheight.toString()+'px';
	if (flg) window.setTimeout("mover()",delay);
}

w_step=20;
w_height=170;
w_delay=10;
var w_obj,w_tgt;

function gettyp(t){
	switch (t) {
		case 0:tt="list";break;
		case 1:tt="com";break;
		case 2:tt="mid";break;
		case 3:tt="mpv";break;
		case 4:tt="suv";break;
	}
	return tt;
}

function wipeout(ob) {
	w_tgt=ob;
	wobj="";
	for (i=0;i<5;i++){
		lay=document.getElementById("ex_"+gettyp(i));
		if (!lay.style.width) ix=lay;
	}
	w_obj=ix;
	if (w_obj!=w_tgt) window.setTimeout("wo("+w_height+")",w_delay);
}

function wo(w_v){
	w_v-=w_step;
	if (w_v<1) w_v=0;
	w_obj.style.height=w_v.toString()+'px';
	if (w_v>0) {window.setTimeout("wo("+w_v+")",w_delay);}
	else {
		w_obj.style.width="0px";
		w_tgt.style.width="";
		wi(0);
	}
}

function wi(w_v){
	w_v+=w_step;
	if (w_v>w_height-1) w_v=w_height;
	w_tgt.style.height=w_v.toString()+'px';
	if (w_v<w_height) {window.setTimeout("wi("+w_v+")",w_delay);}
}

function chkmenu(ev){
	if (!ev) ev=window.event;
	toele=ev.relatedTarget || ev.toElement;
	if (toele) {
		if (toele.id.substr(0,2)!="ex") {
			hidemenu();
		}
	}
}

function got(typ,q) {
	for (i=0;i<5;i++){
		thistyp=gettyp(i);
		lay=document.getElementById("ex_"+thistyp);
		if (q) {if (thistyp==typ) {lay.style.width='';lay.style.height='';} else {lay.style.width='0';lay.style.height='0';}}
		else if (thistyp==typ) wipeout(lay);
	}
}

function getobj() {
	ix="";
	for (i=0;i<5;i++){
		thistyp=gettyp(i);
		lay=document.getElementById("ex_"+thistyp);
		if (!lay.style.width) ix=thistyp;
	}
	return ("ex_"+ix);
}

function butdown(obj){obj.style.marginTop="5px";}
function butup(obj){obj.style.marginTop="0px";}

function preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


imagelist = new Array ("1","2","3","4");

preloadImages("/images/kia_spl_2.jpg","/images/kia_spl_3.jpg","/images/kia_spl_4.jpg");

imageoffset=1;
next_layer=1;
slide_delay=2000;
step_delay=30;
op_step=4;
cur_op=0;
var fdir;
cur_w=0;
w_step=10;

function nextpic() {
	imgname="images/kia_spl_"+imagelist[imageoffset]+".jpg";
	imageoffset++;
	if(imageoffset>=imagelist.length) imageoffset=0;
	if (next_layer==1) {fdir="in"; imgtgt="mp"; next_layer=0;}
	else {fdir="out"; imgtgt="bp"; next_layer=1;}
	document.getElementById(imgtgt).src=imgname;
	window.setTimeout("wipepic()",step_delay);
}

function wipepic() {
	if (fdir=="in"){
		cur_w+=w_step;
		if (cur_w>390) {cur_w=390;fdir="i";}
	}
	else {
		cur_w-=w_step;
		if (cur_w<1) {cur_w=0;fdir="o";}
	}
	document.getElementById("m_p").style.width=cur_w.toString()+"px";
	if (fdir=="i" || fdir=="o") window.setTimeout("nextpic()",slide_delay);
	else window.setTimeout("wipepic()",step_delay);
}

var snowy=new Array;
var snowd=new Array;
var snoww=new Array;
var flakes=0;

function init_snow(num){
	for(i=0;i<num;i++){
		im="f"+i;
//		document.getElementById("flurry").innerHTML+="<img id='im' src='images/snow10.gif' style='left:"+(Math.floor(Math.random()*990))+"px'/>";
		document.getElementById(im).src="images/snow10.gif";
		document.getElementById(im).style.top="-10px";
		document.getElementById(im).style.left=Math.floor(Math.random()*990)+"px";
		snowy[i]=-10;
		snowd[i]=Math.floor(Math.random()*10+2);
		snoww[i]=Math.floor(Math.random()*40);
	}
	flakes=num;
	window.setInterval("movesnow()",150);
}

function movesnow(){
	for(i=0;i<flakes;i++){
		if(snoww[i]>0){snoww[i]--;}
		else{
			if(snowy[i]>710){ny=-10;snowd[i]=Math.floor(Math.random()*10)+2;}
			else ny=snowy[i]+snowd[i];
			snowy[i]=ny;
			ob=document.getElementById("f"+i);
			ob.style.top=ny+"px";
			if(ny<-9)ob.style.left=Math.floor(Math.random()*990)+"px";
		}
	}
}
