

function thumbClick( x ){
	$('mainImg').innerHTML = '<img src=" ' + window.image_src_list[x] + '"/>\n';
	$('current_images').value = x;
}

function nextClick(){
	if($('current_images').value == $('number_of_images').value){
		$('current_images').value = 0;
	}else{
		$('current_images').value++;
	}
	
	$('mainImg').innerHTML = '<img src=" ' + window.image_src_list[$('current_images').value] + '"/>\n';
}

function previousClick(){
	if($('current_images').value == 0){
		$('current_images').value =  $('number_of_images').value;
	}else{
		$('current_images').value--;
	}
	
	$('mainImg').innerHTML = '<img src=" ' + window.image_src_list[$('current_images').value] + '"/>\n';
}


var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=600,width=1000');
	if (window.focus) {newwindow.focus()}
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

Event.observe(window, 'load', function() {

	//Takes the URL. If the page is a gallery page, then we need to make it a gallery!
	var proto_page;
	var base;
	var page;
	
	proto_page = window.location.href.split('index.php/');
	base = proto_page[0] + 'index.php/';
	page = proto_page[1].replace('/', '');
	
	
	//==========================================
	if( page == 'gallery' || page == 'kitchen-gallery' || page == 'bedroom-gallery' || page == 'media-room-gallery' || page == 'exterior-gallery'){
		
		var image_count;
		var image_src_list = new Array();
		var image_alt_list = new Array();
		var beta_image_list;
		var page_info = $('gallery-info').innerHTML;
		var proto_images_list = $('gallery-images').innerHTML;
		var gallery = '';
		var temp;
		var temp2;
		
		//The page should only contain a list of images. Let's put that list into an array.
		proto_images_list = proto_images_list.replace("<div>Place your images below.</div>", "");
		proto_images_list = proto_images_list.replace("<div>Place your images above.</div>", "");
		proto_images_list = proto_images_list.replace("<DIV>Place your images below.</DIV>", "");
		proto_images_list = proto_images_list.replace("<DIV>Place your images above.</DIV>", "");
		
		beta_image_list = proto_images_list.split('>');
		image_count = beta_image_list.length;
		image_count = image_count - 1;
		
		if(image_count > 0)	{
			for ( var k=0; k < image_count; k++){
			
				temp = beta_image_list[k].split('src="');
				temp2 = temp[1].split('"');
				image_src_list[k] = temp2[0];
				
				temp = beta_image_list[k].split('alt="');
				temp2 = temp[1].split('"');
				image_alt_list[k] = temp2[0];
				if(k >= image_count - 1){
					break;
				}
			}
		}
		
		window.image_src_list = image_src_list;
		window.image_alt_list = image_alt_list;
		
		// image_list is an array containing all images for the gallery
		//Now, lets write the gallery.
		
		gallery = gallery + '<div class="Gallery-Page">\n';
		gallery = gallery + '	<div class="Gallery-Page-Body">\n';
		gallery = gallery + '		<div class="Gallery-Page-Left">\n';
		gallery = gallery + '			<div class="Gallery-Nav">\n';
		gallery = gallery + '				<a ';
		if(page == 'gallery'){ gallery = gallery + 'class="here"';}
		gallery = gallery + 'href="' + base + 'gallery">Great Room</a> \n';
		gallery = gallery + '				<a ';
		if(page == 'kitchen-gallery'){ gallery = gallery + 'class="here"';}
		gallery = gallery + 'href="' + base + 'kitchen-gallery">Kitchen</a> \n';
		gallery = gallery + '				<a ';
		if(page == 'bedroom-gallery'){ gallery = gallery + 'class="here"';}
		gallery = gallery + 'href="' + base + 'bedroom-gallery">Bedroom</a> \n';
		gallery = gallery + '				<a ';
		if(page == 'media-room-gallery'){ gallery = gallery + 'class="here"';}
		gallery = gallery + 'href="' + base + 'media-room-gallery">Media Room</a> \n';
		/*
		gallery = gallery + '				<a ';
		if(page == 'exterior-gallery'){ gallery = gallery + 'class="here"';}
		gallery = gallery + 'href="' + base + 'exterior-gallery">Exterior</a>\n';
		*/
		gallery = gallery + '			</div>\n';
		gallery = gallery + '		</div>\n';
		gallery = gallery + '		<div class="Gallery-Page-Right">\n';
		gallery = gallery + '			<div class="content_head">\n';
		gallery = gallery + '				<p>Roller Shades</p>\n';
		gallery = gallery + '			</div>\n';
		gallery = gallery + '			<div class="Gallery-Img-Frame" >\n';
		gallery = gallery + '				<div class="Gallery-Img-Box" id="mainImg" >\n';
		if(image_count > 0){ gallery = gallery + '				<img src="' + image_src_list[0] + '"/>\n';}
		gallery = gallery + '				</div>\n';
		gallery = gallery + '				<div class="Gallery-Controls">\n';
		gallery = gallery + '					<div onclick="previousClick()" class="previousBtn"></div>\n';
		gallery = gallery + '					<div onclick="nextClick()" class="nextBtn"></div>\n';
		gallery = gallery + '				</div>\n';
		gallery = gallery + '			</div>\n';
		gallery = gallery + '			<div class="Gallery-Assets">\n';
		gallery = gallery + '				<div class="Gallery-Detail" id="mainImgDetails">' + page_info + '</div>\n';	
		gallery = gallery + '				<table cellpadding="0px" cellspacing="0px" id="thumbs" class="Gallery-Thumbnails">\n';
		
		if(image_count > 0)	{
			for( var i=0; i < image_count; i++){
				gallery = gallery + '				<tr >\n';
				gallery = gallery + '					<td class="galleryThumbFrame1" onclick="thumbClick(' + i + ')"  width="85px">\n';
				gallery = gallery + '							<img src="' + image_src_list[i] + '" />\n';
				gallery = gallery + '					</td>\n';
				
				i = i + 1;
				
				if(i < image_count){
					gallery = gallery + '					<td class="galleryThumbFrame2" onclick="thumbClick(' + i + ')"  width="85px">\n';
					gallery = gallery + '							<img src="' + image_src_list[i] + '" />\n';
					gallery = gallery + '					</td>\n';
				}else{
					gallery = gallery + '					<td class="galleryThumbFrame0">&nbsp;</td>\n';
				}
				
				gallery = gallery + '				</tr>\n';
			}
		}
		
		gallery = gallery + '				</table>\n';
		gallery = gallery + '			</div>\n';//assets
		gallery = gallery + '		</div>\n';//page right
		gallery = gallery + '		<div class="clear"></div>\n';
		gallery = gallery + '	</div>\n'; //page body
		gallery = gallery + '	<div class="Gallery-Page-Footer"></div>\n';
		gallery = gallery + '</div>\n'; //page
		gallery = gallery + '<input type="hidden" name="number_of_images" id="number_of_images" value="' + (image_count - 1) + '"/>\n';
		gallery = gallery + '<input type="hidden" name="current_images" id="current_images"   value="0"/>\n';
		
		//This populate the page.
		$('The_Gallery_Page').innerHTML = gallery;
		
		
		
		//This turns on the hidden div. We can finally see the page.
		$('The_Gallery_Page').setStyle({ display: 'block' }); 
	}
	//==========================================
	
	
	
	
	
	var obj   = document.getElementById('attribute534'); //Selecting a Width Range
	if(obj != null){
		obj.observe('change', function() {
			
			//Set all 6 text boxes to none.
			var proto_options;
			var proto_options_1;
			var proto_options_2;
			var options;
			var range;
			var min;
			var max;
			var count;
			
			proto_options = document.getElementById('attribute534').innerHTML;
			proto_options_1 = proto_options.split(obj.value+'">');
			if( proto_options_1[1] != null){
				proto_options_2 = proto_options_1[1].split('<');
			}else{
				proto_options_1 = proto_options.split('value='+obj.value);
				proto_options_1 = proto_options_1[1].split('>');
				proto_options_2 = proto_options_1[1].split('<');
			}
			options = proto_options_2[0];
			range = options.replace(' ', '');
			range = range.replace(' ', '');
			range = range.split('to');
			min = parseFloat(range[0]);
			max = parseFloat(range[1]);
			count = min;
			
			options = "";
			while(count <= max){
				options = options + '<option value="' + count + '">' + count + '</option>\n';
				count = count + 1;
			}
			
			//document.getElementById('widthSpecificInch').innerHTML = options;
			$('widthSpecificInch').update(options);
			
			$('widthSpecificDT').removeClassName('off');
			$('widthSpecificDT').addClassName('on');
			$('widthSpecificDD').removeClassName('off');
			$('widthSpecificDD').addClassName('on');
			setWidthBox();
		});
	}
	
	var obj2  = document.getElementById('attribute535'); //Selecting a Height Range
	if(obj2 != null){
		obj2.observe('change', function() {
			
			//Set all 6 text boxes to none.
			var proto_options;
			var proto_options_1;
			var proto_options_2;
			var options;
			var range;
			var min;
			var max;
			var count;
			
			proto_options = document.getElementById('attribute535').innerHTML;
			proto_options_1 = proto_options.split(obj2.value+'">');
			if( proto_options_1[1] != null){
				proto_options_2 = proto_options_1[1].split('<');
			}else{
				proto_options_1 = proto_options.split('value='+obj2.value);
				proto_options_1 = proto_options_1[1].split('>');
				proto_options_2 = proto_options_1[1].split('<');
			}
			options = proto_options_2[0];
			range = options.replace(' ', '');
			range = range.split('to');
			min = parseFloat(range[0]);
			max = parseFloat(range[1]);
			count = min;
			
			options = "";
			while(count <= max){
				options = options + '<option value="' + count + '">' + count + '</option>\n';
				count = count + 1;
			}
			
			//document.getElementById('heightSpecificInch').innerHTML = options;
			$('heightSpecificInch').update(options);

			$('heightSpecificDT').removeClassName('off');
			$('heightSpecificDT').addClassName('on');
			$('heightSpecificDD').removeClassName('off');
			$('heightSpecificDD').addClassName('on');
			setHeightBox();
		});
	}
	
	var obj3a  = document.getElementById('widthSpecificInch'); //Selecting a Height Range
	if(obj3a != null){ obj3a.observe('change', function() { setWidthBox();});}
	
	var obj3b  = document.getElementById('widthSpecificEigth'); 
	if(obj3b != null){ obj3b.observe('change', function() { setWidthBox();});}
	
	var obj4a  = document.getElementById('heightSpecificInch'); 
	if(obj4a != null){ obj4a.observe('change', function() { setHeightBox();});}
	
	var obj4b  = document.getElementById('heightSpecificEigth'); 
	if(obj4b != null){ obj4b.observe('change', function() { setHeightBox();});}
		
	var obj5  = document.getElementById('sillRangeInch'); //Selecting a Sill Range
	if(obj5 != null){
		obj5.observe('change', function() {
			
			//Set all 6 text boxes to none.
			var proto_options;
			var proto_options_1;
			var proto_options_2;
			var options;
			var range;
			var min;
			var max;
			var count;
			
			proto_options = document.getElementById('sillRangeInch').innerHTML;
			proto_options_1 = proto_options.split(obj5.value+'">');
			if( proto_options_1[1] != null){
				proto_options_2 = proto_options_1[1].split('<');
			}else{
				proto_options_1 = proto_options.split('value='+obj5.value);
				proto_options_1 = proto_options_1[1].split('>');
				proto_options_2 = proto_options_1[1].split('<');
			}
			options = proto_options_2[0];
			range = options.replace(' ', '');
			range = range.split('to');
			min = parseFloat(range[0]);
			max = parseFloat(range[1]);
			count = min;
			
			options = "";
			while(count <= max){
				options = options + '<option value="' + count + '">' + count + '</option>\n';
				count = count + 1;
			}
			
			//document.getElementById('sillSpecificInch').innerHTML = options;
			$('sillSpecificInch').update(options);

			$('sillSpecificDT').removeClassName('off');
			$('sillSpecificDT').addClassName('on');
			$('sillSpecificDD').removeClassName('off');
			$('sillSpecificDD').addClassName('on');
			
			setSillBox();
		});
	}
	
	var obj6a  = document.getElementById('sillSpecificInch'); 
	if(obj6a != null){ obj6a.observe('change', function() { setSillBox();});}
	
	var obj6b  = document.getElementById('sillSpecificEigth'); 
	if(obj6b != null){ obj6b.observe('change', function() { setSillBox();});}
		
	
	
});

