// This is the implementation of SimpleSwap
// by Jehiah Czebotar
// Version 1.1 - June 10, 2005
// Distributed under Creative Commons
//
// Include this script on your page
// then make image rollovers simple like:
// <img src="/images/ss_img.gif" oversrc="/images/ss_img_over.gif">
//
// http://jehiah.com/archive/simple-swap
// 

$(document).ready(function(){
   SimpleSwapSetup();//setup rollovers
 	windowLinks();
   $(".bedroom2").hide();
   $(".bedroom3").hide();
     
  // $("#jointchoice").click(function(){$(".joint").show()});
  // $("#singlechoice").click(function(){$(".joint").hide()});
   
   $("#furniture_pack").change(function(){
  						if($("#furniture_pack").val() == ' ')
						{
							$(".bedroom2").hide();
							$(".bedroom3").hide();													
						}
  												
  						else if($("#furniture_pack").val() == '1 bed')
						{
							$(".bedroom2").hide();
							$(".bedroom3").hide();						
							$("#price").val(2250 +2250 * 0.175);
							var p1price = parseFloat($("#price").val());
							$("#deposit").val((p1price * 0.50).toFixed(2));
							$("#balance").val((p1price - parseFloat($("#deposit").val())).toFixed(2));							
						}
   						else if($("#furniture_pack").val() == '2 bed')
						{
							$(".bedroom2").show();
							$(".bedroom3").hide();
							$("#price").val(2550 +2550 * 0.175);
							var p2price = parseFloat($("#price").val());						
							$("#deposit").val((p2price * 0.50).toFixed(2));
							$("#balance").val((p2price - parseFloat($("#deposit").val())).toFixed(2));							
						}
						else if($("#furniture_pack").val() == '3 bed')
						{
							$(".bedroom2").show();
							$(".bedroom3").show();
							$("#price").val((2895 +2895 * 0.175).toFixed(2));						
							$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
							$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));
						}
						
						});
	     $("#add_essentials_pack").click(function(){
  						var newprice = 269 + (269*0.175);
  						if(document.getElementById("add_essentials_pack").checked == true)
						{
							$("#price").val((parseFloat($("#price").val()) + newprice).toFixed(2));
							$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
							$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));							
						}
   						else
						{
							$("#price").val((parseFloat($("#price").val()) - newprice).toFixed(2));
							$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
							$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));
						}
						}); 
	 $("#add_bedding_pack").click(function(){
							var newprice = 89 + (89*0.175);
							if(document.getElementById("add_bedding_pack").checked == true)
							{
								$("#price").val((parseFloat($("#price").val()) + newprice).toFixed(2));
								$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
								$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));							
							}
							else
							{
								$("#price").val((parseFloat($("#price").val()) - newprice).toFixed(2));
								$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
								$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));
							}
							}); 
	 $("#add_bathroom_pack").click(function(){
							var newprice = 89 + (89*0.175);
							if(document.getElementById("add_bathroom_pack").checked == true)
							{
								$("#price").val((parseFloat($("#price").val()) + newprice).toFixed(2));
								$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
								$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));							
							}
							else
							{
								$("#price").val((parseFloat($("#price").val()) - newprice).toFixed(2));
								$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
								$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));
							}
							}); 
		 $("#add_decorative_pack").click(function(){
							var newprice = 129 + (129*0.175);
							if(document.getElementById("add_decorative_pack").checked == true)
							{
								$("#price").val((parseFloat($("#price").val()) + newprice).toFixed(2));
								$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
								$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));							
							}
							else
							{
								$("#price").val((parseFloat($("#price").val()) - newprice).toFixed(2));
								$("#deposit").val((parseFloat($("#price").val()) * 0.50).toFixed(2));
								$("#balance").val((parseFloat($("#price").val()) - parseFloat($("#deposit").val())).toFixed(2));
							}
							}); 											
	

});

function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}


function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
  var x = document.getElementsByTagName("input");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

//var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
//window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}// JavaScript Document

/* This handy function from Simon Willison allows you to stack up 'window.onload' events <br />
without them stepping on each other's toes. It's explained here - http://www.sitepoint.com/blog-post-view.php?id=171578 

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
*/

/* This is our old popup code - parts of the site still use it, so I need to keep it */
function acpopup(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="console") strOptions="resizable,scrollbars=1,height="+strHeight+",width="+strWidth;
window.open(strURL, '', strOptions);
}


/* new accessible, unobtrusive popup code */

function windowLinks() {
    if(!document.getElementsByTagName) {
         return;
    }
	
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
         var anchor = anchors[i];
         var relIndex = anchor.rel;
		 if (relIndex){
		 var relSplit = relIndex.split("|");
/* XHTML compliant target attribute */
		 if (relSplit[0] == "external") {
            anchor.target = "_blank";
			anchor.className = "external";
			anchor.title = "Load in new window: "+ anchor.href;
/* XHTML compliant popup attribute */
   			} else if (relSplit[0] == "popup") {
			anchor.className = "popup";
			anchor.title = "Link loads in Popup Window";
			anchor.popupWidth = relSplit[1];
			anchor.popupHeight = relSplit[2];
	        anchor.onclick = function() {acpopup(this.href,'console',this.popupWidth,this.popupHeight);return false;};
			}
		}
	   }
} 
/*
addLoadEvent(function() {
	windowLinks();	
	//PreSimpleSwapOnload(); 
	SimpleSwapSetup();
	//goHere();
});*/