function getPrices(id,p1,sp){

		p2 = p1;
		id2 = id;
  	var setID = id;
	// set get params
	var pars = 'basePrice='+p2;
	
	if (sp){
		if (sp == 'short'){
			var setPath = 'ajaxContent/woodPricesShort.php';
		} else if (sp == 'out') {
			var setPath = 'ajaxContent/woodPricesL.php';
		} else if (sp == 'st') {
			// set pars prod to screen transom
			pars += '&prod=st';
			var setPath = 'ajaxContent/woodPrices.php';
		}
	} else {
		var setPath = 'ajaxContent/woodPrices.php';
	}
	
   
	if (document.getElementsByClassName('woodPrice on')){
			idToChange = document.getElementsByClassName('woodPrice on')
			
			for(i=0; i <idToChange.length;i++)
			{ 
				if(idToChange[i].id != setID){
					
					new Effect.Fade(idToChange[i],{duration: .1,queue:'front'});
					idToChange[i].className='woodPrice';
				}
			}
		}
	
	
	
	// alert(pars);
	new Ajax.Updater(setID,setPath, { // URL for next <IMG> tag 
		asynchronous: true,
		evalScripts:true,
		method:'get',
		parameters:pars, 
		onComplete: showAjax(),
		on404: errorAjax() 
		})
			 
		
  	function showAjax() { 
		new Effect.Appear(setID,{duration: .1,afterFinish: setNewID,queue:'end'});
		}
	function setNewID() {
		document.getElementById(setID).className='woodPrice on';
	}
	function errorAjax() {
		$(setID).innerHTML = "There was an error retreiving this content. Please try again. <p><a id=\"closeLink\" href=\"#\" onclick=\"new Effect.toggle(id2,'appear',{duration: .2}); return false;\">Click To Close</a></p>";
	}
  	}
	
function mlspopup(myDiv,image,text,buyB){
   
   var divIdName = "created"+myDiv;
   
	if (document.getElementsByClassName('door-photos on')){
			idToChange = document.getElementsByClassName('door-photos on')
			
			for(i=0; i <idToChange.length;i++)
			{ 
				//if(idToChange[i].id != myDiv){
					
					//new Effect.Fade(idToChange[i],{duration: .1,queue:'front'});
					idToChange[i].className='door-photos';
					//alert(idToChange[i].id+" thinks it needs to be removed");
					//need to get at the PARENT here
					//alert(idToChange[i].id+" is being sent to be removed");
					
					var removeDiv = idToChange[i].id;
					//alert(removeDiv+" is the parent div");
					
					var removeChildDiv = "created"+removeDiv;
					
					var toRemove = $(removeChildDiv);
					//alert(toRemove.id+" is the div to be removed");
					
					var d = $(removeDiv);
					//alert(d.id+" is the id of the object whose child we\'re removing");
					d.removeChild(toRemove);
					
				//}
			}
		}
	//Check for buy button, and display appropriately
	if (buyB == 1) {
		buyButton = "<a href=\"order_ext.html\" target=\"_blank\"><img src=\"images/quote-buy_button05.gif\" width=\"48\" height=\"25\" alt=\"\" border=\"0\"></a>";
	} else if (buyB == 2) {
		buyButton = "<a href=\"order_screen.html\" target=\"_blank\"><img src=\"images/quote-buy_button05.gif\" width=\"48\" height=\"25\" alt=\"\" border=\"0\"></a>";
	} else {
		buyButton = "";
	}
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id',divIdName);
	newdiv.className='innerPopup';
	newdiv.style.display='none';
	newdiv.innerHTML = "<img src=\""+image+"\"><p>"+text+"</p>"+buyButton+"<p><a href=\"javascript:;\" onclick=\"removeElement(\'"+myDiv+"\')\">(X) Close Window</a></p>";
	var ni = $(myDiv);
	ni.style.display='block';
	ni.appendChild(newdiv);
	showAjax(newdiv);		 
		
  	function showAjax(newdiv) { 
		new Effect.Center(newdiv,{queue:'front'});
		new Effect.Appear(newdiv,{duration: .1,afterFinish: setNewID,queue:'end'});
		}
	
	
	function setNewID() {
		//alert(divIdName+" class is being set to the new DIV");
		$(myDiv).className='door-photos on';
		}
	
  	}
	
	function removeElement(removeDiv)
		{
		//alert(removeDiv+" is the parent div");
		$(removeDiv).className='door-photos';
		
		var toRemove = $('created'+removeDiv);
		//alert(toRemove.id+" is the div to be removed");
		var d = $(removeDiv);
		//alert(d.id+" is the id of the object whose child we\'re removing");
		d.removeChild(toRemove);
		// hide container div
		d.style.display='none';
		}

