var jsRoot='/';

function embedFlash(url,vars,w,h,bg,id){
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' id='"+id+"' width='"+w+"' height='"+h+"'>");	
	document.write("<param name='movie' value='"+url+"' />");
	document.write("<param name='quality' value='high' />");
	document.write("<param name='allowScriptAccess' value='sameDomain' />");
	document.write("<param name='scale' value='noscale' />");
	if(vars.length > 0)	document.write("<param name='flashvars' value='"+vars+"' />");
	document.write("<param name='salign' value='lt' />");	
	document.write("<embed src='"+url+"' flashvars='"+vars+"' quality='high' bgcolor='"+bg+"' name='"+id+"' scale='noscale' salign='lt'  pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+w+"' height='"+h+"'></embed>");
	document.write("</object>");
}

function selectExt(ix){
	var imgurl=jsRoot+'images/decor/ext-'+brand+'-'+exterior[ix][0]+'.jpg';
	$("#imgExt").set("src",imgurl);
	$("#extCaption").html(exterior[ix][1]);
	$(".decExtTh").css("border","1px solid #FFFFFF");
	$("#extthumb"+ix).css("border","1px solid #CC0000");	
}

function selectInt(ix){
	var imgurl_fab=jsRoot+'images/decor/fab-'+brand+'-'+interior[ix][0]+'.jpg';
	var imgurl_han=jsRoot+'images/decor/handle_'+brand+'-'+interior[ix][2]+'.jpg';
	$("#imgFab").set("src",imgurl_fab);	
	$("#imgHandle").set("src",imgurl_han);	
}

function selectWood(ix){
	var imgurl=jsRoot+'images/decor/wood-'+brand+'-'+woods[ix][0]+'.jpg';
	$("#imgWood").set("src",imgurl);	
}

function loadExtPage(thumbsPerPage) {
	// build exterior thumbs
	curDecorExtIx += thumbsPerPage;	
	$("#divPrevBtn").css('visibility','visible');
	$("#divNextBtn").css('visibility','visible');
	
	if(curDecorExtIx <= 0){
		curDecorExtIx=0;
		$("#divPrevBtn").css('visibility','hidden');
	}
	if(curDecorExtIx > exterior.length-6) {
		// nothing on next page - hide next button
		$("#divNextBtn").css('visibility','hidden');
	} 
	if(curDecorExtIx > exterior.length) {
		curDecorExtIx=exterior.length-1			
	}
	
	$("#extThumbs a").remove();
	for(t=curDecorExtIx; t<(curDecorExtIx+5); t++){	
		if(t==exterior.length)  break;
		var thBtn = document.createElement('a');	
		var thImg=new Image();	
		var imgurl=jsRoot+'images/decor/ext-'+brand+'-'+exterior[t][0]+'_th.jpg';		
		thImg.src=imgurl;		
		thImg.id='extthumb'+t;		
		$(thImg).addClass('decExtTh');			
		thBtn.href="javascript:selectExt("+t+");";
		thBtn.appendChild(thImg);				
		$("#extThumbs").append(thBtn);		
	}			
}

var curDecorExtIx=0;
function initDecor(){	
	// populate interior dropdown
	for (i=0; i<interior.length; i++) {
		document.forms['frmDecor'].interiorOptions.options[i]=new Option(interior[i][1],interior[i][0]);
	}		
	// populate woods dropdown
	for (i=0; i<woods.length; i++) {		
		document.forms['frmDecor'].woodOptions.options[i]=new Option(woods[i][1],woods[i][0]);
	}
	selectExt(0);
	selectInt(0);
	selectWood(0);	

	// build exterior thumbs
	loadExtPage(curDecorExtIx);	
}

//preloader
var preloaded=new Array();
var x=0;
function preloadImgArr(imgsrc,srcIx){						
	for (var i = 0; i < imgsrc.length; i++){
		x=preloaded.length;
		preloaded[x] = document.createElement('img');
		preloaded[x].setAttribute('src',imgsrc[i][srcIx]);
	};				
}