function setWidthBox(){
	var inch  = document.getElementById('widthSpecificInch').value;
	var eigth = document.getElementById('widthSpecificEigth').value;
	var my_id = next_ID(document.getElementById('WidthDetail').innerHTML);
	
	document.getElementById(my_id).value = '' + inch + ' and ' + eigth + '/8 inches';
}
function setHeightBox(){
	var inch  = document.getElementById('heightSpecificInch').value;
	var eigth = document.getElementById('heightSpecificEigth').value;
	var my_id = next_ID(document.getElementById('HeightDetail').innerHTML);
	
	document.getElementById(my_id).value = '' + inch + ' and ' + eigth + '/8 inches';
}
function setSillBox(){
	var inch  = document.getElementById('sillSpecificInch').value;
	var eigth = document.getElementById('sillSpecificEigth').value;
	var my_id = next_ID(document.getElementById('SillDetail').innerHTML);
	
	document.getElementById(my_id).value = '' + inch + ' and ' + eigth + '/8 inches';
}

function next_ID(selection){
	var my_id = selection.split('id=');
	my_id = my_id[1];
	my_id = my_id.split(' ');
	var returnThis = my_id[0];

	returnThis = returnThis.replace('"', '');
	returnThis = returnThis.replace('"', '');
	return returnThis;
}
/* */
function corrections(){
	document.getElementById('SCPcustomOptionsDiv').innerHTML = '';
}
/* */