// ZOOM INTO IMAGE USED ON GLASS PAGE *************
function mlsZoom(myDiv,image,text,buyB){
   
   var divIdName = "created"+myDiv;
   // if Zoom already open, close it
	if (document.getElementsByClassName('door-photos on')){
			idToChange = document.getElementsByClassName('door-photos on')
			
			for(i=0; i <idToChange.length;i++)
			{ 
				idToChange[i].className='door-photos';
				var removeDiv = idToChange[i].id;
				var removeChildDiv = "created"+removeDiv;
				var toRemove = $(removeChildDiv);
				var d = $(removeDiv);
				d.removeChild(toRemove);
			}
		}
	//Check for buy button, and display appropriately
	if (buyB == 1) {
		buyButton = "<a href=\"order_ext.html\" target=\"_blank\"><img src=\"images/quote-buy_button02.gif\" width=\"67\" height=\"18\" alt=\"\" border=\"0\"></a>";
	} else if (buyB == 2) {
		buyButton = "<a href=\"order_screen.html\" target=\"_blank\"><img src=\"images/quote-buy_button02.gif\" width=\"67\" height=\"18\" alt=\"\" border=\"0\"></a>";
	} else {
		buyButton = "";
	}
	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id',divIdName);
	newdiv.className='innerPopup';
	newdiv.style.display='none';
	newdiv.innerHTML = "<img src=\""+image+"\"><p>"+text+"</p>"+buyButton+"<p><a href=\"javascript:;\" onclick=\"removeElement(\'"+myDiv+"\')\">(X) Close Window</a></p>";
	var ni = $(myDiv);
	ni.style.display='block';
	ni.appendChild(newdiv);
	// ni.onmouseout=function(){removeElement(myDiv);};
	showAjax(newdiv);		 
		
  	function showAjax(newdiv) { 
		new Effect.Center(newdiv,{queue:'front'});
		new Effect.Appear(newdiv,{duration: .1,afterFinish: setNewID,queue:'end'});
		}
	
	
	function setNewID() {
		//alert(divIdName+" class is being set to the new DIV");
		$(myDiv).className='door-photos on';
		}
	
  	}

function popAjax(container_id,ajax_id,path){
	
	
	 

  	new Ajax.Request(path, {   method: 'get',   onSuccess: function(transport) {
	     var data = transport.responseText;
	     new Effect.Fade('popAjax', { afterFinish: function () { 
     $('popAjax').update(data); 
     new Effect.Center('popAjax',{queue:'front'});
	 new Effect.Appear('popAjax'); 
     } 
   });   } });
	
	}
	
// GENERIC SHOW/HIDE FUNCTION
function showHide(id){
	
	Effect.toggle(id,'blind',{duration: .5});
}

// FUNCTIONS FOR SPECIAL FEATURE
var toggle = 0;
  function showCart(){
  Effect.toggle('cart-inner2', 'slide', { delay: 0.5, duration: .5, afterFinish: function () {
  
  if (toggle == '1'){
  	document.getElementById('cartToggleLink').innerHTML = "Special Offer";
	set_cookie("showSpecial","no");
  } else {
	document.getElementById('cartToggleLink').innerHTML = "Hide Special Offer";
	set_cookie("showSpecial","yes");
  }
	(toggle == '1') ? toggle = '0' : toggle = '1';
	} });
	
  }
function show_special() {
	Event.observe('cartToggleLink', 'click', showCart, false);
	var theURL = "ajaxContent/specials.html?"+Date()
	new Ajax.Request(theURL, {   method: 'get',   onSuccess: function(transport) {
		var data = transport.responseText;
		$('cart-inner2').update(data);
		// set cookie
		var theCookie = get_cookie("showSpecial");
		if (theCookie == "yes" || theCookie != "no" || theCookie == null){
	  		
			new Effect.toggle('cart-inner2', 'slide', { delay: 1, duration: .5, afterFinish: function () {
			(toggle == '1') ? toggle = '0' : toggle = '1';
			//alert("toggle = "+toggle);
			
			document.getElementById('cartToggleLink').innerHTML = "Hide Current Specials";
			set_cookie("showSpecial","yes");
			var theCookie2 = get_cookie("showSpecial");
			
			} });
		}
	  
		if (theCookie=='no') {
	  		// alert(get_cookie("showSpecial"));
		}
		}
	});
}

// COOKIE FUNCTIONS	

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}
function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}


// CROSSFADE FUNCTION
// http://mikeomatic.net/?p=78
// id attributes of the divs to fade
//var divs_to_fade = new Array("box-1", "box-2", "box-3", "box-4", "box-5");
// Prototype fix to accept n number of child elements

function assembleRotate(){
	divs_to_fade = new Array();
 
	var childDivs = document.getElementById("crossfade-container").childNodes;
 	// alert ("child divs length "+childDivs.length);
	
	//loop thru divs and add each div's id to the array
	for(var i=0; i < childDivs.length; i++) {
    	if(childDivs[i].nodeType == 1) {
		divs_to_fade.push(childDivs[i].id);
		}      
	}
	//for(var i=0; i < divs_to_fade.length; i++) {
   	//	alert(divs_to_fade[i]);
	//}
	startRotate(divs_to_fade);
}
		
// starting index.  should be set to the value of the div which doesn't have the CSS Display property set to "none"
var fade_i = 0;
			
// milliseconds between swaps.  Default is five seconds.
var fade_wait = 5000;

// the function that performs the fade - set fade_i=number of images
function swapFade(divs_to_fade) {
	Effect.Fade(divs_to_fade[fade_i], { duration:1, from:1.0, to:0.0 });
	fade_i++;
	if (fade_i == divs_to_fade.length) fade_i = 0;
	Effect.Appear(divs_to_fade[fade_i], { duration:1, from:0.0, to:1.0 });
}
			
// the onload event handler that starts the fading.
function startRotate(divs_to_fade) {
	setInterval(function() { swapFade(divs_to_fade); },fade_wait);
}

// ORDER FORMS
function sameAsBilling() {
	  Event.observe('sameAsBilling', 'click', item_clicked, false);
	  if($('sameAsBilling').checked == true){
			$('ship_info').style.display='none';
		}
	}
	
function item_clicked(){
	if($('sameAsBilling').checked == true){
		$('ship_info').style.display='none';
	} else {
		$('ship_info').style.display='block';
	}
}

// WINDOW ONLOAD FUNCTION
// window.onload = function(){
//	if ($("cart-wrap")){
//		show_special();
//		}
//	if ($("crossfade-container")) {
//		startRotate();
//		}
//	if ($("cat-price")) {
//		calcPrice();
//		}
//	if ($("sameAsBilling")) {
//		sameAsBilling();
//		}
//	}

Event.observe(window, 'load', function() {
  if ($("cart-wrap")){
		show_special();
		}
	if ($("crossfade-container")) {
		assembleRotate();
		}
	if ($("cat-price")) {
		calcPrice();
		}
	if ($("sameAsBilling")) {
		sameAsBilling();
		}
});
